How to Make Arduino Remote Control Light Switch

Controlling your light switch using a remote control from the comfort of your bed sounds good and convenient, such wireless communication system is one of the comforts you can create for yourself using arduino.

  • In this tutorial you will learn how to make a remote control lamp holder.
Video of how to design the remote controlled Lampholder

Components needed for the prototype design of Arduino remote control light switch include:

  • One Arduino Nano board
  • Car MP3 SE-020401 Infrared (IR) remote control
  • AA3P TK19 Infrared receiver
  • 5 volts Relay
  • Adjustable 12 volts AC-DC power supply
  • One bread board
  • Bunch of jumper wires
  • Lamp holder
  • One 100Ω 1/2W resistor
  • One IN4001 diode

Most electronic devices at home and offices use remote control; televisions, air conditioner, stereo player, DVD, etc. most buttons on these remote control devices are not often used. Instead of having these buttons useless, you can program them to work with arduino and enjoy more convenience with them. However, to make your design unique, you can use a new remote controller altogether. A typical less expensive, easy-to-get and programmable remote control you can use is the one shown in figures 2 and 3 below.

The three main components for Arduino Remote Control Light Switch

The three main components to make arduino remote control light switch are the arduino microcontroller board, the IR transmitter (remote control) and the IR receiver sensor.

Arduino Microcontroller Board:

We have already discussed how to use an arduino board in the previous tutorial; you may want to go through that tutorial first.

arduino-nano-1
Figure 1: Arduino Nano

Infrared (IR) Remote Control [Transmitter]:

Infrared (IR) remote control is a remote control that sends out infrared light from an IR LED. Infrared is one of the frequencies or wavelengths found in the electromagnetic spectrum with a wavelength longer than that of the visible light (700nm-1mm), hence we cannot see most infrared radiations with our  eyes’ lenses, but, a smart phone camera’s lens can view it. So, put your remote control under a smart phone camera and press a button, you will see the remote control LED blinking (at a frequency of 38,000 Hz or 38 KHz per second). Information can be encoded into this wave at this frequency to make it unique and different from other IR waves in the environment, this process is called modulation, the information can then be sent to a receiver sensor which receives and demodulates the information for interpretation and usage with the help of a micro-controller.

Car MP3 SE-020401 Infrared (IR) remote control
Figure 2: Car MP3 SE-020401 Infrared (IR) remote control
KEYES remote control
Figure 3: KEYES remote control

Infrared Receiver Sensor [Receiver]:

This sensor receives the information encoded in the infrared light from the remote control and demodulates the wave to extract the encoded information. The information is subsequently sent to a microcontroller for processing, in this case, the arduino board contains the microcontroller which is an ATmega 32p-pu integrated circuit. For this project, we will use an AA3P TK19 IR sensor receiver shown below.

AA3PTK19 IR sensor receiver
Figure 4: AA3PTK19 IR Sensor Receiver

To use an IR remote control to program a circuit, you need to first extract some information from the remote control, which you can use to program the circuit. To extract the information encoding hexadecimal files of an IR remote control, you need to do some tinkering using arduino and an IR receiver like the AA3Ptk19 shown above. Connect the circuit as shown below:

Hex files extraction circuit
Figure 5: Hex files extraction circuit

After you have connected the circuit, connect the arduino board to a PC that has arduino IDE. Follow the steps below to program the circuit. You have to first download the IRremote library by Ken Shirriff.

  1. Open the arduino IDE
  2. Go to Sketch → Include library → Manage libraries
  3. Type and search for IRremote , install the IRremote by Ken Shirriff
  4. After installing the library, close the download page
  5. Go to File → Example → IRremote → IRrecvDemo

You will see a sketch like the one shown below

Sketch to extract HEX files from a remote control
Sketch to extract HEX files from a remote control

Upload the sketch and open the serial monitor console window to view the extracted codes. Follow the procedure:

Go to:  Tools → Serial Monitor or use the shortcut (Ctrl+Shift+M)

Aim the remote control at the AA3P TK19 IR receiver sensor, press the buttons and you will see that any button you pressed has associated with it a code that is displayed on the serial monitor console window. You can copy the codes associated with each button. For the remote we are using, here are the button codes:

Figure 7: Car MP3 SE-020401 Infrared (IR) remote control scan codes (courtesy of www.github.com).

Having extracted the codes, it’s time to use the codes to program our circuit.

Firstly, connect the circuit as shown below. I tactically combined Fritzing and some windows Image editor to get the pictorial image.

Arduino light switch
Figure 8: Physical diagram of the design

Circuit Connection Explanation of Arduino Remote Control Light Switch

  1. Connect the 5v pin of the arduino to the middle lead of the IR receiver
  2. Connect one end lead of the IR receiver (the one nearest to the middle lead) to the ground pin of the arduino
  3. Connect pin 7 of the arduino to the far end lead of the receiver
  4. Connect the collector lead of the transistor to the anode lead of the diode and one lead of the power supply leads of the relay.
  5. Connect the base lead of the transistor to one lead of the 100Ω resistor
  6. Connect the emitter lead of the transistor to the ground pin of the arduino and the ground point of the AC-to DC power supply
  7. Connect the second lead of the resistor to pin 10 of the arduino
  8. Connect the cathode lead of the diode to the other power supply lead of the relay and the ADJ 12 volts point of the power supply.
  9. Connect the common lead of the relay to the AC supply point of the AC-DC power supply.
  10. Connect the normally open lead of the relay to one lead of the lamp holder.
  11. Connect the other lead of the lamp holder to the other AC point of the AC-DC power supply.

After making the connections, connect your arduino board to the PC, check for COM port connection.

#include <IRremote.h>                         //include the IRremote Library
int RECV_PIN = 7;                                  //set (declare) the pin of the arduino that will receive the demodulated IR signal
   const int light_switch = 10;                 //declare a variable to take up light_switch (the arduino pin that gives output signal for light switching)
     boolean last_state_of_light_switch; //declare a boolean data type to keep track of the state of light_switch 
         IRrecv irrecv(RECV_PIN);            //create an object (code) in the arduino that will receive the signal from the pin declared above
           decode_results results;             //create an object (code) in the arduino that will decode the signal that has been received above
         void setup()                                 //the code within this function runs once when the arduino comes ON
         {
       irrecv.enableIRIn();                      //Trigger the Receiver object above(code for receiving signal from the IR receiver device) to start receiving 
     pinMode(light_switch, OUTPUT);    //Declaring light_switch as output
   last_state_of_light_switch=LOW;    //initialising last state of light_switch as LOW
  }
void loop()                                           //the codes withing this function runs continuously when the arduino comes ON
  {  
   if(irrecv.decode(&results))              //Check if a signal has been received, if yes, then decode the results
    {
      switch(results.value)                   //switch over to working with the "result" that will be received and decoded
        {
          case 0XFF30CF:                           //for the signal that has the file code 0xFF87F execute the codes below and stop at break 
if(last_state_of_light_switch == LOW) //equate LOW to the last_state_of_light_switch if the condition is true    
        {
      digitalWrite(light_switch, HIGH);     // prompt the light_switch to output a HIGH voltage(5v)
    delay(10);                                         // delay for 50  milliseconds ( i.e, no other codes below will be executed until 50 milliseconds passes         
 last_state_of_light_switch=HIGH;     //initiate last_state_of_light_switch to be HIGH
}
 else                                                    //otherwise (i.e, if the condition executed above is not in line with the if command                
   {
     digitalWrite(light_switch,LOW);    //prompt the light_switch to output a LOW voltage(0v)
      delay(10);                                   //delay for 50 milliseconds (i.e, no other codes below will be executed until 50 milliseconds passes 
       last_state_of_light_switch= LOW;   //initiate the last_state_of_light_switch to be LOW
        }
         break;                                           //end of the case situation above
          }
        irrecv.resume();                           //Initiate the IR receiving pin to start receiving again 
        }
         }

Download Code here, or copy and paste the code above in your Arduino IDE. Your sketch should look like this for Arduino IDE:

Arduino sketch for the design in arduino IDE
Figure 9: Arduino sketch for the design in arduino IDE

If you are using Fritzing code editor, your code should look like the image below:

Arduino codes for the design using Fritzing code editor
Figure 10: Arduino codes for the design using Fritzing code editor

I explained each code line of the sketch after the double solidus character or forward slash. In arduino programming, anything written after the double slash in same line has no impact on the program. It is used to make comment on each line of the sketch as I did in this sketch.

Circuit explanation of Arduino Remote Control Light Switch

If you upload the sketch (arduino source code is called sketch) above to the arduino, connect an Alternating current (ac) light bulb to the lamp holder then press the button marked 1 on the remote control, the light bulb will come ON, and when you press the button again, the light bulb will go OFF. Now, if you watch closely, you will discover that we used the hex file data of the remote button marked 1 to write the program. Check figure 7 and line 19 of the arduino IDE sketch screen shot in figure 9 to confirm this. We used the information from the remote to write the sketch. You can use any of the hex file data to write the sketch.

How the circuit is implemented

When you press the button marked 1 the first time, after powering the arduino board, the IR remote control sends out a data modulated signal to the environment, the IR receiver sensor receives the signal, demodulates it, then sends the demodulated information to pin 7 of the arduino microcontroller board, the microcontroller processes the information and prompts pin 10 of the arduino board to output 5volts DC signal, this 5volts is sent to the base of the TIP122 power transistor via the 100Ω current limiting resistor. When the transistor is driven to its saturation point, DC voltage moves from the AC-DC power supply through the relay, enters the transistor’s collector and flows down to its emitter and from the emitter to ground. As current passes through the relay, it is energized to switch. As the relay switches with a click sound, it closes its normally open switch, thereby creating a conducting part for 220volts current to flow from the power supply to one lead of the lamp holder, and then switches ON the light bulb which is connected to the lamp holder, then, it flows to the other lead of the lamp holder and through that part returns to the other 220volts supply point of the power supply. In this process, we have switched ON the light bulb using the remote control.

To turn OFF the light bulb, we press the button marked 1 again, when we do that, the same first three actions taking in the first case will be repeated, however, the microcontroller senses that the button has been pressed the second time, it prompts pin 10 of the arduino to output 0volts, and when this happens, the transistor will switch over to cut-off mode, the relay will be de-energised with its contacts returning to normally closed, and when this happens no 220v current will flow from the power supply to the light bulb and the bulb will go OFF.

The function of the diode is to gradually damp the excess inductive voltage that is generated in the relay coil when it is de-energised.

Summary

  • With arduino we can design a remote control light switch using IR transmitter and receiver.
  • The remote transmits modulated data
  • The receiver receives and demodulates the data and sends result to the microcontroller
  • The microcontroller switches a transistor through which a relay is energised or de-energised
  • The energised or de-energised relay switches ON or OFF the light bulb via 220v ac power supply.

Leave a Reply

Your email address will not be published. Required fields are marked *