Raspberry Pi Pico Panic Alarm

We are going to setup a simple Raspberry Pi Pico based wired Panic Alarm in this tutorial. It is very practical for elderly individuals.

Key Things Needed

  • Raspberry Pi Pico
  • Red LED (5mm or 10mm)
  • Green LED (5mm or 10mm)
  • Momentary Pushbutton Switch/Foot Pedal Switch

Schematic Drawing

You have to make the hardware setup as per the schematic drawing below. It is easy and can be made by any novice. This project can be mounted on a small prototype enclosure after successful testing along with a battery pack/connector for an external power source.

Circuit Description

As depicted in the above schematic, GP11 of Pico is wired to the “NORMAL” LED (green) while the “PANIC” LED (red) is driven by GP10. The 220Ω resistors are current limiting resistors for the LEDs. And, the “PANIC” button (normally-open) is wired between +3.3V rail and GP15 of the Pico board. The GP10 can be extended to control an external audio/visual alert device.

Power Source Picks

The easiest way to power Pico is to plug in the micro-USB, which will power VSYS (hence the entire system) from the 5V USB VBUS voltage via the Schottky diode (D1). However, if the USB port is not going to be used, it is safe to power Pico by connecting VSYS to your preferred power source (in the range 1.8V to 5.5V). Moreover, if you want to power Pico from another power source like a single Lithium-Ion cell or 3xAA series cells or any other fixed power supply in the 2.3V to 5.5V range (V), then the safest way is to feed it through a Schottky diode (D) as shown below.

Pico can also be used with a battery charger. This is a slightly more complex use case, but it is still straightforward. Figure 17 (Page 21) in the Raspberry Pi Pico datasheet (https://datasheets.raspberrypi.org/pico/pico-datasheet.pdf) shows a practical example of using a Power Path type charger, where the charger seamlessly manages swapping between powering from battery or powering from the input source and charging the battery, as needed.

At this point, take note that when using Lithium-Ion cells they must have adequate protection against over-discharge, overcharge, charging outside allowed temperature range, and overcurrent. Bare, unprotected Lithium-Ion cells are dangerous and can catch fire or explode if over-discharged, over-charged or charged/discharged outside their allowed temperature and/or current range.

MicroPython Script

Now to the code part! Actually, this is a simple script that can definitely be amended upon, but it will serve to demonstrate the basic panic alarm concept very well.

# RED LED – Pico GPIO 10

# GREEN LED – Pico GPIO 11

# PANIC BUTTON – Pico GPIO 15

# TKHareendran

# RPi Pico Panic Alarm v1.0

import machine

import time

led_panic_red = machine.Pin(10, machine.Pin.OUT)

led_normal_green = machine.Pin(11, machine.Pin.OUT)

led_panic_red.value(0)

led_normal_green.value(0)

button_panic_red = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN)

def int_handler(pin):

button_panic_red.irq(handler=None)

print(“Interrupt Detected!”)

led_panic_red.value(1)

led_normal_green.value(0)

utime.sleep(6)

led_panic_red.value(0)

button_panic_red.irq(handler=int_handler)

button_panic_red.irq(trigger=machine.Pin.IRQ_RISING, handler=int_handler)

while True:

led_normal_green.toggle()

utime.sleep(2)

In this MicroPython script, we will be blinking the NORMAL LED using a toggle to change its state. Under normal operation, the green LED state will toggle every three seconds.

However, we can interrupt the blinking by pressing the PANIC button. This will cause an interrupt, which will turn off the NORMAL LED and then turn on the PANIC LED. The red LED will stay on for six seconds, after which control of the program is returned so we can go along with the green LED blinking.

Here we defined a function, which is our interrupt handler called “int_handler“. An Interrupt is simply an event that “interrupts” the normal flow of a program. In this case we are dealing with external hardware interrupts, meaning that a signal or change of state has occurred that needs to be addressed before the program can continue. So, every time that interrupt input condition occurs the Pico will stop whatever it is doing and will execute the interrupt handler (it will then resume where it left out).

One key thing to notice at this time is that the interrupt handler specifies “IRQ_RISING” which means that it will trigger an interrupt if the input rises from LOW (0V/GND) to HIGH (3.3V).

Bells and Whistles!

You can think about linking a regular piezo buzzer with the existing warning signal output (GP10 & GND). You can use the common active piezo sounder to raise a relatively loud aural alert, but it’s impractical to rely on its sound in real-life. So, the quickest option to solve that problem would be to simply replace the proposed piezo buzzer with a sufficiently loud hooter. But in order to do that, you would require more electronics.

There are several varieties of suitable driver circuits and modules. The one I picked was a LR7843 MOSFET module which has a galvanic-isolation feature provided by an onboard optocoupler PC817.

As you can see, the module is centered on a 30V N-Channel MOSFET with a low resistance package to provide extremely low RDS(ON). Here is the datasheet of that IRLR7843 MOSFET https://www.infineon.com/dgdl/irlr7843pbf.pdf?fileId=5546d462533600a40153566de53526d8

The LR7843 MOSFET module requires 3 connections. A logic-high signal (3.3V-5V) to turn the MOSFET on/off, a DC power supply (6-28V) to power the load being controlled, and finally the load itself. Appropriate screw terminal connectors and/or pin headers can be soldered to the module, but those connections can also be made by direct wiring if desired.

Note that the module supports about 15A of continuous current with a load voltage of 12V. If driven with PWM, the maximum peak current can be greater up to 30A or more. However, the module does not have a fly-back diode on the board. So, when using the module with inductive loads, an external fly-back diode must be employed to avoid possible impairments. Moreover, you should keep the MOSFET under about 80°C to keep it happy!

Here you can see the circuit diagram of the LR7843 MOSFET module

https://protosupplies.com/wp-content/uploads/2020/06/LR7843-MOSFET-Control-Module-Schematic.jpg

Enclosure Build

It’s one thing to prototype a circuit on breadboard, and a completely different thing to make it suitable for everyday use. This project definitely needs a little enclosure to make it more rugged and durable, and starting with a store bought enclosure can save a lot of time (there is no ignominy in using off the shelf).

You can also build your own project enclosure(s) using any materials and tools you like, but ensure that you can get back inside to make quick repairs, change batteries, modify the hardware, etc.

Now see some great enclosure build ideas https://itp.nyu.edu/fab/intro_fab/week-4-enclosures/

When considering the placement of the panic button, think of places that its user may be situated for a while (and perhaps alone). In most cases, the best place for the panic button is on the nightstand or on the wall next to the bed so that the user will always have a quick way to alert others in an emergency. Likewise, it is important to install the panic alarm device (the alarm box) in a proper location to bring the situation to first responders immediately.

This is a view of my prototype wired on a standard breadboard! Note that the Rpi Pico board is powered by a USB power bank, and an active 12VDC buzzer (2.5kHz, 100dB) is used as the alarm sounder. The alarm sounder circuitry (mosfet module and piezo buzzer) is powered by an independent 12VDC power source.

Essentially this is just a cheap and easy way to test the RPi Pico panic alarm concept. The basic idea can however be enhanced with other types of momentary switches, foot pedal switches, tilt switches or even some types of electronic sensors (and transducers), too. Give it a Go!

Watch my quick test video https://youtu.be/swnrQDusTcs

Take It Further…

So that’s the bedrocks when it comes to setting up a simple RPi Pico Panic Alarm. Hopefully you’ve got some solid inspiration and gathered more practical insight into creative and robust panic alarm design. Now get out there and make something!

Okay, I hope you found this tutorial to be helpful. If you have any questions or feedback just leave it in the comments below and I’ll be sure to reply right away.

Leave a Comment