As I’ve already discussed here and here, opto detectors are one way to sense position. Unlike a switch, there’s no moving parts, so reliability is high. However, the compromise is a more complicated setup.
In a previous article, I showed a schematic that sent a signal to the Arduino when the light beam was unbroken between diode and sensor, and turned off when it was broken. One reader commented that the usual way was the reverse, and included a link to a schematic. The result? Two resistors instead of three, and a simple wiring job to add photo detection to the Arduino.
The devices I’m using are the HY306-02 photoelectric sensors, which I got on eBay for under 75 cents each (in packs of 10, of course), but any optical (photoelectric) sensors on eBay should work. The procedure is simple: an infrared diode shines into a detector, and both are held in place by a plastic casing (which also provides the gap between them, and the thin slit to let light pass).
Using this new circuit, the device is pretty simple to get going. One caveat: although the layout looks nice and neat here, in fact the device has reversed leads from the schematic (I reversed the detector leads on the diagram so the schematic wouldn’t look so messy with crossover leads). This means you’ll need to wire one resistor crossing over the other. In my case, I first filled the void with hot glue from a glue gun to keep the bare leads in place (apart). I then twisted on the two resistors, using a shrink heat tube to physically space the wires from each other. Finally, I soldered it all up.
The result is a nice tight bundle ready to go into the Braille device. Three wires come out of it: ground, power, and the Arduino detection wire (which can go to any digital pin). The signal is reversed (the Arduino detects a HIGH on the pin when the light beam is interrupted), but that’s a small price to pay for a circuit that is compact and easy to put together.
While a switch is much simpler to wire, this opto circuit has one benefit (besides no wear of course) – it can be used easily for left and right detection of end stops. In my current design, it sits below the motor, perpendicular to travel. At each end of travel, I have a small flap of material to block the light – the result is it can detect left and right end without a second switch or sensor.
Although a bit tricky to use, optos like this are very handy for devices that need high reliability. For future use, I may consider just soldering four wires to it, and then bringing them out and wiring the resistors where there’s more room – however, for now it works, and that’s the main thing!