Hardware Reference
In-Depth Information
Connect an LED
You will connect the LED to the open-collector outputs. Remember open-collector outputs
cannot supply current; they are essentially a switch that connects the terminal to ground.
You'll create a circuit where the current will low from the 5V terminal, through a resistor (to
limit the current so the LED is not damaged) and through an LED and into the output termi-
nal. When the output terminal is turned on it allows current to low to ground, completing
the circuit and illuminating the LED. Remember LEDs only work if current lows through
them one way, so it matters which lead you connect to positive. For most LEDs the longer leg
indicates the anode , which should be connected to the resistor and then the 5V terminal. A
complete circuit diagram is available on the topic's website ( www.wiley.com/go/
raspberrypiprojects ).
Some switches with built-in LEDs can safely work at 5V so you do not need a resistor.
However, most normal LEDs would be damaged by a voltage of over 2V. If you are using a
normal LED, you need to put about a 330Ω resistor in series with the LED. Chapter 8 has
more information about using resistors with LEDs. Connect the longer leg of the LED and
resistor together and then connect the other leg of the resistor to the 5V terminal. Now is a
good time to check if the LED will work. Briely touch the other lead of the LED, called the
cathode, to GND. You should see the LED glow. If not, check your wiring and make sure that
you have identiied the anode and cathode correctly. (You shouldn't have damaged the LED
if you got the polarity wrong.)
When you know the circuit works, disconnect from the ground and then connect to the tran-
sistor via one of the output terminals - such as output 0. When the transistor is turned on,
it will allow the current to low to ground and complete the circuit, so the LED will illumi-
nate. Turn the output on from the emulator and check that it lights.
Playing with the Reaction Timer
Now that you have connected an LED and switch, rerun the reaction timer program. Again
the LED should light after a random time, and the switch should stop the timer. Now that
you know your wiring and circuit works, you can really start to have fun - try diferent out-
put devices, wire up a buzzer instead of the LED and see if your reactions to sound are
quicker. You could perhaps mount a feather on a motor and test your reaction to touch. You
might ind this reaction to be quicker. his is because the inputs (nerves in the skin) can send
a message to the outputs (muscles) without going through a complicated processing system
(your brain) - the principles of computing apply to lots of other systems too! Experiment
with diferent input switches too - you could attach a switch to diferent parts of your body
and see if they respond as fast as your hand.
Have a go at making your own switch! Instead of a pre-made switch, you could wire up pieces
of aluminium foil as the contacts and detect when they are connected. Maybe you could
Search WWH ::




Custom Search