Switches are perhaps the most used devices as digital input sensors but obviously not the only ones. Any device that can open or close a circuit branch can be easily configured and connected to Arduino to act like a digital input sensor, from a reed relay (http://en.wikipedia.org/wiki/Reed_relay) to a PIR motion detector (http://en.wikipedia.org/wiki/Passive_infrared_sensor).
One of those devices that are very cheap and easy to acquire are optocouplers or, as they are sometimes referred to, optical switches.
An optocoupler is a very simple device that has two parts:
In the following couple of images, you can see the schematic of the internal structure of a typical optocoupler and a real picture of the one I used for my own assembly of the next project:
If you take a closer look at the picture, you may even notice the indications on the plastic housing of the emitter part with its diode sign to reference the anode and cathode and the collector and emitter markings on the phototransistor part.
If we connect the phototransistor part to our Arduino board, we could easily detect whether it is being excited or not, thus indicating whether there is something placed just in the middle of the plastic housing or not.
This was the same principle that used the first mechanical computer mice to detect and count the X and Y movement, and for that, they used a very recognizable small slotted wheel that allowed for its internal microcontroller to account for every step the mouse took in every axis.
If you are too young, perhaps you have never seen one of this kind of mice, but you could take a look at the Wikipedia entry for mouse under the Mechanical mice section at http://en.wikipedia.org/wiki/Mouse_(computing).
In the next example, we will use an optocoupler as a light barrier that when interrupted, triggers a digital input.
3.140.249.104