In this lesson, we will see how they are used in Arduino infrared signals. Who among us does not have a remote control in the house, such as the one to turn on and turn off the TV? Well today will understand how our TV is able to determine the key pressed by our remote control.
Supports hardare required for these programs are few. In fact, over the same Arduino, we will have to procure on Ebay an IR receiver, with its remote control and an infrared LED, can send signals. Here is a list of possible products that can be purchased on ebay:
The cost of these devices is very little and is around 5 Euro.
From the perspective of software you need to download the official library for Arduino, from this link:
How does an infrared transmission?
The operating mechanism of an infrared transmission is quite "simple"; a light beam, high-frequency 38 KHz (typical for the remote controls for TV) is projected against a receiver. This light beam is no more than a sequence of bits (0 and 1) that is encoded by the receiver, through the polarization of photo-transistors. Let's make this simple case; in our remote control, encryption of the various pulsed with various sequences and bits for example the on / off button is:
010101001110
The receiver will have a received signal very similar, if not equal to the one sent and based on the correspondence which has the memory, will be able to perform the actual request, such as turning on the TV! The light beam that is sent from the remote control, you can not see it with the naked eye because it has a rate too fast for us!
However, there are different encodings; typically each producer of technological devices, has its own coding, such as Sony, NEC, Samsung etc ..
However, it is possible to establish the sequence of bits of any infrared signal, calculating the time in which the signal is high and the time in which the signal is low. This type of coding is called RAW.
We pass codes for Arduino
As with any new library in Arduino, we have to install it, simply copy it in the Libraries folder, which typically is in its documents.
If we were to use the device TSOP1738, the connection is very simple; simply feed the signal with 5 V Arduino, connect it to ground and connect the output pin to pin 11.
TSOP1738 Datasheet
As regards other devices on Ebay, simply connect the output pin to pin always 11 Arduino.
1 Program decode a generic signal
Program name Decode_generic_IR
12
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
| / *
* Modified by Chris Targett
* Now includes blackberries protocols
* Novemeber 2011
* 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
* Http://arcfn.com
*
* Modified by Chris Targett to speed up the process of collecting
* IR (HEX and DEC) codes from a remote (and to put into .h file)
*
* /
#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 == SAMSUNG) {
Serial.print ("Decoded SAMSUNG:");
}
else if (Results-> decode_type == JVC) {
Serial.print ("Decoded JVC");
}
else if (Results-> decode_type == PANASONIC) {
Serial.print ("Decoded Panasonic");
}
Serial.print (Results-> value, HEX);
Serial.print ("(");
Serial.print (Results-> bits, DEC);
Serial.println ("bits)");
Serial.print ("#define Something_DEC");
Serial.println (Results-> value, DEC);
Serial.print ("#define Something_HEX");
Serial.println (Results-> value, HEX);
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)) {
dump (& results);
irrecv.resume (); // Receive the next value
}
}
|
The program here this shows the serial encoding infrared signal that is received by the receiver, connected to pin 11 Arduino. The mechanism is really quite clear, thanks to the comments in the code, taken from the official library.
2nd Programme for Arduino: We light a lamp with any signal Infrared
12
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| / ** This program allows you to turn on a lamp, through
a relay, with a
infrared remote control. This version does not allow you to change
code
at run time
Author James Bellazzi
* /
#include <IRremote.h>
int RECV_PIN = 11;
int RELAY_PIN = 13;
int code = 16738455; // Code dec remote control
IRrecv irrecv (RECV_PIN);
decode_results results;
void setup ()
{
pinMode (RELAY_PIN, OUTPUT);
Serial.begin (9600);
irrecv.enableIRIn (); // Start the receiver
}
int on = 0;
unsigned long last = millis ();
void loop () {
if (irrecv.decode (& results)) {
// If it's been at least since the second quarter last
// IR received, toggle the relay
if (millis () - last> 250 && == results.value code) {
On =! on ;
digitalWrite (RELAY_PIN, on ? HIGH: LOW);
// Dump (& results);
}
last = millis ();
irrecv.resume (); // Receive the next value
}
}
|
This code allows you to turn on a lamp connected to a relay, pressing an infrared remote control. The coding of the remote control that you want to use, can be obtained with the code of the first program and inserted at the beginning of this code. However, the code can not be changed at run time.
3rd Program: We light a lamp with any remote control
12
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| / * This project allows you to use Arduno and an IR remote control, to turn on a load connected to the relay on pin 13.
Also you can change the code on the remote control, through the
pushbutton RESET
AUTHOR: James Bellazzi
VERSION: 1.0
* /
#include <IRremote.h>
int RECV_PIN = 11;
int RELAY_PIN = 13;
int pushbutton = 3;
unsigned long queues;
IRrecv irrecv (RECV_PIN);
decode_results results;
void setup ()
{
pinMode (RELAY_PIN, OUTPUT);
pinMode (pushbutton, INPUT);
irrecv.enableIRIn ();
Serial.begin (9600);
}
int on = 0;
unsigned long last = millis ();
void loop () {
int = buttonState digitalRead (pushbutton);
delay (100);
if (buttonState == HIGH) {
Serial.println ("Settings ...");
if (irrecv.decode (& results) && millis () - last> 250) {
code = results.value;
Serial.println ("New code setting ...");
Serial.println (code);
Serial.println (results.value);
last = millis ();
irrecv.resume ();
}
}
if (irrecv.decode (& results)) {
if (millis () - last> 250 && == results.value code) {
On =! on ;
digitalWrite (RELAY_PIN, on ? HIGH: LOW);
}
last = millis ();
irrecv.resume ();
}
}
|
This program, unlike the previous one, allows you to change the IR code that is used to activate a relay, also at run time, setting it via a push button connected to the Arduino. The operation is very simple and is shown in the video:
4th program: we turn on the TV Samsung home with Arduino
This program allows you to turn on a TV Samsung with our little Arduino. The first step is to use RAW to carve the code of the signal emitted by our remote control, through the program that was previously discussed previously.
Now we have to take the RAW code, delete the first value, convert the signs - with the space and put commas between the various values.
30498,4450,4400,600,1650,600,1600,600,1650,600,500,600,550,550,550,600,500,600,550,550,1600,650,1600,600,1650,600,550,550,550,550,550,600,550,550,550,600,500,600,1600,600,550,600,550,550,550,550,550,600,500,600,550,600,1600,600,550,550,1650,600,1600,600,1650,600,1600,600,1650,600,1600,600,
The code for Arduino that is used to send the signal to the TV is the following:
12
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| #include "IRremote.h"
IRsend irsend;
void setup ()
{
Serial.begin (9600);
}
unsigned int ON [68] = {4450,4400,600,1650,600,1600,600,1650,600,500,600
, 550,550,550,
600,500,600,550,550,1600,650,1600,600,1650,600,550,550,550,550,550,
600,550,550,550,600,500,600,1600,600,550,600,550,550,550,550,550,600,
500,600,550,600,1600,600,550,550,1650,600,1600,600,1650,600,1600,600,
1650,600,1600,600,};
void loop () {
irsend.sendRaw (ON, 68,38);
Serial.println ("I turn on the TV Samsung");
delay (10000);
}
|
The infrared LED is connected to pin 3, with a resistance of at least 100 ohms in series. The resistance value is proportional to the radius of the remote control of Arduino.
Post a Comment