Pi Pico Code to control a fog machine via variable timer or motion sensors
I bought this fog machine for Halloween. It worked great, but almost too great. The automatic mode ran 30 seconds every 2-3 minutes which seems fine ... until after about 30 minutes and there's smoke all over our front yard into the street.
I wanted a way to control the duration it is on and off to not put out as much fog. But it didn't offer that. It only offered the automatic mode, a wireless button, and a mechanical button.
So I built a small microcontroller circuit to control it the way I wanted, with parts < $10.
So I did the following:
- Soldered two wire leads to the inside switch of the mechanical button,
- Bought a Raspberry Pi Pico,
- hooked it to a 5V relay module,
- Hooked relay to the switch leads,
- Wired this PIR sensor module to a GPIO pin, and
- Set the pin as an interrupt to trigger the fogger on motion as well as timer.
The relay module was a useful way to activate that mechanical switch with circuit isolation.
The main.py
can be uploaded to the Pico via a tool like Thonny after you flash it with MicroPython firmware.
The main.py
is a timer that switches the onboard LED and relay pin ON/OFF. When the pins are OFF, it can be optionally interrupted via the interrupt pin (i.e. with a PIR motion detection event), which will turn the LED/relay back on.
- "I SCARED my Daughters using a Raspberry Pi" YouTube Video by NetworkChuck
- I watched this after I created the controller, but wish I had it as a resource while I was building.
- Great intro to how to use a Pi to control various Halloween devices via sensors, iphone, and other means
- Centered around Raspberry Pi and not the Pico, but it's quite close in implementation for these purposes.
- Raspberry Pi Pico and HC-SR501 Motion Sensor
- Provides pin connection diagrams and descriptions of the behavior of the HC-SR501 PIR sensor module