Burglar/Intruder Alarm Using Wizfi-360 EVB Pico
The burglar alarm system uses a motion sensor (PIR Sensor) to detect intruders.
The system will flash the light and beep.
Burglar Alarm Using WizFi 360 EVB Pico
Microcontrollers are often used in commercial security products such as burglar alarms. This one uses a PIR (passive infrared) sensor – as used by many commercial alarm systems – to detect the presence of an intruder. It’s ideal for catching anyone sneaking into your room or snooping around your desk, or for protecting your stash of cookies. Using Micro Python, you can program your alarm to react with an audible alert and flashing light.
- WizFi360 EVB Pico
- 330 ohm Resistor
- Jumper Wires
- IR Sensor
Connections and Working -
Connect one of the breadboard’s ground rails to another GND pin on Pico. For a flashing light, insert an LED into the breadboard, its legs either side of the central divide. The shorter leg (cathode) should then be connected to the same ground rail. The longer leg (anode) of the LED needs to be connected to the GP15 pin via a resistor to limit the amount of electric current passing through it, which might otherwise damage the LED or the Pico.
On the breadboard, insert the Pico’s male pin headers into the holes at one end. Push it down firmly to ensure good connections – it should fit snugly. Then use female-to-male jumper wires to connect the PIR sensor to it: the VCC pin should be wired to Pico’s 5V VBUS, digital OUT to GP28, and GND to a GND pin (e.g, pin 3), as shown in the wiring diagram below.
Here, import the machine and utime libraries at the top. Next, set up objects for the PIR, LED, and buzzer – connected to GP28, GP15, and GP14 pins respectively.Note that the PIR is set as an input with machine.Pin.IN, with a machine.Pin.PULL-DOWN parameter to set its Pico pin’s resistor to pull-down mode; this means it will read as zero until an electric current is sent to it from the PIR being triggered.
At the bottom of the code, an IRQ (interrupt request) is set up to trigger the pir_handler function as soon as a signal is detected on the input pin (GP28) from the PIR sensor.In the function itself, to avoid repeated triggering within a short time, add a 100ms delay before checking the pin value again and, if it is non-zero, triggering the alarm. It then toggles the LED and buzzer on and off, to flash the light and make a beeping noise.Save the program to your Pico with a relevant name, such as alarm.py. Run the program and, when you wave your hand over the PIR sensor, the buzzer should beep and the LED flash rapidly.
If the alarm is going off too easily, or not at all, you may need to adjust the sensitivity of the PIR sensor. The HC-SR501 has two plastic screws – usually labelled Sx and Tx – attached to two tiny potentiometers to adjust its settings.Using a small screwdriver, you can turn the Sx screw counter-clockwise to increase its sensitivity (or vice versa). Turning the Tx screw alters the length of time the triggered signal is sent after intruder detection – we found it best to turn it fully counter-clockwise, for the shortest delay of 1 second.
pir = machine.Pin(28, machine.Pin.IN, machine.Pin.PULL_DOWN)
led = machine.Pin(15, machine.Pin.OUT)
buzzer = machine.Pin(14, machine.Pin.OUT)
print("Motion detected. Intruder alert!")
for i in range(50):
Make your own mobile intruder -
Once your intruder alarm is working to your satisfaction, you may well want to move it away from your computer. By saving the program as main.py, you can then disconnect it from the computer and connect a standard mobile power bank to its micro-USB port.The Pico will then automatically run the main.py program as soon as it’s powered up. You now have a mobile intruder alarm to place anywhere you want.