Other types of digital sensors
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:
An infrared light emitter: This is a simple infrared LED in a housing that directs its light emission in a precise direction
A phototransistor: This is a special kind of transistor whose base is activated by the reception of light, infrared light in this case, and also in a special case that ensures that the phototransistor gets excited only with light coming from a concrete direction—that of the...