You will see from my breadboard pictures that I am using my latest Arduino - another BreadboArduino from HobbyTronics Ltd. You just can't have enough of them!! The ATMega 328 chip has been given a useful label on the top, to help identify the pin-outs of the chip. This BreadboArduino uses a mini USB connection from my PC, to a Sparkfun FT232 Breakout (bottom middle), which supplies power and connections for programming on the PC via the Arduino ISP.
At the top left, I have included 2 LEDs close together (and surrounded by heat shrink to insulate the long legs from other connections). The red LED shows "power on" and the green LED is connected via a resistor to Digital Pin 13 - as is usual with proper Arduinos. Pin 13 is used in my sketch, so that the LED will blink when the IR sensor receives a signal.
The IR Sensor is at the top right of the picture and the three legs as we see them in the picture, are Vcc, GND and Vout signal. You can also see my oscilloscope probes connected to the IR Sensor signal out and GND, so that I can have a look at what's coming out.
Remote Controllers
TV and Hi-Fi remote controllers are very common in the home, but do we really know much about them?
I found I had several of them about the house, and borrowed a couple:
On the left is a Haier TV controller and on the right is a Toshiba VCR player controller. If you look at the upper end of these, you see an infra red LED, whose light you can't see with your naked eyes.
However, most digital cameras can "see" these LEDs light up - unless they have been fitted with IR filters.
The IR transmitter LED transmits Near Infra Red (or IR-A) light, carrying hexadecimal (Hex) codes which are pulse-width modulated at a high frequency (38 kHz) (hence the 38 in the model number).
The Vishay TSOP4138 is a smart device because it de-modulates the carrier frequency, so that it's output signal is the Hex code only.
The video below shows each of the controllers above emitting IR light:
The files that can be downloaded as the IRremote library include a test sketch which allows identification of the sensor's Hex output corresponding to each button on each IR controller:
The example sketch is on the top and the Serial Monitor output is below. From this I identified the numbered buttons on each of the two IR controllers. I then modified the IRrecvDemo sketch to detect if any of the number buttons on either of the two IR Controllers have been pressed. When any other button is pressed, even on any other controllers, the output from the Serial Monitor is simply "--------------------------". Otherwise, if any of the numbered buttons on either of the two IR controllers is pressed, its identification is printed, along with the Hex code itself:
Here are a couple of oscilloscope traces of the sensor hexadecimal output, one resulting from the Haier and one from the Toshiba:
My modified version of the sketch is listed below:
1: /*
2: * IRremote: IRreceiveKC - demonstrates receiving IR codes previously identified with IRrecv
3: * An IR detector/demodulator must be connected to the input RECV_PIN.
4: * Version 0.1 July, 2009
5: * Copyright 2009 Ken Shirriff ::: Modified by Sparks N Smoke
6: * http://arcfn.com
7: */
8:
9: #include <IRremote.h>
10:
11: int ledPin = 13;
12:
13: int RECV_PIN = 12;
14: IRrecv irrecv(RECV_PIN);
15: decode_results results;
16: String v;
17:
18: void setup()
19: {
20: Serial.begin(9600);
21: irrecv.enableIRIn(); // Start the receiver
22: pinMode(ledPin, OUTPUT);
23: }
24:
25: void loop() {
26: if (irrecv.decode(&results)) {
27:
28: digitalWrite(ledPin, HIGH);
29: delay(100); // wait
30: digitalWrite(ledPin, LOW);
31: //Serial.println(results.value, HEX);
32: v=String(results.value, HEX);
33: //Serial.println(v);
34: if(v=="22dd807f")
35: {
36: Serial.print("Button 1, Toshiba ");
37: Serial.println(results.value, HEX);
38: }
39: else if(v=="fb2ad5")
40: {
41: Serial.print("Button 1, Haier ");
42: Serial.println(results.value, HEX);
43: }
44: else if(v=="22dd40bf")
45: {
46: Serial.print("Button 2, Toshiba ");
47: Serial.println(results.value, HEX);
48: }
49: else if(v=="fb6897")
50: {
51: Serial.print("Button 2, Haier ");
52: Serial.println(results.value, HEX);
53: }
54: else if(v=="22ddc03f")
55: {
56: Serial.print("Button 3, Toshiba ");
57: Serial.println(results.value, HEX);
58: }
59: else if(v=="fba857")
60: {
61: Serial.print("Button 3, Haier ");
62: Serial.println(results.value, HEX);
63: }
64: else if(v=="22dd20df")
65: {
66: Serial.print("Button 4, Toshiba ");
67: Serial.println(results.value, HEX);
68: } else if(v=="fb0af5")
69: {
70: Serial.print("Button 4, Haier ");
71: Serial.println(results.value, HEX);
72: }
73: else if(v=="22dda05f")
74: {
75: Serial.print("Button 5, Toshiba ");
76: Serial.println(results.value, HEX);
77: }
78: else if(v=="fb48b7")
79: {
80: Serial.print("Button 5, Haier ");
81: Serial.println(results.value, HEX);
82: }
83: else if(v=="22dd609f")
84: {
85: Serial.print("Button 6, Toshiba ");
86: Serial.println(results.value, HEX);
87: }
88: else if(v=="fb8877")
89: {
90: Serial.print("Button 6, Haier ");
91: Serial.println(results.value, HEX);
92: }
93: else if(v=="22dde01f")
94: {
95: Serial.print("Button 7, Toshiba ");
96: Serial.println(results.value, HEX);
97: }
98: else if(v=="fb32cd")
99: {
100: Serial.print("Button 7, Haier ");
101: Serial.println(results.value, HEX);
102: }
103: else if(v=="22dd10ef")
104: {
105: Serial.print("Button 8, Toahiba ");
106: Serial.println(results.value, HEX);
107: }
108: else if(v=="fb708f")
109: {
110: Serial.print("Button 8, Haier ");
111: Serial.println(results.value, HEX);
112: }
113: else if(v=="22dd906f")
114: {
115: Serial.print("Button 9, Toshiba ");
116: Serial.println(results.value, HEX);
117: }
118: else if(v=="fbb04f")
119: {
120: Serial.print("Button 9, Haier ");
121: Serial.println(results.value, HEX);
122: }
123: else if(v=="22dd50af")
124: {
125: Serial.print("Button 0, Toshiba ");
126: Serial.println(results.value, HEX);
127: }
128: else if(v=="fb30cf")
129: {
130: Serial.print("Button 0, Haier ");
131: Serial.println(results.value, HEX);
132: }
133: else
134: {
135: Serial.println("--------------------------");
136: }
137: irrecv.resume(); // Receive the next value
138: }
139: }
This ability to control systems via infra red would be very useful for controlling robots, and other systems which are within line-of-sight (although as you will see with your TV controller, the signal does seem to scatter off other surfaces in the room, without pointing directly at the TV) and at the sort of ranges that you find within household rooms.
For more information on this kind of project, there is an excellent tutorial from Lady Ada at http://learn.adafruit.com/ir-sensor - highly recommended!
No comments:
Post a Comment