Either adapt this to work with the step pad or follow this directly to use HCSR-04 Ultrasonic sensor (step pads you have to actually step on and they're finicky - for reference just go to any Spirit Hallowe'en and see that they're finicky on the floor models).
Tip from a 10-year Hallowe'en Arduino Enthusiast: your original idea sounds epic. Unfortunately, it's 35 days 'til the big night and you don't have time for that. Start on that November 1 for next year (after you raid Spirit Hallowe'en for all the deals).
The sketch and instructions that follow should be easy enough to get you up and running. This single prop controller will work for anything you'd power with that relay module with a few tweaks you should be able to figure out. For AC loads just imagine the relay taking the place of the mechanical switch, because after all, that's what a relay is - an electrically operated switch. Sorry if I'm telling you stuff that's very basic to you but I hope to save you time.
Of course, copy this sketch and never change it. Make copies and change those.
/*****************************************************************************
******************* HALLOWE'EN SONIC FOGGER 2024 EDITION ********************
*****************************************************************************
--general info and summary--
THIS USES AN ARDUINO AND ULTRASONIC SENSOR OR THREE TO ACTIVATE THE SWITCH
ON A PREHEATED SPIRIT HALLOWE'EN LOW LYING FOG MACHINE BY BYPASSING THE SWITCH
AND SWITCHING IT INSTEAD WITH A RELAY MODULE.
THIS WILL WORK THE SAME FOR ANY OF THEIR FOGGERS THAT COME WITH A MANUAL
SWITCH, WHICH THEY ALL HAVE FOR AT LEAST THE TEN YEARS I'VE BEEN A
HALLOWE'EN NUT. WILL ALSO WORK WITH ANY 5V ARDUINO BOARD THAT SUPPORTS THE
NEWPING LIBRARY (ALL AVR BOARDS PLUS MOST OF THE OTHERS).
------------------build details---------------------
<<< EQUIPMENT >>>
[hardware]
ARDUINO NANO EVERY x 1
WHADDA 5V RELAY MODULE x 1
HCSR-04 Ultrasonic sensor modules 1-3x
SPIRIT HALLOWE'EN 01423078 400W LOW LYING FOG MACHINE (COFFIN SKELETON)
GENERIC SMART PHONE BATTERY BACKUP OUTPUT 5V/2.4A MAX, 5200mAh/19.2Wh
CORD TO CONNECT BATTERY BACKUP TO ARDUINO NANO EVERY.
FEMALE-TO-FEMALE DUPONT JUMPER WIRES min 7, max 15
[software]
Arduino IDE v2.3.2
NewPing Arduino library v1.9.7 (available in IDE under Sketch > Include Library > Manage Libraries > NewPing )
or here: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home as of the time of this writing.
<<< UPLOAD THIS CODE TO YOUR ARDUINO >>>
BEING SURE TO SELECT THE CORRECT BOARD AND
COM PORT UNDER Tools > Board and Tools > Port in the Arduino IDE.
<<< ASSEMBLE THE CIRCUIT: >>>
The switch that comes with Spirit Hallowe'en fog machines has 3 wires:
mine had white, black and green. I cut them all off the switch and
stripped back 1/4" on the white and green. We will use a 5V relay
module (I used a Whadda brand model WPM406 5V relay module).
The HCSR-04 ultrasonic sensor senses something within 400 cm (about 13').
Change as needed below.
I did not use the black wire but it is cut off the switch and just taped
to the switch housing plastic.
The switch will measure something like 8VAC when the heater isn't warm enough
across the two stripped wires. Once the heater is warm, you will be
able to hear the built in internal relay of the fog machine click to
activate the stock switch. This is the action we are bypassing with the
Arduino and relay module. If you measure the voltage now, you will see
about 120VAC (North America).
WIRE fog machine Normally Open (NO) switch as follows:
switch green to relay C (common)
switch white to relay NO (Normally Open)
WIRE HCSR-04 sensors (use one, two or three, spaced out to cover some
periphery as you like):
the sensors themselves are all powered by Arduino analog pins
driven HIGH during void setup(). Choose any of A0, A1 or A2.
Typically this is ill-advised as a way to power devices; however,
since the Nano Every can tolerate up to 20mA current per I/O pin
and each sensor needs only 15mA @ 5V to function, it's fine.
WIRE all the grounds of all the sensors to Arduino GND.
WIRE Sensor Trigger/Echo pin combos:
D6, D7 and D8, D9 and D10, D11.
WIRE Arduino to relay module connections:
Connect Arduino D5 to relay S (Signal)
Connect Arduino GND to relay module -
Connect Arduino +5V pin to relay module +
Power Arduino with USB smart phone battery backup
power bank.
Tested and working as expected.
By Hallowed31
Five-second timer revision courtesy of Arduino Forum member kolaha
2024-09-09
*/
#include <NewPing.h>
const int sonarNum = 3; // Number of HC-SR04 sensors
const int maxDistance = 400; // Max distance to ping for (cm). Adjust this number as needed up to 400
const int sensor1PowerPin = A0; // we will use the analog pins to power the sensors
const int sensor2PowerPin = A1;
const int sensor3PowerPin = A2;
// use one to three sensors to cover desired range of detection, sketch won't care which
NewPing sonar[sonarNum] = {
// Each sensor's trigger pin, echo pin, and max distance to ping for.
NewPing(6, 7, maxDistance), // each of these can be manually adjusted if needed different distances
NewPing(8, 9, maxDistance),
NewPing(10, 11, maxDistance)
};
const int fogPin = 5;
const int led = LED_BUILTIN;
const unsigned long pingTimer = 50;
unsigned long lastPingInterval = 0;
unsigned long lastFogCountdown = 0;
unsigned long fogOnInterval = 5000; // 5 seconds, adjust if you like
byte state;
int ledState;
int fogPinState;
void setup() {
pinMode(fogPin, OUTPUT);
pinMode(led, OUTPUT);
pinMode(sensor1PowerPin, OUTPUT);
pinMode(sensor2PowerPin, OUTPUT);
pinMode(sensor3PowerPin, OUTPUT);
digitalWrite(sensor1PowerPin, HIGH);
digitalWrite(sensor2PowerPin, HIGH);
digitalWrite(sensor3PowerPin, HIGH);
fogPinState = LOW;
ledState = LOW;
Serial.begin(115200);
// some blank lines because I like them
for (int j = 0; j < 15; j++) {
Serial.println("");
}
Serial.println(F("halloweenSonicFoggerV2024ed\n"));
state = 0;
Serial.println("off");
}
void loop() {
unsigned long pingInterval = millis();
if (pingInterval - lastPingInterval >= pingTimer) {
lastPingInterval = pingInterval;
for (uint8_t i = 0; i < sonarNum; i++) {
if ((sonar[0].ping_cm() == 0) && (sonar[1].ping_cm() == 0) && (sonar[2].ping_cm() == 0)) {
state = 0;
} else if ((sonar[0].ping_cm() >= 10) || (sonar[1].ping_cm() >= 10) || (sonar[2].ping_cm() >= 10)) {
state = 1;
}
}
}
switch (state) {
case 0:
fogPinState = LOW;
ledState = LOW;
noFog();
break;
case 1:
fogPinState = HIGH;
ledState = HIGH;
deployFog();
break;
default:
fogPinState = LOW;
ledState = LOW;
noFog();
break;
}
}
void deployFog() {
Serial.println("\non");
unsigned long thisFogTimer = millis();
while (millis() - thisFogTimer <= fogOnInterval) {
digitalWrite(fogPin, fogPinState);
digitalWrite(led, ledState);
}
Serial.println("\noff");
state = 0;
}
void noFog() {
digitalWrite(fogPin, fogPinState);
digitalWrite(led, ledState);
}
For those about to Haunt, I salute you 