Hardware Reference
In-Depth Information
he PIR sensor has three coloured wires: ground, positive and alarm. he colours and pin
positions may difer, depending on which one you buy, so be sure to check the data sheet of
your PIR. he alarm pin is an open collector, meaning you will need to connect a pull-up resis-
tor on the alarm pin (see Chapter 9, “Test Your Reactions”, for details on open collectors).
In Figure 13-5 you can see the circuit diagram with all the components, and in Figure 13-6
there is the breadboard prototype diagram.
Figure 13-5:
A circuit
diagram for the
door switch and
motion sensor
connected to
two GPIO pins
on the
Raspberry Pi.
Software
he software will print to the screen whenever motion is detected or the door sensor is trig-
gered. You want to print to the screen only once per event, so you will use variables ( motion
and door ) to keep track of when you are in an alarm state and prevent the trigger reoccur-
ring for the same event. If you were logging these events to a database, or taking another
action such as switching on a light or sending an e-mail alert, you would use this method
to prevent multiple actions being created for the same event. he code is provided in
Listing 13-1.
Search WWH ::




Custom Search