PICs, I2C and sensors

Hello.

I am working on a fun little half-built device that is going to follow a black trace line the floor, but due to my less perfect knowledge of electronics this is starting to look like a huge task.. :/

Programming is no problem, using the PIC1F628 I've made it go round the floor like a happy puppy, but without any sense of direction. But the difficult part is combining the three little photointerrupters, another PIC1F628 and the I2C-bus.

The photointerrupters are of simple analog type Kodenshi SG-2BC, and I want to connect them to the PIC. But I am clueless what I need to do to make the PIC utilize them? I suppose I can not directly solder them to the PIC?

The whole point is to make the second PIC act as a slave on the I2C-bus, take care of the input from the photointerrupts and deliver to the master PIC upon request.

Thanks for any help :)

Reply to
fredric palsson
Loading thread data ...

Hi !

The photointerrupters are simple devices with two basic components: a) a photodiode that emits an IR light and b) a phototransistor that is sensitive to IR light.

Now, if you know how a transistor works, then a phototransistor works precisely the same way, only that the IR light's luminancy acts as the "base current", i.e. more light means more current, thus resulting greater current via collector-emitter pins. In order to interface this device with any microcontroller, you need to fathom some sort of a A/D converter. This would consist of two parts. First, you'd have the photointerrupter, and it's photodiode. The diode is connected to a series resistor (small) and then to a 5V output on the PIC. The other end of the diode is grounded. Now, when logic 1 is written to the port, 5V's will cause a current through the diode, thus causing it to emit IR light. To calculate the series resistor, use the data sheet's "forward voltage" and "forward current" diagrams, making sure the current passing through the diode doesn't exceed maximum ratings (i.e. break the diode) Second part of the design has the phototransistor. The collector pin is connected to a series resistor, and this resistor to a voltage source (not the PIC, but some steady voltage source, such as 5V). When the transistor detects IR light, it starts to allow current pass-through from collector to emitter. The emitter is connected directly to an A/D converter, and a parallel resistor is connected to the same pin. The converter input must be as high-impedance as possible, so majority of the current will pass through the parallel resistor to ground. Current passing through the parallel resistor causes a voltage drop over the resistor. Thus, the A/D input pin will have a voltage that is related to the amount of current passing through the transistor (and indirectly related to the amount of IR light received). Then you create an A/D conversion and depict a way to relate the amount of voltage (distance of object) with the control logic.

If the robot is supposed to follow a black trace line, then you must place the photointerrupters so that two of them will target both sides of the line, and one will target the line itself. Whenever the two side interrupters report max luminosity (they point to white floor) and the center one reports low luminosity (the black line doesn't reflect IR that good), then your robot is going to correct direction. If the center one reports high luminosity, then you check which one of the side ones reports low (i.e. where is the trace turning to) and adjust robot direction appropriately.

This might or might not work, and it might or might not be complete. But it's a start, nevertheless. You should first create a schematic that uses the photointerrupter to measure a distance of some object, and interfacing this with the A/D converter design. I don't know how PIC's A/D converter works, so I can't give you a precise, working solution.

-Antti Keskinen

"fredric palsson" wrote in message news:LG5Od.129887$ snipped-for-privacy@newsc.telia.net...

Reply to
Antti Keskinen

Hi Fred, Hi Antti,

Like to add just two comments.

i) The current through the IR-LED should not be more than

10 mA if you want to control the led by a PIC.

ii) Have in mind, that an IR phototransistor (the device built into your "photo interruptors") uses infrared light, not visible light. Therefore, a black line may not give you enough infrared contrast to have a good bright/dark distinction. Also, some floor coatings etc. are mirrors for infrared light. To be sure I recommend using a photocoupler with a red led. It has also the advantage that you can actually see it working.

Happy tinkering, Wolfgang

--
From-address is Spam trap
Use: wolfgang (dot) mahringer (at) sbg (dot) at
Reply to
Wolfgang Mahringer

A minute with Google brings up this sensor circuit of another robot project.

formatting link

I wouldn't bother with doing it in analog. If a sensor sees the line then change direction! And why use I2C when you already have serial I/O built in?

Peter

Reply to
Peter

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.