Showing posts with label TV remote. Show all posts
Showing posts with label TV remote. Show all posts

2018/02/27

Arduino - Switch celling light with TV remote (2/2)

This is the part two of Switch celling light with TV remote tutorial. If needed, please check out the part one from link below. By the way, the source code is also available there.


Quick Link


System Design

See the illustration below. I used a phone charger(purple block; AC110V to DC5V) to supply power from 110v AC power outlet from the celling. The Arduino controls the relay module to switch the celling light and Arduino interpret IR code to change  RGB LED to shift color and on/off accordingly. 

Connections

  • IR Receiver to Arduino pin 2
  • IR Receiver + to VCC
  • IR Receiver - to GND
  • Relay + to VCC
  • Relay - to GND
  • Relay to Arduino pin 8
  • RGB Red to Resistor to Arduino pin 3
  • RGB Green to Resistor to Arduino pin 5
  • RGB Blue to Resistor to Arduino pin 6
  • *** CAUTION: Turn off home main power switch first before 110V connection! ***
  • *** Connect 110V to the system after you secure prefboard to the celling light ***
  • Connect 110V VCC to "Relay NO (Normally Open)" on the left
  • Connect Relay COM (Common connection) to 110V GND. 

      Step by step



      Solder pins to Arduino mini pro.

      Pick up the corner of the perfboard as the fix position. Then, solder pin header connectors on the side of Arduino mini pro, so we could have the flexibility to change wiring later.  Don't forget to face Arduino five data pins towards outside of the prefboard for easier connection to upload source code later.

      Selected few unused solder holes from the Arduino Mini Pro and used the connection pin headers as supporting material on the perfboard. This could prevent unintentional shortage. See below:


      After fixed Arduino Mini Pro in place, solder RGB LED, resistors, and wires to the prefboard. 
      Remember to power up to test the whole setup before moving forward.


      I used a screw to fix the relay module on the perfboard. However, fixed on one side is not stable enough, so I took a cable tight to keep the relay module tightly in place.  *Remember to reserve a very long IR reception wire*, so the IR receiver could placed outside of the celling light or the IR receiver might be obscured by the decorative glass cover.



      Here is the over all system in action!



      Next, find a good power source for the system. 
      For this project, I used a HTC smart phone charger. At least, HTC is (or was?) an international brand name smartphone company and has good reputation regarding to safety. Again, for safety reason, please use certified chargers only, such as CE, FCC, UL from well-know brand name company. *** Do not use no brand or very cheap chargers from unknown source. You are on your own risk! ***



      I used a short USB cable to connect the HTC charger to the system.  Cut the USB cable near micro-B (smaller connector) and strip the shielding off the cable. In there, you will find four wires with GREEN, WHITE, RED, BLACK. Solder the RED(5V+) and BLACK(GND) wires to positive and negative respectively on the perfboard. 

      Cable connection:
      • USB type-A (Larger connector) to HTC charger
      • USB micro-B (smaller connector) to system



      After soldered the USB wires, plug the charger to power outlet and test the system.



      My bedroom celling light looks like this below. It has a switch located at the entrance of the bedroom. And the switch works like this. After implement this system, the control of the switch will be shift to Arduino Mini Pro.

      For every switch on/off, it cycles through 

      1.  Turn on three lights
      2.  Turn off
      3.  Turn on Five lights
      4.  Turn off 
      5.  Turn on two lights
      6.  Turn off



      Carefully loosen the screw from the bottom glass cover and remove the decorative glass away.


      Drill a hole on the light base for tightening the system.


      Use a screw to secure the prefboard to the celling light as shown below.


      *** Important: Wrong connection will cause the light not working ***
      • Connect 110v VCC to "Relay NO (Normally Open)" on the left
      • Connect Relay COM (Common connection) to 110v GND



      When connect AC 110V power line to phone charger, please make sure the isolation is done properly. It would be better to use Heat shrink tube for the isolation. However, I didn't have those on hand, so I used the isolation tape and tight them 3~4 times to ensure it's 100% isolated.  

      *** Disclaimer: Many experts expressed safety concerns for connecting Arduino with relay to AC 110V power!  I'm not responsible for any damage or lose that could happened to your projects or properties! You are at your own risk of doing this! ***



      Before tighten the light frame and decorative glass back to the celling, use the remote to test the system to see if it's working as expected.

      See the red circle below, that's the IR receiver that I used an extended wire from the perfboard to the rim of the light to get better IR reception.



      Let's try to change the color with the TV remote.


      Finally, the project is completed! Watch the video below to see it in action!
      Now I can turn the celling light off directly from my bed after turn TV off!  




      This is the end of this tutorial. I hope you liked it! Please leave comments below and I will see you next time.

      Enjoy!


      2018/02/25

      Arduino - Switch celling light with TV remote (1/2)

       Preface

      It must be happened to you before that in a very cold night watching TV or movie in bed and you were ready for bed. You turned off the TV or DVD player with remote control easily. However, for the celling light, you just had to get out of the bed to turn the light off. What a pain! 

      After I searched the Internet, there are many examples out there suit for this purpose, such as IR receiver, relay module, and RGB LED shift hue and most of them have codes that I could utilize on this project.  

      Quick Link

      Material Needed

      • Arduino mini pro *1 
      • USB upload module *1 
      • Relay module (5V/10A/125V) * 1 
      • IR Receiver LED * 1 (Aixin AX-1838HS 38KHz * 1 / All 38KHz should work) 
      • RGB LED *2 
      • Resister 220 Om * 3
      • Few jump wires
      • Any TV or DVD remote you have at home
      • Breadboard * 1
      It's not difficult to find these components on Amazon or eBay.

      System Functionality

      Assign two buttons on the remote to control the celling light. Remember to assign less frequently used buttons on the remote or you might accidentally activate the particular function on your appliances. :)
      • Button 1: Turn on/off
      • Button 2: Switch LED color hues (static or color shifting)

      Schematic

      This schematic is made with Fritzing. 
      You can download it from its official website: www.fritzing.org


      Connections

      • IR Receiver to Arduino pin 2
      • IR Receiver + to VCC
      • IR Receiver - to GND
      • Relay + to VCC
      • Relay - to GND
      • Relay to Arduino pin 8
      • RGB Red to Resistor to Arduino pin 3
      • RGB Green to Resistor to Arduino pin 5
      • RGB Blue to Resistor to Arduino pin 6

      Check Remote IR code

      You have to find out the remote button IR codes on your remotes and embed them in the source code below for this project to work.


      For Example, my Sanyo TV remote has the following codes. As you can see, I have assigned two buttons for each feature to have a fall back plan.

      • Celling Light Switch function
        • Mute:irCode: 1CE318E7,  bits: 32  sanyoLight1
        • Channel minus :irCode: 1CE3D02F,  bits: 32  sanyoLight2
      • LED Switch function
        • Volume minus :irCode: 1CE3F00F,  bits: 32  sanyoLED1
        • CH View: irCode: 1CE352AD,  bits: 32 sanyoLED2

      To find out the IR codes for you remote, please refer to my previous IR Repeater Tutorial (Part 2)

      Source Code

      /*
       * Author: Stonez56
       * IRRemote for bedroom lighting control 
       *   Light buttons: Switch lights through the 
       *            cycle - 3, 5, 2, off with 2 types of remote
       *   LED buttons: Switch display random color a, b, transistion, off
       */
      
      #include <IRremote.h>
      
      // Setting up pins
      // Setup pin 8 for relay. 
      //    For some reason, Pin 13 will cause relay to switch one time
      //    when system powers on
      const int relay1Pin = 8; 
      const int redPin = 3;                    
      const int greenPin = 5;
      const int bluePin = 6;
      const int irReceiverPin = 2;
      
      // Milisecond to delay when shifting colors
      int colorShiftTime[] = {20, 10, 1, 50}; 
      int colorShiftTimeCounter = 0;
      
      int myPins[] = {2, 4, 8, 3, 6};
      int LEDstatus = 0;       // mode of LED or switch light
                          /*
                           * 0 = LED off
                           * 1 = LED orange
                           * 2 = LED color rotation
                           * 3 = Relay Light swtich
                           */
      
      int relay1Status = 0; // Switch of the relay; either 1 or 0;
      
      
      IRrecv irrecv(irReceiverPin);            
      decode_results results;  // IR decode_results 
      
      unsigned int rgbColour[3]; //RGB LED array
      
      unsigned int preCode = 0x0;  //Previous remote code
      unsigned int currentCode = 0x0; //Current remote code
      
      /* Define remote codes  
      Remote A (iBit Remote)
       Switch
        - (L/R) irCode: 609E09F6,  bits: 32 bitLigth1
        - Subtitle:irCode: 609E8877,  bits: 32  bitLight2
       LED Switch
        - Sound change irCode: 609E42BD,  bits: 32 bitLED1
        - Favorite channel:irCode: 609E728D,  bits: 32 bitLED2
        LED Color speed 
          - colorShiftTime: irCode: 
      
      */
       
      const unsigned long bitLight1 = 0x609E09F6;
      const unsigned long bitLight2 = 0x609E8877;
      const unsigned long bitLED1 = 0x609E42BD;
      const unsigned long bitLED2 = 0x609E728D; 
      const unsigned long bitLEDspeed = 0x609EAA55;
      /*
      Remote B (Sanyo Remote)
       Switch
        - Mute:irCode: 1CE318E7,  bits: 32  sanyoLight1
        - Channel minus :irCode: 1CE3D02F,  bits: 32  sanyoLight2
       LED Switch
        - Volume minus :irCode: 1CE3F00F,  bits: 32  sanyoLED1
        - CH View: irCode: 1CE352AD,  bits: 32 sanyoLED2
        LED Color speed
          - colorShiftTime: irCode: 
      
      */
      const unsigned long sanyoLight1 = 0x1CE318E7;
      const unsigned long sanyoLight2 = 0x1CE3F00F;
      const unsigned long sanyoLED1 = 0x1CE352AD;
      const unsigned long sanyoLED2 = 0x1CE3D02F;
      const unsigned long sanyoLEDspeed = 0x1CE350AF;
      
      void setup()
      {
        
        //////Serial.begin(9600);   
        irrecv.enableIRIn(); // enable IR pin
        pinMode(relay1Pin, OUTPUT);
        // Start off with the LED off.
        ledOff();
      }
      
      // Turn off LED
      void ledOff(){
        rgbColour[0] = 255;
        rgbColour[1] = 255;
        rgbColour[2] = 255;  
        setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
      
        preCode = currentCode;
        while(preCode == currentCode){
              currentCode = checkRemoteCode();
              // Check the code on Serial port
              Serial.print(rgbColour[0]); Serial.print(" | ");
              Serial.print(rgbColour[1]);  Serial.print(" | ");
              Serial.println(rgbColour[2]);
        }
      }
      
      /*
      * Turn on LED to Orange color
      */
      void ledOrange(){
        //LED color orange??
        rgbColour[0] = 65391;
        rgbColour[1] = 400;
        rgbColour[2] = 255;  
        setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
      
        preCode = currentCode;
        while(preCode == currentCode){
              currentCode = checkRemoteCode();
        }
      
      }
      
      
      /*
       * Rotating RGB LED color
       */
      void colorRotation(){
        // Start off with red.
        rgbColour[0] = 0;
        rgbColour[1] = 255;
        rgbColour[2] = 255;  
      
        preCode = currentCode;
       
        // Choose the colours to increment and decrement.
        for (int decColour = 0; decColour < 3; decColour += 1) {
          int incColour = decColour == 2 ? 0 : decColour + 1;
       
          // cross-fade the two colours.
          for(int i = 0; i < 255; i += 1) {
            rgbColour[decColour] -= 1;
            rgbColour[incColour] += 1;   
      
            setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
            delay(colorShiftTime[colorShiftTimeCounter]);
            currentCode = checkRemoteCode();
      
      /*
            Serial.print(" R:");Serial.print(rgbColour[0]);
            Serial.print(" G:");Serial.print(rgbColour[1]);
            Serial.print(" B: ");Serial.println(rgbColour[2]); 
            */     
            //if accepted new remote codes,
            //     exit this function and back to the main loop;
            if(preCode != currentCode){
              return;
            }
          }
        }
      } // End of LED color rotation
      
      
      /* This turn on/off relay switch
       *
       */
      void switchRelay(){
        relay1Status = 1 - relay1Status;   
         if(relay1Status == 0){
          digitalWrite(relay1Pin, HIGH);
          delay(500);
         }else{ 
          digitalWrite(relay1Pin, LOW);
          delay(500);
         }
      }
      
      /* Check remote code and return a mode to be changed
       *
       */
      int checkRemoteCode(){
        if (irrecv.decode(&results)) { // Received IR code and decoded ok!
          // Print to Serial port for debug purposes
          Serial.print("Color shift time: ");
          Serial.print(colorShiftTime[colorShiftTimeCounter]);
          Serial.print("  irCode: ");           
          Serial.print(results.value, HEX);    // IR decode
          Serial.print(",  bits: ");          
          Serial.println(results.bits);        // IR codes
          
          irrecv.resume();                    // Continue to receive next IR code 
          if(results.bits == 32){ //only 32bit code will be evaluated
            switch(results.value){
              /*All these buttons switch lights */ 
              case bitLight1:
              case bitLight2:
              case sanyoLight1:
              case sanyoLight2:  
              case 0x992A2843: //Benq Remote Green button for test
                   LEDstatus = 3; //switch relay;
      
                break;
              case bitLED1:
              case bitLED2:
              case sanyoLED1:
              case sanyoLED2:
                    //Check LEDstatus and switch to next mode
                    LEDstatus += 1;
                    if(LEDstatus >= 3){ 
                        LEDstatus = 0; //LEDstatus only has 0,1,2 if == 3, reset it to 0;
                    }
                break; 
              case bitLEDspeed:
              case sanyoLEDspeed:
                    colorShiftTimeCounter++;
                    if(colorShiftTimeCounter==4){ 
                        colorShiftTimeCounter=1; //only 4 elements, from 0~3
                      }
                    colorShiftTime[colorShiftTimeCounter];
                break;
              default:
                break;        
            } //switch
          } // check 32bits
        } //end of get a remote code
      
        return LEDstatus;
      }
      
      void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
        analogWrite(redPin, red);
        analogWrite(greenPin, green);
        analogWrite(bluePin, blue);
       }
      
      void loop(){
        switch(LEDstatus){
           case 0:
              ledOff();
              break;
           case 1:
              ledOrange();
              break;
           case 2:
              colorRotation();
              break;
           case 3:
              switchRelay();
              LEDstatus = 99;
              break;
           default: // set it up to do nothing, but wait the remote code to activate
               break;
        }
        //constanly check new remote code
        LEDstatus = checkRemoteCode();
        //////Serial.print("LEDstatus: ");Serial.println(LEDstatus);
      } // end of loop
      
      
      Here is the prototype in the photo below.



      In next tutorial, I will show you the 2nd phase to put everything together and install the whole system in the celling light.  See you soon!


      2015/11/15

      Arduino - IR Repeater Tutorial (Part 2)

      If you want to see the complete tutorial, please visit IR Repeater Tutorial Part 1 first.

      Test out everything on the proton board:
      It's always a good practice to test out the wiring before solder components together. 
      Connect IR receiver LED to Arduino Pro Mini



      Connect IR emitter LED through 100 Ohm resister

      The program below was created by Lauszus that I found on Gighub. The original program was written to receive IR code and decode IR then save the IR code in the memory until a button is pressed to emit IR code. To meet my requirement, I made few modifications to make it receive IR, decode IR, and then emit the IR immediately. Here is my code:

      [Programming code]
      
      /*
       * IRrecord: record and play back IR signals as a minimal 
       * An IR detector/demodulator must be connected to the input RECV_PIN.
       * An IR LED must be connected to the output PWM pin 3.
       * A button must be connected to the input BUTTON_PIN; this is the
       * send button.
       * A visible LED can be connected to STATUS_PIN to provide status.
       *
       * The logic is:
       * If the button is pressed, send the IR code.
       * If an IR code is received, record it.
       *
       * Version 0.11 September, 2009
       * Copyright 2009 Ken Shirriff
       * http://arcfn.com
       *
       * 
       * Version 0.2 October, 2015
       * Modified to remove button function 
       * This module acts a IR Repeater to just 
       * "Read the IR Code " and "Send the IR Code" immediately
       * By En-Lin Chen / Stonez56
       *
       */
      
      #include <IRremote.h>
      
      int RECV_PIN = 2;
      int STATUS_PIN = 13;
      
      IRrecv irrecv(RECV_PIN);
      IRsend irsend;
      
      decode_results results;
      
      void setup()
      {
        Serial.begin(9600);
        irrecv.enableIRIn(); // Start the receiver
        pinMode(STATUS_PIN, OUTPUT);
      }
      
      // Storage for the recorded code
      int codeType = -1; // The type of code
      unsigned long codeValue; // The code value if not raw
      unsigned int rawCodes[RAWBUF]; // The durations if raw
      int codeLen; // The length of the code
      int toggle = 0; // The RC5/6 toggle state
      
      // Stores the code for later playback
      // Most of this code is just logging
      void storeCode(decode_results *results) {
        codeType = results->decode_type;
        int count = results->rawlen;
        if (codeType == UNKNOWN) {
          Serial.println("Received unknown code, saving as raw");
          codeLen = results->rawlen - 1;
          // To store raw codes:
          // Drop first value (gap)
          // Convert from ticks to microseconds
          // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
          for (int i = 1; i <= codeLen; i++) {
            if (i % 2) {
              // Mark
              rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
              Serial.print(" m");
            } 
            else {
              // Space
              rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
              Serial.print(" s");
            }
            Serial.print(rawCodes[i - 1], DEC);
          }
          Serial.println("");
        }
        else {
          if (codeType == NEC) {
            Serial.print("Received NEC: ");
          } 
          else if (codeType == SONY) {
            Serial.print("Received SONY: ");
          } 
          else if (codeType == RC5) {
            Serial.print("Received RC5: ");
          } 
          else if (codeType == RC6) {
            Serial.print("Received RC6: ");
          } 
          else {
            Serial.print("Unexpected codeType ");
            Serial.print(codeType, DEC);
            Serial.println("");
          }
          Serial.println(results->value, HEX);
          codeValue = results->value;
          codeLen = results->bits;
        }
      }
      
      void sendCode(int repeat) {
        if(codeValue == 0xFFFFFFFF) return;  //ignore FFFFFFF IR code
        if (codeType == NEC) {
            irsend.sendNEC(codeValue, codeLen);
            Serial.print("Sent NEC ");
            Serial.println(codeValue, HEX);
        } 
        else if (codeType == SONY) {
          irsend.sendSony(codeValue, codeLen);
          Serial.print("Sent Sony ");
          Serial.println(codeValue, HEX);
        } 
        else if (codeType == RC5 || codeType == RC6) {
          if (!repeat) {
            // Flip the toggle bit for a new button press
            toggle = 1 - toggle;
          }
          // Put the toggle bit into the code to send
          codeValue = codeValue & ~(1 << (codeLen - 1));
          codeValue = codeValue | (toggle << (codeLen - 1));
          if (codeType == RC5) {
            Serial.print("Sent RC5 ");
            Serial.println(codeValue, HEX);
            irsend.sendRC5(codeValue, codeLen);
          } 
          else {
            irsend.sendRC6(codeValue, codeLen);
            Serial.print("Sent RC6 ");
            Serial.println(codeValue, HEX);
          }
        } 
        else if (codeType == UNKNOWN /* i.e. raw */) {
          // Assume 38 KHz
          irsend.sendRaw(rawCodes, codeLen, 38);
          Serial.println("Sent raw");
        }
      }
      
      
      void loop() {
      
        if (irrecv.decode(&results)) {
          /* Receive IR code */
          Serial.println("Pressed!");
          digitalWrite(STATUS_PIN, HIGH);
          storeCode(&results);
          irrecv.resume(); // resume receiver
          digitalWrite(STATUS_PIN, LOW);
          delay(50);
          
          /* Send IR code */
          Serial.println("Sending!");
          digitalWrite(STATUS_PIN, HIGH);
          sendCode(true);
          digitalWrite(STATUS_PIN, LOW);
          delay(50); // Wait a bit between retransmissions
          irrecv.enableIRIn(); // Re-start the receiver
          Serial.println("--------------------------------");
        } 
      }
      

      After programming code is copied into Arduino IDE, upload it to your Arduino Pro Mini.

      Power it up and then use any remote control to point to IR receiver and observe the Arduino IDE Serial output screen.  Turn on Serial Monitor: Arduino -> Tools->Serial Monitor


      Here shows you the IR command received through the serial port monitor.

      Received NFC: FFA252D (Remote type is NEC, and the code is 0xFFA25D)
      Sent NEC: FFA25D


      After fully tested, it's time to solder everything together.
      First, solder IR emitter LED to the extended long wires. Although not showing at the photo below, an 100 Omh resistor is needed on the data pin 2.



      I soldered the IR receiver LED on small proton board to allow me to fix it into the IR BOX easier. 
      To provide constant power, I decided to use a smart phone power adaptor through a USB connector.


      There are 4 tiny wires in the USB cable and you only need black and red wire to supply power to Arduino Pro Mini.  Red connects to VCC and Black connects to Ground.


      I've chosen to use a name card case as the enclosure. I drilled a tiny hole in the front of the name card case (see below), to expose IR receiver LED towards the edge.


      Too often, accidentally pulling the wires will break the soldering part, so I tight a knot on the extended long wires to secure wires in place. 

      Now, every parts are soldered together as you see below.

      Emitter board and Arduino Pro Mini placement is looked like this below.

      Then, I glue the entire board with a glue gun to secure PCBs inside the name card box.

      Plug the USB adaptor to power it up. Great! It's working.

      Below is how this project looked like. As you can see, the extended wires are almost five to seven meters long.


      Setup:
      Follow IR Repeater Setup Illustration in Tutorial Part 1 
      1. Place IR BOX next to your TV and plug the USB adapter
      2. Pull the IR emitter with the wire through the wall into the living room
      3. Make sure the IR emitter is aiming towards the IR receiver on the Set Top Box
      4. I glue the IR emitter LED next to my couch and it working fine
      5. Done

      After the setup, I've been use this IR repeater for 2~3 weeks and it's working perfectly without any issue. If you would like to make your own, you can follow this tutorial!

      See the video below, if you haven't!


      END.

      ==================================================

      如果你要閱讀完整的教學,請參考第一篇教學

      在洞洞板上試著做做看:
      把所有電子零件都焊起來之前,我們最好利用洞洞板來測試一下,可以正常運作後才做焊接。請參考上圖,先用跳線把紅外線接收LED連線到  Arduino Pro Mini。



      連接100歐姆電阻到紅外線發射 LED 正極

      簡單的連線後,大致就完成了。接下來把下面的程式碼上傳到 Arduino 。

      [程式碼請參考英文版內文]

      上方的程式碼的原作者是 Lauszus  (Github) ,此程式原本是要接受到紅外線解碼後,儲存在記憶體中,在使用者按下一個按鈕後才由紅外線發射 LED 發射出訊號。
      為了符合這個 IR BOX 的需求,我做了一些修改,讓它收到後直接發射出紅外線編碼。
      接上 5V 電源,利用 MOD 的搖控器對準 IR 接收LED。你可以在 Arduino IDE 的 Serial Monitor 上觀查 IR BOX 接收與傳出 IR Code 的資料。
      打開 Serial Monitor 的方式: Arduino -> Tools->Serial Monitor 參考下圖:




      Received NFC: FFA252D (Remote type is NEC, and the code is 0xFFA25D)
      (IR 接收解碼為:FFA252D 搖控器類型 NEC)
      (IR 發射碼)Sent NEC: FFA25D

      一切測試無誤後,可以開始動手把零件焊在一起。
      先把 IR 發射 LED 焊到加長的電線上,別忘了在 LED 資料前焊上一個 100 歐姆的電阻(我底下的照片沒有這個電阻)。這個 IR 發射 LED 和兩條 7.5 公尺的電線就是要穿過牆放到到客廳裡。


      我把 IR 接收 LED 焊在一塊洞洞板上,這樣可以讓 IR LED 固定的更好。
      這個模組需要一個 5V 的電源長期供電才能運作,所以我找來一個手機的 5V 充電器來供電。


      先把 USB 電源線剪一小段並剝去外面包覆的絕緣層。裡面有四條電線,我們只需要把紅色的焊接到 Arduino 正極(VCC),黑色的焊接到 Arduino 負極(GND),再把 USB 插到手機充電插頭即可以供電。


      手上臨時找到了一個名片盒,就拿它來當做 IR BOX 的外殻吧!(好...我承認它不太美觀 ...Orz..)先在名片盒的側面鑽個小孔,只要讓 IR 接收 LED 可以外露出來,接受紅外訊號即可;如下圖:


      接著,把延長的電線穿到名片盒後打上一個結固定好,以避免不小心拉扯電線時,把焊點拔斷了!

      再接著,把電源焊到Arduino Pro Mini,並把線路依圖示都焊上。

      再把焊有紅外接收 LED 的洞洞皮放到名片盒裡試試看那個位置合適。

      確定 IR LED 有露出到剛剛鑽孔的位置,再把Arduino Pro Mini 位置確定後,用很多的膠固定電路板的位置;如下:

      接上 USB 電源後紅色 LED 亮起,表示 IR BOX 已正常的運作了,太好了!

      我做的 IR BOX(紅外線轉發器)整個看起來就像下面一樣。IR BOX 連著長長的電線(7.5公尺),電線的尾端則是 IR 發射LED 。

      安裝:
      依照教學的 Part 1 紅外線轉發器安裝方法圖示:
      1. 把 IR BOX 放在房間適當位置固定並插入電源
      2. 把長長的電源線和 IR 發射LED 穿過牆壁,
      3. 確認IR 發射LED 拉到能正對著機上盒的紅外接收位置 (Set Top Box)
      4. 我用膠槍把 IR LED 固定在沙發旁邊。
      5. 完成

      安裝好後,我已經用了兩三個星期了,而且整個 IR 轉發器運作都很順利。
      如果你也想要自己 DIY 一個話,可以自己開始動手了!!

      如果你還沒有看過實際運作的影片,請按底下播放。


      全文完.

      2015/11/08

      Arduino - IR Repeater Tutorial (Part 1)

      Goal: 
      To share a Set Top Box in living room with Bedroom TV using the same Remote Control.

      Preface: 
      Recently, I subscribed a VOD (Video On Demand) service that came with a Set Top Box in the living room. However, I would like to occasionally watch VOD in the bedroom, but the Set Top Box is in the living room. As you know, there is no way to control the Set Top Box in the living room from the bedroom.  Yeah, an IR repeater is all I need. There are commercial products available in the market already, but I quickly thought about the Control celling light with a TV remote Arduino project I have done before might be an replacement for the IR repeater I need. After all, this is why I learn Arduino - May my life easier!!

      Drawbacks of this project:
      Either one VOD TV program can be watched from living or bedroom at a time, since the Set Top Box is shared. 


      Arduino Programming Logic:
      The programming logic to repeat the IR signal is quite simple
      • Receive remote control signal from IR receiver
      • Decode the IR code
      • Send the decoded IR code from the IR emitter

      IR Repeater Setup Illustration:
      The illustration below shows you how the whole IR Repeater is setup in my apartment to share Set Top Box in two rooms.
      1. Living Room TV
      2. Bedroom TV
      3. Set Top Box (HDMI out connect to a HDMI switch, yes you need this!)
      4. HDMI cable from Set Top Box to bedroom TV
      5. Arduino IR Box 
      6. IR Emitter
      7. A hole on the wall
      * The IR remotes shown below are actually the same remote

      Working IR Repeater Prototype Video:
      See the working prototype in the video below. As you can see, even through the IR repeater, the Set Top Box response time is fairly quick!


      Material Needed:
      1. Arduino Mini Pro
      2. IR Emitter 940nm * 1 
      3. IR Receiver LED, Aixin AX-1838HS 38KHz * 1 (Other brand 38KHz should work)
      4. ProtoBoard * 1
      5. 100 ohm resistor * 1
      6. Short Jump wires * 10 
      7. 5 meter long single wires * 2 

      LED Lineup:
      Starts from the left: IR LED receiver, IR LED emitter, green LED, and red LED.
      In the end, I didn't use red and green and LED, but relied on the Arduino built-in red LED on pin 13 and Serial port green LED in this project.



      IR Repeater Wiring:
      Wiring up is quite easy as you can see below. (I forgot to draw the 100 Ohm resistor in the illustration below, but you need it.)
      1. IR Emitter GND to GND
      2. IR Emitter Data to 100 Ohm resistor to Arduino pin 3
      3. IR Receiver Data to Arduino pin 2
      4. IR Receiver GND to Arduino GND
      5. IR Receiver VCC to Arduino VCC
      6. Proton board GND to power source GND
      7. Proton board VCC to power source VCC (USB power adapter)

      In part 2, I will show you how I made the IR Repeater box, schematic, and Arduino code I modified from github by Lauszus. If you are interested, you may take a look at the code first.

      To be continued. 

      ------------------------------

      目的: 
      不用另外租用一個額外的 MOD 機上盒,只要使用同一個搖控器,該你在臥室裡也可以觀看客廳所訂閱的中華電信 MOD! 

      前言: 
      最近,我訂閱了中華電信MOD系統,我把機上盒放在客廳裡。但是,我偶爾想在臥室裡收看MOD。可是機上盒在客廳裡,要怎麼辦呢?大家都知道,我不可能從臥室裡控制位於客廳的MOD。是的,我只需要一個紅外線(轉發器, 這個名詞正確嗎?)。市面上的相關產品有一大堆,但是我很快的想起我以前做的 以電視遙控器控臥室天花板電燈開關。這就是為什麼我要學Arduino - 讓我生活的更方便!

      此作品之缺點:
      因為機上盒是共用的,所以無法同時在客廳和臥室一起觀看不同的頻道。

      Arduino 程式邏輯:
      要讓紅外線信號重複的邏輯還蠻簡單的

      • 用紅外線接收器接收遙控器的信號
      • 將紅外線信號解碼
      • 從紅外線發射器傳送出解過碼的IR信號

      紅外線轉發器安裝方法示圖
      下圖展示出整個紅外線轉發器是如何安裝在我的家裡,使得兩個房間能分享機上盒。
      1. 客廳電視
      2. 臥室電視
      3. 機上盒
      4. HDMI延長線要從臥室電視連到機上盒
      5. Arduino紅外線轉發器
      6. 紅外線發射器
      7. 牆上的鑽孔
      *下圖中的兩個遙控器代表同一個遙控器



      紅外線轉發器原型運作影片:
      請看以下的原型運作影片  可以看到即使經過轉接器 機上盒的反應仍舊相當迅速

      所需材料:
      1. Arduino Mini Pro * 1
      2. 紅外線發射 LED 940nm * 1
      3. 紅外線接收 LED Aixin AX-1838HS 38KHz * 1 (只要是 38KHz 應該就能用)
      4. 麵包板 * 1
      5. 100歐姆電阻 * 1
      6. 短跳線*10
      7. 7.5 米長電線


      各式 LED:
      由左算起,IR 接收 LED, IR 發射 LED, 綠色 LED, 紅色 LED
      這個專案裡,我最後沒有用到綠色 LED, 紅色 LED,我用的 Arduino 內建在13腳的紅色 LED, 和 Serial port 訊號的 LED.



      紅外線轉發器接線方式:
      接線很簡單,請參考下圖:(我忘了畫 100 Ohm 電阻,不過我們需要這個電阻)
      1. IR Emitter GND to GND
      2. IR Emitter Data to 100 Ohm resistor to Arduino pin 3
      3. IR Receiver Data to Arduino pin 2
      4. IR Receiver GND to Arduino GND
      5. IR Receiver VCC to Arduino VCC
      6. Proton board GND to power source GND
      7. Proton board VCC to power source VCC (USB power adapter)

      接好了嗎?很簡單吧!
      在第二段教學裡,我會把我如何用手邊棄不用的東西來製作紅外線轉發器的外盒(不是很好看,但墈用),及分享我用的程式碼。如果你等不及,那你可以參考 Github by Lauszus. 我就是用這位前輩的程式碼來修改完成這個作品的。

      未完待續...