Now we’re going to try an interesting experiment using a light sensor2, like the one pictured in Figure 5-5.
As its name suggests, the light-dependent resistor (LDR) is some sort of resistor that depends on light. In darkness, the resistance of an LDR is quite high, but when you shine some light at it, the resistance quickly drops and it becomes a reasonably good conductor of electricity. It is thus a kind of light-activated switch.
Build the circuit shown in Figure 4-5 (see “Using a Pushbutton to Control the LED”), and then upload the code from Example 4-2 to your Arduino. Press the pushbutton to make sure it works.
Now carefully remove only the pushbutton, and insert the LDR into the circuit exactly where the pushbutton was. The LED should come on. Cover the LDR with your hands, and the LED turns off.
You’ve just built your first real sensor-driven LED. This is important because for the first time, you are using an electronic component that is not a simple mechanical device: it’s a real, rich sensor. In fact, this is only a small example of what the LDR can be used for.
Leave a Reply