Tuesday, January 21, 2014

Reading IR Remote using TSOP1838 and Arduino Compatible Pro Mini

After getting the Arduino compatible Pro Mini all soldered up and programmed using the CP2102 serial adaptor I thought it would be see if it works with the TSOP1838 Infra Red Receiver.  I bought 2 from eBay as I want to rig up a couple of Arduinos to send and receive 'messages' from each other.

I started by testing with my Arduino Uno with Ethernet Shield attached. It was the nearest to hand so I thought I might as well see if the TSOP1838 works with it.
TSOP1838 on small board with pins for use with breadboard

After finding a blog post that explains the Pins are transposed.  From top to bottom in the picture above it is
OUT - connected ot digital pin on the Arduino

Compared to the actual pin outs for the PSOP1838 OUT and VCC are swapped.

Then as I expected I'm late to the party I checked if there was a handy library already in place to take if the decoding and I found the fantastic Ken Shirriff Library

Wired it all up correctly and used the library provided.
Uploaded the IRrecvDemo sketch provided with the library and when I pressed a button a remote control the LED on the IR board flashed so date was being received but nothing was appearing on the Serial Monitor.
I tried switching pins.
I added an extra Serial.prinln to output directly the logic on Pin 11 (default in the Example)
I looked at the code and noted it uses Interrupts

Then  I remembered the Ethernet Shield uses Interrupts. Maybe the Ethernet Shield is was stopping the IR Receiver from working.  So, off came the Ethernet Shield. Rewired the circuit. All 3 wires...and it worked perfectly and reliably.

Then it was onto seeing it it would work with the Pro Mini from eBay.

Wired OUTto Pin4. Note VCC middle and GND on the right above.
Wired it all up as per the programming blog post. Added the IR Receiver and uploaded the same sketch after remembering to change the board from Arduino Uno to Arduino Duemilanove w/ ATmega328.
This time it worked first time. No reconfiguring. No modification of the code.

It means for £1.18 (TSOP1838) and £2.15 (Pro Mini) a total of £3.33 I can read remote Infra Red Remote controls and with the simple addition of an IR LED and a resistor I can also send IR codes. I have IR LEDs somewhere in my box of wires, so a little hunt will be needed to find them. It will be fun to see if I can send codes to my TV.

NOTE: The Ken Shirriff Library includes codes to emulate various remote controls, so the library can handle send and receive.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.