This project is adapted from the staggeringly popular Make: Electronics Third Edition, which has been completely re-re-written with most photos and schematics replaced and updated!
During 2021 I started writing a third edition of my book Make: Electronics. One of the pleasures of this task was that I could rethink all the circuits, and with the benefit of hindsight, I saw how to simplify one project in particular: The intrusion alarm.
You’d think an alarm should be easy enough. Just place some sensors on doors and windows, wire them to a beeper, and — job done!
But it’s not so simple. First, the alarm has to notify you that all the doors and windows are closed before you activate it. Then you need a delay (which I call the Exit Delay) so that you can leave the area without causing the alarm to start making a noise. When you come back, you need another delay (which I call the Last Chance Delay) to prevent the alarm from beeping or wailing till you have a last chance to switch it off. The diagram below shows what I mean.
The word delay suggests a component that measures time. That could be a timer, couldn’t it? In fact you can build this circuit entirely with three 555 timers — the old-school chips that have outsold all other chips ever made. Along the way you’ll learn about pullup and pulldown resistors, diodes, and coupling capacitors, which can be useful in many other applications.
IC1, IC2, and IC3 are acronyms for integrated circuits, which are the three 555 timers.
Using a Pico
You can, of course, use a microcontroller instead of 555 timers. My collaborator Fredrik Jansson likes the new Raspberry Pi Pico chip, because it’s so powerful and so affordable, so he wrote some code for it in MicroPython to behave the same way as my circuit, as shown in Figure . His comments in the code show you what the alarm program is doing at each step; you can type it in as you see it here, or download it.
# Raspberry Pico version of Make: Electronics alarm from machine import Pin from time import sleep # LED outputs l1 = Pin(17, Pin.OUT) # Switches are closed GP17 l2 = Pin(16, Pin.OUT) # Time to leave GP16 l3 = Pin(14, Pin.OUT) # Alarm is triggered GP14 l4 = Pin(15, Pin.OUT) # Alarm! GP15 # Inputs with pulldown go = Pin(8, Pin.IN, Pin.PULL_DOWN) # Go button sensors = Pin(20, Pin.IN, Pin.PULL_DOWN) # Sensor switches # show sensor state on LED 1 l1.value(sensors.value()) # function to be called when the sensor pin changes # show sensor state on LED 1 def sensors_change(p): l1.value(sensors.value()) # connect function to the sensor pin change interrupt sensors.irq(trigger=Pin.IRQ_RISING | Pin.IRQ_FALLING, handler=sensors_change) # The alarm logic starts here # Wait for GO button press while go.value() == 0: pass l2.value(1) # time to leave sleep(10) # exit delay l2.value(0) # wait for sensors to open while sensors.value() == 1: pass l3.value(1) # alarm is triggered sleep(10) # last chance delay l3.value(0) l4.value(1) # Alarm! # the alarm stays on until reset/power-off while True: sleep(1)
Fredrik’s breadboarded circuit for the Pico is shown above, using sensor switches that are normally closed, and adding a reset button to boot the Pico. The components look wonderfully simple, but of course you do have to write the program, upload it, test it, track down your syntax errors, and upload it again.
Personally I prefer old-school components, because I think they’re fun — and you will learn about concepts such as diodes, pullup resistors, and coupling capacitors as you go along.