I bought a robot car chassis similar to this:
https://goo.gl/images/u6GLHc
The set included nuts and bolts and this and that. But nothing to accompany the encoding plates seen in the image. Has anyone of you come up with any clever ideas of how to use them? I thought of glueing one bright led and one LDR onto each motor and have them face each other with the rotating plate in the middle.
Then perhaps simple interrupt routines triggered by the LDRs, with counters just counting pulses, no directions (which would be almost impossible with these plates).
A future project of mine will include a pen, placed exactly in the middle of the two wheels. For it to draw exactly, I need these encoding plates.
I can't tell from your image whether the black marks on the encoder discs are slots that light can shine through or just black marks.
If they are slots then you need to get a slotted optical switch. It will contain an LED and photo-transistor in a U-shaped housing that can straddle the disk. The light will then be able to shine through, or not as the disc rotates. The switches come in different sizes so choose one that will suit.
If they are just black marks you should be able to detect them with a QRE1113 reflective optical sensor. Sparkfun makes a board with the sensor attached but it is also possible to buy them as parts if the board is too big. In spite of what it says use the analog version of the board (and its schematic if making your device) but use it with Arduino digital inputs.
By the way I have used that Sparkfun schematic with a few different optical switches that I recovered from printers. They don't seem to be fussy devices.
In either case you need to connect the detector to the Arduino external interrupts and use attachInterrupt() to detect the pulses.
...R
Now that you mentioned it, I do have two or three of those led things I got from some printers. I bet I don't have two of a kind. Or anyone of the right size at all.
They are slots. And I think I can manage attaching a led and an ldr at each wheel. The concept of interrupts is not quite familiar to me, but I guess this is no space rocket either.
Nick Gammon has a very good tutorial on interrupts.
...R
Great tutorial! Thanks for the link. If I have two wheels, I'd rather register one interrupt for each wheel rather than combining them somehow and then including logic to tell which wheel triggered the interrupt.
Johan_Ha:
Great tutorial! Thanks for the link. If I have two wheels, I'd rather register one interrupt for each wheel
That's what I assumed you would do.
...R