we learned how to use the SD card. This time, we will use the infrared remote control receiver module and an infrared LED to create an infrared remote control. Most of the TV and air conditioning remote control are using infrared rays. Let’s analyze the remote control signal, and control our electronic devices using Arduino as a remote control to transmit the signal.
Today’s Electronic Recipe
Expected time to complete: 90 minutes
Parts needed:
- Arduino (Arduino Mini Pro) http://ift.tt/1zFuYR3
- Breadboard http://ift.tt/1z7Tzip
- 5mm infrared LED OSI5LA5113A http://ift.tt/1r3ihhI
- CDS sensor (light sensor) http://ift.tt/1XLTCbZ
- Tact switch http://ift.tt/1r3ijpV
- Resistor (220Ω)
What are Infrared Rays?
We often see the word “infrared” in terms such as “Infrared data communication”, “infrared camera”, “far infrared rays heater”, and so on. But what is it exactly? Let’s have a look at Wikipedia.
Infrared – Wikipedia
Infrared (IR) is invisible radiant energy, electromagnetic radiation with longer wavelengths than those of visible light. Most of the thermal radiation emitted by objects near room temperature is infrared.The below figure shows the electromagnetic waves classified by wavelength.
Figure 1 Electromagnetic spectrumInfrared Communication Basic Mechanism
Let’s see how things like remote control use infrared for signal transmission.
Basically, it is sending a command to switch on/off the infrared LED.
Figure 2 Remote control signal basicUsually, infrared remote controls used with consumer electronic appliances have a common format. Japanese consumer electronics infrared remote controls use the three below formats.
Typical formats
- NEC format
- Home Appliance Cooperation format
- SONY format
Figure 3 NEC format schematic diagram
For example, the NEC format will send out the leader signal as a cue to send a command from the remote control. Next, it sends a data signal, then it sends a stop signal format. These three formats used this basic format. If you hold down the button of the remote control, the signal is sent repeatedly, but this differs depending on the consumer electronics manufacturers. If you want to make it, you need to analyze the signal directly read from a remote control, like a “learning remote”.
※ If you want to know more about the format analysis, you should be able to find a variety of code by searching for “infrared remote control code”, “infrared analysis” and such.
Remote Control Signal Frequency
Infrared is coming from everywhere, the sun, the light, and so on. To differentiate it from the light, most of the remote controls are set to a 38KHz frequency. This time, the infrared receiver module we will use also support the 38KHz frequency.
Try to Send and Receive Infrared with Arduino
Let’s try to receive infrared signals on the Arduino. We will use an infrared remote control receiver module SPS-440-1 which can used as a receiving part for TV too. The receiving frequency is 38kHz, and it can connect directly to the Arduino as the required circuit is already built. In addition, an infrared LED is used for the transmitter.
Picture 1 Infrared receiver module
Picture 2 Infrared LEDThe figure below shows the circuit to connect the infrared receiver module to Arduino.
Figure 4 Infrared circuit
Picture 3 Infrared receiver module and the ArduinoThe next step is about the program. Regarding the infrared analysis, we will use the Github public Arduino-IRremote library. You can download the source on the right sidebar at the bottom. Add the downloaded source by going to “Sketch”, “Include Library”, then “Add .ZIP Library”. If the files have been successfully added, you can see that “IRremote” library has been added in “Sketch”, “Include Library”. If you can’t find it, you can unzip the downloaded file, move the folder to the Arduino libraries directory, and restart it.
shirriff / Arduino-IRremote
http://ift.tt/P0Xp3d
Figure 5 Download the library
Picture 6 Adding the libraryWe will create a program to use this library. IRremote library includes a sample program that you can use to test the receiver. This program displays the format and the data analyzed of the infrared signal input from the pin 11.
Program: analysis of the infrared signal
Code-Example 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091/*
* IRremote: IRrecvDump - dump details of IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
* LG added by Darryl Smith (based on the JVC protocol)
*/
#include <IRremote.h>
int
RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void
setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
// Start the receiver
}
// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
// decode_results *results = (decode_results *)v
void
dump(decode_results *results) {
int
count = results->rawlen;
if
(results->decode_type == UNKNOWN) {
Serial.print(
"Unknown encoding: "
);
}
else
if
(results->decode_type == NEC) {
Serial.print(
"Decoded NEC: "
);
}
else
if
(results->decode_type == SONY) {
Serial.print(
"Decoded SONY: "
);
}
else
if
(results->decode_type == RC5) {
Serial.print(
"Decoded RC5: "
);
}
else
if
(results->decode_type == RC6) {
Serial.print(
"Decoded RC6: "
);
}
else
if
(results->decode_type == PANASONIC) {
Serial.print(
"Decoded PANASONIC - Address: "
);
Serial.print(results->panasonicAddress,HEX);
Serial.print(
" Value: "
);
}
else
if
(results->decode_type == LG) {
Serial.print(
"Decoded LG: "
);
}
else
if
(results->decode_type == JVC) {
Serial.print(
"Decoded JVC: "
);
}
else
if
(results->decode_type == AIWA_RC_T501) {
Serial.print(
"Decoded AIWA RC T501: "
);
}
else
if
(results->decode_type == WHYNTER) {
Serial.print(
"Decoded Whynter: "
);
}
Serial.print(results->value, HEX);
Serial.print(
" ("
);
Serial.print(results->bits, DEC);
Serial.println(
" bits)"
);
Serial.print(
"Raw ("
);
Serial.print(count, DEC);
Serial.print(
"): "
);
for
(
int
i = 0; i < count; i++) {
if
((i % 2) == 1) {
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
}
else
{
Serial.print(-(
int
)results->rawbuf[i]*USECPERTICK, DEC);
}
Serial.print(
" "
);
}
Serial.println(
""
);
}
void
loop() {
if
(irrecv.decode(&results)) {
Serial.println(results.value, HEX);
dump(&results);
irrecv.resume();
// Receive the next value
}
}
After uploading the program to the Arduino, direct the remote control of a TV (for example) towards the infrared received, and press a button on the remote control. The data signal will be displayed in the serial monitor.
Figure 7 Infrared signal outputs from the remote controlNext, let’s try the sending program for the remote control signal. To use the sending program, we will need to use the source of the library. In Arduino’s “libraries” directory, open IRremote.h, add the source of the blue frame #define… (Below figure), and then save. Now, you can send signals in accordance with each format.
Figure 8 Editing IRremote.hAfter completing the IRremote.h compilation, we will write an Arduino program. In the sample example, when pressing the tact switch, the program will send three times the signal to turn on the TV in the Sony format.
Program infrared transmitter circuit
Code-Example 123456789101112131415161718#include <IRremote.h>
IRsend irsend;
int
sensorPin = A0;
void
setup()
{
Serial.begin(9600);
}
void
loop() {
int
sensorValue = analogRead(sensorPin);
//Serial.println(sensorValue);
if
(sensorValue == 0){
for
(
int
i = 0; i < 3; i++) {
irsend.sendSony(0xa90, 12);
// Sony Signal of TV power ON in the format
delay(40);
}
}
}
Figure 9 Infrared remote control circuit
Picture 4 Infrared transmitter circuitI tried to transmit the signal to the TV (※ the program slightly changed. A repeated signal is sent every 5s to turn-on/turn-off the TV).
We can now turn a TV on/off with Arduino!
Summary
This time, we have been using the infrared receiver module and the infrared LED to send and received signals from an infrared remote control. Next time, we will try to combine the infrared sensor, the temperature sensor, the light sensor, and other sensors to make a smart controller for our electronic devices.
View more at: http://yoursmart.mobi
Post a Comment