36 KHz modulated infrared light detector

I have started working on a new robot that is mainly based on LEGO MINDSTORMS NXT. This robot is aimed at participating in DTU robocup 2008 but time will tell if it will be finished in time. Anyway in robocup the robot must at least be good at following a black line and preferably it should be able to accomplish other of the tasks at hand as well, and this is just not feasible using the standard LEGO sensors and the very limited number of these it can use at one time. So I thought I'd take advantage of the fact that LEGO sensor ports can access I2C hardware (up to 127 devices on each port!) and make my own I2C slave line follower.

First off I had read somewhere that the picaxe can only do I2C master, so I figured I'd go for using the PCF8574 I/O expander from NXP since I had five of these lying around. After designing a circuit on paper I realised that the picaxe 40x1 which is the only picaxe chip I have can in fact be set to act as an I2C slave (though I have not tested this yet - just read it in the manual), so I dropped the PCF8574 since it would now be possible to do the whole processing of the line detection in the picaxe and just returning the result of the processing to the NXT when it asked for it.

The line sensor will contain 8 SFH5110-36 infrared detectors that can detect an infrared signal modulated at around 36 KHz - when a signal is detected it draws its DETECT-pin low. Also it will contain 7 infrared LEDs that will be modulated at 36 KHz by the picaxe via PWM. The light from the LEDs are supposed to be bounced back from the floor only where there is no black line.

Yesterday I made a test setup for the detector circuit on my breadboard and it seems to work kind of like I want it to. First I thought that the SFHs could only be used for ON/OFF detection but after testing it, I think maybe I can put in a capacitor on the DETECT-pin and maybe a resistor somewhere to make a potential divider and measure the voltage somewhere. I got the idea since the detection LED I put in did not just switch on and off - rather it seemed to go from off to on smoothly which I guess happened because the infrared light just barely reached the SFH so the DETECT-pin was modulated like PWM or something.

You can see a short movie showing detection of my hand here:


As you can see this setup can easily be used for obstacle detection as well (maybe my robot will use that as well).

Picture of the test setup:


- Jimmy

So many questions :slight_smile:

You do not have to answer the below, but your post leaves me with so many questions, so here is my comment, answer if you like, it is only chit-chat, of course you can do what ever robots you want etc :slight_smile:

  • 38 or 36 KHz?
  • Why on earth a modulated signal? You will get a I/O return, would an analouge value not be much more versatile?
  • Is this not the third robot you start up, what happend to the last 2?
  • Why at all use the LEGO-brick, why not just make it all in the Picaxe? (Or another Microcontroller) The brick is heavy, powerconsuming, and your whole setup is much more complex, meaning longer testing time and worse performance than without it. Would it not (for sure) be a more elegant sollution to get a lot out of something simple than getting just a simple line-follower out of such a complex dual-core-multi-language-double-power-pack-setup?
  • You know you can bulid a splendid line-follower with just a picaxe 18, and you know that the best line-followers are focused on light weight? Check this page, specially the video for an optimal line-follower design - No LEGO-brick in there, I bet you :wink: http://www.robotroom.com/Jet.html
  • The video (which i think you have showed me earlier at some point) does not seem to use a modulated signal?

/ Frits

Early morning answers…

  • Ah yes… 36 KHz of course… will change the heading :slight_smile:
  • A modulated signal doesn’t suffer so much from ambient light and it might be possible to do something similar to analogue with the modulated signal using capacitor and resistor (working on that design).
  • The last 2 robots are still in development. This one is just meant for robocup which is just around the corner.
  • Because the lego brick is well tested, well documented, robust and has all I need but the line sensor. So I have to focus only on the electronics for the line sensor and not on motor controller, wheel encoders, etc. Furthermore I can program it using Eclipse and Java, it has more RAM than picaxe, operates faster than picaxe, battery is nicely attached with a plug for charging. The servo motors (that can rotate freely) can easily drive this robot so weight is not a problem. The lego brick also has a user interface with LCD and push buttons. I can’t really see any reason to use a picaxe where the lego brick could be used.
  • Weight has nothing to do with good line following. Weight has something to do with fast line following when you don’t have too much motor power. Besides line following isn’t the only task at hand for robocup so lego is nice and easy to assemble for solving these tasks.
  • I don’t think that Jet uses modulated signal, but that doesn’t mean that using it is bad.

I still have my Picaxe Pete under development (he is just missing some picaxe basic in his brain) and I also have my R/C car which will most likely be controlled by my LPC2106 development board using I2C devices like line sensor, motor controller etc.

- Jimmy


"it might be possible to do something similar to analogue with the modulated signal using capacitor and resistor (working on that design)"

Huh?? Modulated = 1/0 = Digital, no?

Are you thinking of multiple modulated signals and over time getting average of 1/0’s? That will be a bad idea, your robot will be extremely slow, and the resoult poor compared to just getting an analouge signal, I should think!

Sorry for being such a killer to your projects this wonderfull sunday morning, and sorry for allways coming after you for using that LEGO-brick ;D but you are telling me that you are inserting a whole LEGO-brick on your project to get “motor controller and wheel encoder”?


Regarding the detector I’m

Regarding the detector I’m thinking that there is no hard cutoff where there is stable detection on one side and stable non-detection on the other side. There is an interval where the detector switches on and off rapidly (like PWM) because some blinks get detected and others don’t. If you feed this pulsing into a capacitor or maybe an inductor (I haven’t tried those yet - not counting motors) then maybe you can get a voltage (through a potential divider) that will be the mean of the pulses. That’s at least how motors work with PWM so I thought it might be possible. You know that PWM is digital too, right? Still you get more than just ON and OFF with your motors since the motor can’t react as fast as the PWM signal. It integrates the voltages seen over a period of time and acts as if it had seen a voltage with the same value as that integral. Anyway read more about motors and PWM if you want to learn more about it.

Regarding the lego brick I’m saying that by using the lego brick I won’t have to do the electronics for anything other than the line sensor, and this makes it easier and faster to build the robot.

Please stop bugging me and take care of your baby… or it will just start playing with LEGO :wink:

- Jimmy

LOL, sorry, I will try to

LOL, sorry, I will try to stop bugging you. At least here on your own blog!

I just so much want to see a robot of yours if not finished, then at least just driving around or something. It is for your own sake, you know and you know it!

/ Frits

Hello fritsl, now I know

Hello fritsl, now I know what I meant by converting the digital signal to analog… I was thinking about putting in a low pass filter that would be set to some usable frequency so when detection switches on and off rapidly the signal will be smoothed out to an average voltage or something like that. That filter can be made by just one capacitor and one resistor (known as an RC-circuit). When the detection switches on and off rapidly I would think that it is because it is not being reflected quite so well so only some of the rays make it back to the detector and that could be because an object is far away (or because the detector is on the edge of a black line when doing line following).

Tomorrow is my weekly day off from work so I will try to get the damn thing to work properly. Right now it bothers me that I can get the circuit to light up an LED but the microcontroller seems to have problems with it since the output voltage doesn’t go quite as low as expected (I think that maybe has something to do with the output being connected to the base of a PNP-transistor that lights up the LED.

Hopefully more info tomorrow sometime…

- Jimmy

:)/ Frits


/ Frits

Of current and PWM

Hi Jimmy,

I’ve been working on a similar circuit, using modulated IR receiver as sensor. Nailed the PWM part, so the LED is pulsating (i think), though receiver hasn’t really been co-operative. So I’ve got some questions about how you hook-up yours.

You connect a PWM signal straight to the negative end of your IR LED. Wouldn’t that be draining all that current from supply rail into your processor when the PWM signal is logic low? Wouldn’t that be harmful to the processor?

The way i did it is to let the PWM signal to drive the base of an NPN transistor through a resistor, in an attempt to isolate the LED current from ever reaching controller. I suspect this isn’t working as smooth as i had hoped, as voltage across the LED oscillate between 1V to 1.3V, instead of the expected 0V (off) to 1.3V (on).

I’m just being cautious coz the Cyclone II processor i’m using tend to fry up really quickly. Am i being too cautious?

Appreciate if you could drop some hint/pointers. Thanx in advanced.


Not so much current

Hi Aqmal,

Sorry for the late response, I’ve been otherwise busy.

Looking at the picture of my setup it seems I have a 2.2k resistor in front of the IR LED, so the chip doesn’t sink that much current. I think standard chip pins can sink/source around 20mA. Of course it’s a good idea to be cautious if your equipment is expensive, but most of the stuff I use is fairly cheap, but still I haven’t fried anything yet.

- jip