Sunday, February 15, 2009

IR Receiver Circuit

The IR receiver from Mouser Electronics arrived this week. It came amazingly quickly. I ordered it late Saturday night. It shipped on Monday and was delivered on Tuesday. The chip we are using is the Vishay TSOP4840, which is only $1.10 quantity one at Mouser. Alan built the test circuit to connect the IR receiver to the Arduino microcontroller board using a breadboard:

Here's a closeup of the IR receiver and the remote control.

Here is the schematic for the test circuit:

The Sony remote control modulates the IR carrier wave at 40 kHz. (Other manufacturers use other frequencies. 38 kHz is common.) This carrier wave is turned on and off to create a stream of pulses that carry the data. The SIRC protocol uses pulse width modulation. A command begins with a start bit that is 2400 µs wide. It is followed by twelve data bits, separated by 600 µs gaps. A logical one bit is represented by a 1200 µs pulse and a logical zero is represented by a 600 µs pulse. The TSOP4840 demodulates the IR carrier wave and presents a logical signal on the output pin that is low when the IR carrier is present and high when it is absent (i.e., active low). The output is connected to a digital I/O pin on the Arduino. D2 is chosen because it is one of two pins that can generate hardware interrupts when the value changes. Thus it is only necessary for the software to time the intervals between the interrupts to decode the signal. I set to work on the software and we got the whole thing working without too much trouble.

It’s amazing how sensitive the receiver is. You can be across the room and point the remote at the opposite wall and it will still pick up the reflected signal. This will work great for the robot. You will have to be standing behind it, but the direction and distance are not critical.

The nice thing about using a standard IR remote control is how many different buttons it has. Once you’ve got the software in place to decode the commands you can define as many commands for the robot as you would like. We expect to have at least seven: stand up, lie down, go forward, go back, turn left, turn right and stop. One interesting issue is that the remote control repeats the command every 45 ms for as long as you hold down the button. It turns out to be essentially impossible to tap a button quickly enough to send only one command. Two or three is more typical. The robot control software will have to determine when a command was doubled or tripled through an auto-repeat and compensate.

Next up is to go back and finish the physics model and the simulation. I set it aside last week when I got stuck, but I’ve asked my brother-in-law, whose degree is in physics, to help me. So it’s back to school for me this week!


Rob said...

It sounds like the command processor will need to detect a "button down" on the remote and then start looking for a "button up" when the commands stop coming. The whole sequence would be one command.

The hold-down-to-repeat command would use a repeat-delay setting like the one on a keyboard.

Bill Hensley said...

That's a good suggestion, but we also don't want the command response to be "laggy". Alan and I were thinking we would respond to the first command immediately. If the next command is a duplicate and it arrives within 90 ms we would ignore it. I say 90 ms because we noticed the receiver seems to miss about one in ten of the repeats. I'm not sure where the breakdown is yet. I may be missing interrupts or it may be slight timing errors.

Anonymous said...

Can anyone recommend the top IT automation system for a small IT service company like mine? Does anyone use or How do they compare to these guys I found recently: N-able N-central service desk
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!

Christiaan said...


This is very awesome,

Do you have a schematic to connect a arduino to a rc receiver to send a signal to a servo.

Bill Hensley said...

Thanks, Christiaan. I haven't interfaced an rc receiver myself, but the Arduino web site has a forum with lots of great information and many helpful users who can answer your questions:

There is also a wiki where Arduino users have posted many of their projects: