Fog machine trigger on an Arduino Uno
A PIR fires a relay across a fog machine’s remote button for a short burst, then a cooldown with a red lamp lets the fog drift and the heater recover. The whole build, an Arduino Uno and 8 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
Build it as the Halloween Prop Kit: the parts in numbered bags and a booklet that checks every step. Free.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Fog machine trigger: a PIR sees someone coming up the path and a relay
// presses the fog machine's remote button for a short burst. Then a cooldown
// keeps it from firing again until the fog has had time to drift and the
// machine has had time to heat back up.
//
// PIR VCC -> 5 V GND -> GND OUT -> pin 2
// relay VCC -> 5 V GND -> GND IN -> pin 7 (high pulls it in)
// COM and NO go across the fog machine's remote button
// ready LED green, pin 4 through 220 ohms to GND
// cooling LED red, pin 3 through 220 ohms to GND
//
// On the canvas the relay's contacts switch the 5 V rail to a white LED. That
// LED stands in for the fog machine's remote: when it lights, the contacts are
// closed and the machine would be pushing fog.
//
// SAFETY. Do not switch the fog machine's mains power with this relay, and do
// not open the machine. Most fog machines come with a wired remote that is
// just a low-voltage push button: wire the relay's COM and NO across that
// button (or across a spare remote's button) and the mains side never comes
// near the Arduino. Use a relay module rated for the job, with the coil
// driven by its own transistor, as these blue modules are. Fog fluid on a hot
// heater is the whole trick, so keep the machine where nobody can touch the
// nozzle, never leave it running unattended, keep fog away from smoke alarms
// you cannot switch off, and keep it away from anyone who has asthma.
//
// Most machines also need to stay plugged in to keep their heater hot, and
// will not fog while it recovers. If yours has a READY light, set COOLDOWN_MS
// to at least the time that light takes to come back after a burst.
//
// Things to try. Click the PIR. Make the burst shorter for a tabletop prop or
// longer for a whole yard. Add a pushbutton on pin 8 as a manual "fog now"
// that still honors the cooldown.
const int PIR_PIN = 2;
const int RELAY_PIN = 7;
const int READY_LED = 4;
const int COOL_LED = 3;
const unsigned long BURST_MS = 2500; // how long the button is held
const unsigned long COOLDOWN_MS = 20000; // before it may fire again
enum State { READY, FOGGING, COOLING };
State state = READY;
unsigned long since = 0;
unsigned int bursts = 0;
void show(State s) {
digitalWrite(READY_LED, s == READY ? HIGH : LOW);
digitalWrite(COOL_LED, s == READY ? LOW : HIGH);
digitalWrite(RELAY_PIN, s == FOGGING ? HIGH : LOW);
}
void setup() {
Serial.begin(9600);
pinMode(PIR_PIN, INPUT);
pinMode(RELAY_PIN, OUTPUT);
pinMode(READY_LED, OUTPUT);
pinMode(COOL_LED, OUTPUT);
show(READY);
Serial.println("Fog trigger ready");
}
void loop() {
unsigned long now = millis();
switch (state) {
case READY:
if (digitalRead(PIR_PIN) == HIGH) {
state = FOGGING;
since = now;
bursts++;
show(state);
Serial.print("Fog burst ");
Serial.println(bursts);
}
break;
case FOGGING:
if (now - since >= BURST_MS) {
state = COOLING;
since = now;
show(state);
Serial.println("Cooling down");
}
break;
case COOLING:
if (now - since >= COOLDOWN_MS) {
state = READY;
show(state);
Serial.println("Ready");
}
break;
}
}
Parts list
10 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Arduino Uno R3
- 1 × Half breadboard
- 3 × Resistor, 220 Ω
- 1 × LED, green
- 1 × LED, red
- 1 × LED, white
- 1 × Motion sensor
- 1 × Relay module
How it is wired
10 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 7; Relay module pin IN
- Arduino Uno R3 pin 4; Resistor, 220 Ω (1) pin 1
- Arduino Uno R3 pin 3; Resistor, 220 Ω (2) pin 1
- Arduino Uno R3 pin 2; Motion sensor pin OUT
- Arduino Uno R3 pin 5V; Motion sensor pin VCC; Relay module pin VCC; Relay module pin COM
- Ground: Arduino Uno R3 pin GND; LED, green pin C; LED, red pin C; LED, white pin C; Motion sensor pin GND; Relay module pin GND
- Resistor, 220 Ω (1) pin 2; LED, green pin A
- Resistor, 220 Ω (2) pin 2; LED, red pin A
- Resistor, 220 Ω (3) pin 1; Relay module pin NO
- Resistor, 220 Ω (3) pin 2; LED, white pin A
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.