Now here we have an exercise using a somewhat unusual device: the slotted opto switch. This consists of an infrared LED paired with an infrared sensor, the twain mounted on either side of a slotted piece of plastic. When the beam communicating between the two is cut off, the "switch" is tripped. The component looks like this:
By the way, I found it surplus at All Electronics a number of years ago.
What we'll do in this experiment is connect it to the PIC, along with an LCD, and count the interruptions. The last word of that sentence is a good one, for in fact, interrupts are used within the PIC to cause an internal count to increment whenever something obscures the invisible beam within the slot. But first, here's the circuit:
Now such a device could have all sorts of applications in everyday life. Several that come to mind would be a doodad for indicating when the flag on a mailbox is raised, or an indicator that a jewelery box has been opened, or that the cat's entry flap has flipped. What makes this particularly attractive is that there are no moving parts; it ought to be far more rugged and long-lasting than a microswitch, say.
In the demonstration, below, I'll first show how it can be used to simply count the breaks. But more impressive is how the circuit is pressed into service as a tachometer to measure the RPM of an electric drill. What we'll do is count how many times the rotation of a cardboard disc with a gap breaks the magic beam in 5 seconds, then multiply by 12 to get a direct RMP reading. Be sure to study the source code to see how interrupts are usefully employed. And here's a picture of the test disc I used with the drill. The cardboard disc is secured to a machine bolt, which is then held within the chuck of the drill.
Enough yammering; let's see how it performs.
Got any other ideas for this cool part? And I've just got to ask, since almost no one has left a comment to date: are we having fun yet?
Click to get the source code.
Click to get the schematic PDF.
Next Project: Humidity Sensor
hello, is the code in ccs format?
ReplyDelete