Let's Make Robots!

IR Detector (How do I hook it up)



I wanted to get an IR detector that would be able to read commands from a TV remote (think VERY cheap remote control robots). How do I wire this thing up? I read about infrain commands and I understand how it works, but does the IR detector get hooked up to ground and the picaxe pin infrain/in? I am using it on an 8m chip but I have a 40m at my disposal as well as a 28x1.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
I broke down and ordered some off the picaxe site. It is my second order form them in the last week ;) I will try to get it working as I want to know why it isn't working. I just can't walk away without fixing something or proving why it won't work.

I think the infrain command of the picaxe is supposed to work with detectors like the ones TheCowGod describes in the end of his post. There is one of those 38 KHz ones at


If you want to use the emitter / detector pair with infrain, I guess you would have to build a bandpass filter that would filter out anything but 38 KHz'ish (you can do that with a couple of capacitors and a couple of resistors) and then maybe use a voltage comparator and an inverter for the final detection setup. I would recommend getting the 3-pin 38 KHz detector though. They're easy to work with and plug straight into the picaxe infrain.

I don't think that interfering fluorescent light should be a serious problem, unless it actually produces valid IR commands.

Oh and btw the 3-pin detector has VCC, GND and DETECT pins. You would want to plug the DETECT into your picaxe infrain pin.

Uh - how ever fond I am of picaxe, I think there is one big problem here; infain halts all program termination untill something is recieved! (I think) So you'd need an extra picaxe just to deal with the IR - and it would take 2 pins from the "main picaxe" to deal with the communication as I see it:

IR-axe: Waiting to recieve, waiting.. bingo, something recieved. Now keep sending this to pin 1 on Main-axe, serial, until pin 2on main axe indicates "I have recieved from you, thanks, I will use it, get back to waiting"

Pretty stupid & complicated setup to have "multitasking".

As  note, the picaxe has the same problem with SERIN - however, there you can use the HSERIN that has a timeout. I do not think there is any timeout-functions on the INFRAIN in the current versions of the Picaxes, sadly! 

For remote control I don't really think it's a problem that the infrain command is blocking. When you receive a command you would normally set some state for the motors - for example set it to turn or to go forward, and then you would wait for another command. Remote control doesn't normally invoke behaviour that requires continous processing.

I am planning on making it so when you hold down an up arrow on the remote it goes forward. When you let go it stops. Same for right, left and backward. Maybe another button that does something else. As long as it does nothing when a button isn't pushed I'm fine. This fits the contraint of infrain. It doesn't need to think for itself, only do what it is told to do when I tell it. If I wanted a sensor to avoid letting me mash it into the wall we would have problems.

I'm assumign the code will be



select infra:

case 1:

blah blah blah

case 2:

blah blah


end select

goto main:


I think you'd be easier off if it didn't have to stop when you let go of the button. How do you detect when the button is not pressed when the infrain doesn't time out? Maybe use a timer to generate an interrupt and then check some state variable that says if you detected button down previously or something like that - just thinking out loud :-).

Would be much easier to do if the robot was set to go forward when pressing one button and was set to stop when pressing another and so on - also that wouldn't wear so much on your thumb ;-).

I'm looking forward to seeing this guy in action!

That is done quite easily, no prob if it is not going to think. The SONY protocol for IR is used with INFRAIN, and I think you have some 127 different commenads. I made something similar, remoted a bot with a TV-style remote control. THe Picaxe shop has one "all round" that is quite handy, easyly configured and stuff. (cheap, and I think it can also be included in a.. KIT!)

- ANd btw; My robot never worked well, because I did not know of the motor drivers and stuff, so it was really slow adnd crap, driving on the pins from the chip directly :D (But that is another story - before I got the 28 KIT)


Oh.. my reason for writing; TheCowGod's bullybot-project would not have a good time with INFRAIN - that was my point initially! 

Huh, wow. I never saw that at my Radio Shack, though the website says my store has it in stock. I'll have to look for that. And yeah, if you're actually sending messages, fluorescent light shouldn't be a problem -- in my case, I'm just looking for the existence of a constant 38 kHz signal. For other uses it probably wouldn't be much of an issue.

BTW, jklug, I've read that adding a .1 uF capacitor across the Vcc and Gnd pins on these 38 kHz detectors helps to eliminate false signals.


I should have time to play with them more tonight. I was hoping to be able to use a TV remote to control a robot. I'm also trying to hack a bluetooth dongle for use on a robot. My goal is to create a couple cheap ways (under $5) to get wireless control for a robot. I know I could rip apart a remote control car and use the radio controller, but bluetooth would blow that out of the water. I would love to control a robot from my PC and have it send back live images from a webcam.

I was just playing with these, but I didn't ever actually figure out how to get the detector to work. My first assumption is that it works like a CdS cell -- it varies its resistance with varying IR light. In that case, you can read it just like a CdS cell or a potentiometer (i.e., wiring it up with a resistor as a voltage divider, as described on this page (scroll down to "CdS sensors")).

But the fact that it's called a phototransistor (and the information on the back of the package) makes me think that maybe that's not how it works. I think that basically, you can imagine that the long lead is the collector, the short lead is the emitter, and infrared light functions as the base pin, controlling how much current can flow between the other two pins. If that's true, then IR light allows current to flow from the collector from the emitter. But I'm not sure how you would measure whether current is allowed to flow through it. maybe wiring the collector to +5v, the emitter through a resistor to ground, and connect an analog input to the emitter, before the resistor? I'm pretty much guessing here. Sorry I can't be more useful, just figured I'd pass along the tiny bit of information I've got on the subject :)

In the end, I gave up on trying to get it to work, since there is IR light in sunlight, incandescent light, etc, so there'd be too many sources of interference for what I wanted to do. I went with the Panasonic PNA4612 sensors, which cost about $1 and detect IR light modulated at 38 kHz, like remote controls do. It makes your emitter circuit more complicated of course, but it makes it easy for your detector to filter out all the other sources of IR light in the room and only detect the modulated one. The only downside to that is that apparently some fluorescent lights output IR light at the same wavelength and flashing at the same 38 kHz rate, so  those would still confuse your detector. But I'd rather just have to deal with one source of interference rather than having it come from everywhere.