In this tutorial, we will use an infrared (IR) Receiver and along with Surilli GSM and Arduino to control the LED using a Remote Control. This is useful to re-use old remote controls or give some functionally to some of your remote’s buttons.
Infrared (IR) communication is a widely used and easy to implement wireless technology that has many useful applications. The most prominent examples in day to day life are TV/video remote controls, motion sensors, and infrared thermometers.
There are plenty of interesting Arduino projects that use IR communication too. With a simple IR transmitter and receiver, you can make remote controlled robots, distance sensors, heart rate monitors, DSLR camera remote controls, TV remote controls, and lots more.
What Is an Infrared?Infrared radiation is a form of light similar to the light we see all around us. The only difference between IR light and visible light is the frequency and wavelength. Infrared radiation lies outside the range of visible light, so humans can’t see it.
Because IR is a type of light, IR communication requires a direct line of sight from the receiver to the transmitter. It can’t transmit through walls or other materials like WiFi or Bluetooth.
How IR Remotes and Receivers WorkA typical infrared communication system requires an IR transmitter and an IR receiver. The transmitter looks just like a standard LED, except it produces light in the IR spectrum instead of the visible spectrum. If you have a look at the front of a TV remote, you’ll see the IR transmitter LED.
The same type of LED is used in IR transmitter breakout boards for the Arduino.
The IR receiver is a photodiode and pre-amplifier that converts the IR light into an electrical signal.
IR light is emitted by the sun, light bulbs, and anything else that produces heat. That means there is a lot of IR light noise all around us. To prevent this noise from interfering with the IR signal, a signal modulation technique is used.
In IR signal modulation, an encoder on the IR remote converts a binary signal into a modulated electrical signal. This electrical signal is sent to the transmitting LED. The transmitting LED converts the modulated electrical signal into a modulated IR light signal. The IR receiver then demodulates the IR light signal and converts it back to binary before passing on the information to a microcontroller.
The modulated IR signal is a series of IR light pulses switched on and off at a high frequency known as the carrier frequency. The carrier frequency used by most transmitters is 38 kHz, because it is rare in nature and thus can be distinguished from ambient noise. This way the IR receiver will know that the 38 kHz signal was sent from the transmitter and not picked up from the surrounding environment.
The receiver diode detects all frequencies of IR light, but it has a band-pass filter and only lets through IR at 38 kHz. It then amplifies the modulated signal with a pre-amplifier and converts it to a binary signal before sending it to a microcontroller.
IR Transmission ProtocolsThe pattern in which the modulated IR signal is converted to binary is defined by a transmission protocol. There are many IR transmission protocols. Sony, Matsushita, NEC, and RC5 are some of the more common protocols.
The NEC protocol is also the most common type in Arduino projects, so I’ll use it as an example to show you how the receiver converts the modulated IR signal to a binary one.
Logical ‘1’ starts with a 562.5 µs long HIGH pulse of 38 kHz IR followed by a 1,687.5 µs long LOW pulse. Logical ‘0’ is transmitted with a 562.5 µs long HIGH pulse followed by a 562.5 µs long LOW pulse.
This is how the NEC protocol encodes and decodes the binary data into a modulated signal. Other protocols differ only in the duration of the individual HIGH and LOW pulses.
IR CodesEach time you press a button on the remote control, a unique hexadecimal code is generated. This is the information that is modulated and sent over IR to the receiver. In order to decipher which key is pressed, the receiving microcontroller needs to know which code corresponds to each key on the remote.
Different remotes send different codes for the key presses, so you’ll need to determine the code generated for each key on your particular remote. If you can find the datasheet, the IR key codes should be listed. If not though, there is a simple Arduino sketch that will read most of the popular remote controls and print the hexadecimal codes to the serial monitor when you press a key.
When you press your remote control, it sends infrared modulated signals. These signals contain information that your receiver collects.
Each button sends specific information. So, we can assign that information to a specific button.
Connections Between IR Receiver, Surilli GSM and LED:- PIN (LED) ---> GND PIN (SURILLI GSM).
+ PIN (LED) connected to one pin of 1k ohm Resistor whereas the other pin of Resistor is connected to PIN 13 of SURILLI GSM.
- PIN (IR RECEIVER) ---> GND PIN (SURILLI GSM).
S PIN (IR RECEIVER) ---> PIN 11 (SURILLI GSM).
MIDDLE PIN (IR RECEIVER) ---> USB PIN (SURILLI GSM).
Set Up Arduino IDE for SurilliMake sure you have selected the right port, board and processor for the Surilli as shown in the picture below and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
The CircuitryThe circuitry is very simple. It's mostly the programming. Follow the figure below to set up your hardware.
1. First of all download the IR Remote Library from the link given below:
https://github.com/z3t0/Arduino-IRremote
2. After downloading the library, you should have a .zip folder in your downloads folder.
3. Now open your Arduino IDE and then navigate to Sketch on the upper toolbar and then select "Include Library."
4. After that select "Add .zip library..." and select the .zip file that you have just downloaded.
5. After doing this, you will see a message in below blue region that the file has been included into your documents folder.
6. Now, close Arduino IDE and then navigate to Documents-->Arduino-->libraries. There you will see that the library has been added to the default libraries of Arduino IDE.
7. Open Arduino IDE again and then go to Sketches --> Include Library and just below "Add .zip library...", you will see your library.
Upload and Burn Code Onto SurilliNow you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE. Make sure that you have the right board and COM port selected.
Arduino Code:#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
int IR_Recv = 11; // IR Receiver Pin 11.
int led = 13; // LED Pin Connected to Pin 13 of Surilli GSM.
IRrecv irrecv(IR_Recv);
decode_results results;
void setup(){
Serial.begin(9600); //starts serial communication
irrecv.enableIRIn(); // Starts the receiver
pinMode(led, OUTPUT); // sets the digital pin as output
}
void loop(){
//decodes the infrared input
if (irrecv.decode(&results)){
long int decCode = results.value;
Serial.println(results.value,DEC);
//switch case to use the selected remote control button
switch (results.value){
case 3772784863: //when you press the 1 button
digitalWrite(led, HIGH);
break;
case 3772811383: //when you press the 0 button
digitalWrite(led, LOW);
break;
}
irrecv.resume(); // Receives the next value from the button you press
}
delay(10);
}
After uploading the above code, open the Serial Monitor at a baud rate of 9600.
If you press number 0 of your TV Remote, some codes will appear on the Serial Monitor which will be in decimal form and at the same time, the LED will remain OFF.
Similarly, if you press 1 of your TV Remote, some codes in decimal form will appear on the Serial Monitor and at the same time, you can see that the LED will be ON.
Play with the program to see how it reacts to different values and logic.
If you make something fun and interesting, do share it with our community.
That’s all for now. If you have any queries, visit surilli.io or contact our support. Stay connected with the Surilli family for more amazing stuff. :-)
Comments