Introduction: Spooky ESP8266 Halloween Hack, With Motion Sensor and Light / Sound / Animation

About: Maker, I make 3D design, 3D printing, electronics, puzzles

For Halloween, I wanted to have a spooky decoration, of course, but with a bit of electronics !

I have imagined a motion sensor, which triggers various candle leds, an animated crawling spider, and a spooky witch sound when someone arrives. That should be nice!

All that is operated by a NodeMCU v3 module, based on ESP8266 (quite similar to Arduino, but I just love the ESP8266!).
I classify the required level as intermediate. You have to know how to use the NodeMCU and how to program with Arduino IDE. The circuit and code are not complex, just requires a bit of hacking of various items.

Of course, all electronic components has to be hidden within the rest of the Halloween decoration for a nice surprise effect.

Let's get started !

Step 1: Parts

Here is the list of the electronic parts you need. You can find them quite easily in your favorite online store.

  • 1 NodeMCU v3 (ESP8266)
  • 1 smartphone powerbank (5v, at least 3000 mAh)
  • 10 flameless led candles powered at 3v
  • 1 PC fan powered at 12v (with 65 CFM in my case, to get enough power in air blowing)
  • 1 Halloween sound machine (there are different models available, but they are equivalent even if wiring is not exactly identical from one to another, and are powered at 5v)
  • 2 pyroelectric infrared motion sensor detector module HC-SR501
  • 1 L293D bridge
  • 1 MT3608 2A DC-DC step up power module booster

And of course:

  • Various cables, breadboards, solder iron (optional), electrical tapes, etc for prototyping
  • PC with arduino IDE configured for ESP8266 (there are many tutorials available if you need)

And for your Halloween decoration, you can use your imagination but here are the various items I used:

  • 2 large carved Jack O'Lantern pumpkins, 1 small one
  • 1 big plastic spider, snake, bats, etc
  • spider webs
  • 1 large bucket with a lid which can enclose all the electronic components (I used a large yogurt container)

The cost of all parts amounts to something like 40 euros.

Step 2: Circuit

Here is a global picture of the wiring. Don't worry, we will go step by step through the different types of components.

It is the first time I a using Fritzing. I did not really try to create a part for the Halloween Sound Machine. I added instead a text note with a generic 2-pin connector.

I have also attached the .fzz Fritzing file.

Step 3: Motion Sensors

The bucket is our Halloween robot head, and contains all the electronic components. Use small breadboards for prototyping to fit in the bucket.

Cut out 2 eyes in the bucket the same size as the motion sensors. Paint it in grey, add a nose and a scary mouth. Set up the 2 motion sensors inside the bucket, attached with electrical tape.

Make sure the pins are accessible and that you can spot Ground, Output and +V for each sensor.

Wire the motion sensors (HC-SR501) as described in the picture:

  • HC-SR501:+V to NodeMCU:+5V
  • HC-SR501:Out to NodeMCU:D0 (16)
  • HC-SR501:G to NodeMCU:G

The two sensors are in parallel to get a better angle coverage (and 2 eyes !).

Take at least 30 cm cables between the motion sensor breadboard and the NodeMCU breadboards to get enough length to maneuver. Tape the small breadboard inside the bucket.

Step 4: Flameless Led Candles

Let's work on these flameless led candles. It is a very simple hack.

Start by removing the battery. Check out where are positionned (+) and (-) of the battery, and the corresponding pins.

Then, you can either solder or tape 2 cables, a black one on (-) and a red one on (+). Make sure you have plenty of cable length (50 to 75 cm) for each candle, so you are not limited by the available length to arrange your decoration later.

Finally, use a file or a cutter (always work carefully with those tools) to let the 2 cables go through the plastic casing of the candle. And that's it, you have 10 candles to hack. !

For the wiring, I have arranged the 10 led candles into 3 groups, and used a small breadboard to arrange all cables:

  • 3 candles wired in parallel
    • Candle:(+) to NodeMCU:DXX(XX)
    • Candle:(-) to NodeMCU:G
  • 3 candles wired in parallel
    • Candle:(+) to NodeMCU:DXX(XX)
    • Candle:(-) to NodeMCU:G
  • 4 candles wired in parallel
    • Candle:(+) to NodeMCU:DXX(XX)
    • Candle:(-) to NodeMCU:G

Step 5: PC Fan

Now, we take a standard PC fan for a nice homemade "crawling spider" animation.

The original idea was to use the fan to blow air and move the spider web, but that did really not work. The fan is probably not powerful enough (65 CFM in my case) and the spider web moves just a bit. Nevermind, the effect with the spider is nice enough !

Refer to the diagram for wiring the PC fan. We use only 2 cables from the fan, red and black, even if there can be 3 or 4 cables on some models. The PC fan is powered at 12v but the logic for the NodeMCU is at 3.3v. So we use first, a L293D bridge to output 5v, and we had a Power Booster MT3608 to boost is to 12v.

For the power booster MT3608, usually you have to solder the pins, and adjust power by turning the screw counter-clockwise and monitoring with a voltmeter to get to 12v as output with 5v as input.

For the bridge L293D, you can refer to the pin out sheet.

Connect following the attached diagram (keep sound machine for next step):

  • NodeMCU:3V to L293D:VCC1
  • NodeMCU:3V to L293D:Enable1 (forced to HIGH, we don't need to change it)
  • NodeMCU:G to L293D:GND (all 4 of them)
  • NodeMCU:5V to L293D:VCC2
  • NodeMCU:D1 (5) to L293D:Input1
  • L293D:Output1 to MT3608:Vin+
  • L293D:GND to MT3608:Vin-
  • MT3608:Vout+ to Fan:+(red)
  • MT3608:Vout- to Fan:-(black)

I have enclosed the fan in a small box, covered in silver duct tape. I taped a straw underneath, so that it does not lay flat on the table and rocks a little when the fan is rotating. Finally, I taped to the fan a piece of silver duct tape, which will brush the legs of the spider when the fan is rotating. Make sure the piece of tape is not too small but not too big so that rotation is not impaired.

Finally, the spider can be positionned on top of the fan, with the legs just at the right level to move with the fan. Nice animated crawling spider !

Step 6: Halloween Sound Machine

Now let's see how to hack this Halloween sound machine ! It is the most tricky part of the instructable, but it should be fine.

First, you have to check that the sound machine is working fine out of the box, with the batteries loaded. I have selected the witch laugh sound, marked by a witch hat on the keyboard. Feel free to choose the one you want.

Then, remove the screws and open gently the sound machine. The cables are quite thin and the soldering quite weak (yes, it is a cheap machine...), so be gentle.

When it is open, you can spot the emplacement of the witch button on the PCB (marked P12 in the picture below). I have tried a couple of different sound machines, the PCB design can be a bit different, but the principle remain the same. In order to trigger the sound, you have to establish contact with a wire between the left and right parts of the P12 button emplacement (blue square on the picture).

If you notice, at least for this model, the left part is linked to VDD (+5V). So to establish contact you need to connect a 5v cable from the NodeMCU, through the L293D bridge, to the red spot and connect Ground to Ground of course (Ground is in a brown square on the picture).

Connection instructions following the attached diagram, assuming you have already wired the fan:

  • NodeMCU:D2 (4) to L293D:Input2
  • L293D:Output2 to SoundMachine:P12 (red)
  • NodeMCU:G to SoundMachine:G (black)

You can solder cables on the PCB. It is quite tricky, because you have to solder on a tiny flat spot, but feasible. I did it on another model.

In the present case, I did not want to mess with the sound machine and take a risk to ruin it (I had ruined one already...). So I used electrical tapes to maintain contacts between the PCB and cables.
Not very elegant, not very robust, but hey, it works.
See the picture with the ugly tape all over the place.


Step 7: Code

See the code below, or download the .ino file for Arduino IDE. The comments are pretty straightforward.

// ESP8266 HACK BY KPTAINKIRK
// MOTION SENSOR ACTIVATED, WITH LIGHT, SOUND AND ANIMATION // OCTOBER 2017

int ledPin1 = 14; // First group of LEDS - NODEMCU D5
int ledPin2 = 12; // Second group of LEDS - NODEMCU D6
int ledPin3 = 13; // Third group of LEDS - NODEMCU D7
int inputPin =16; // PIR sensor - NODEMCU D0
int fanPin = 5; // FAN - NODEMCU D1
int audioPin = 4; // AUDIO - NODEMCU D2
int pirState = LOW; // previous state for PIR sensor, initial state is LOW assuming no motion detected
int val = 0; // variable for reading current PIR sensor status
int calibrationTime = 30; // time in seconds for PIR sensor to calibrate (10-60 secs according to the datasheet)

void setup() {
pinMode(ledPin1, OUTPUT); // declare LED as output
pinMode(ledPin2, OUTPUT); // declare LED as output
pinMode(ledPin3, OUTPUT); // declare LED as output
pinMode(fanPin, OUTPUT); // declare FAN as output
pinMode(inputPin, INPUT); // declare PIR as input
pinMode(audioPin,OUTPUT); // declare AUDIO as output
Serial.begin(9600);

Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000); }
}

void MyLed(byte led1, byte led2, byte led3, unsigned long msec){
// Control the 3 groups of LEDS during duration of msec
digitalWrite(ledPin1, led1);
digitalWrite(ledPin2, led2);
digitalWrite(ledPin3, led3);
delay(msec);
}

void loop(){
val = digitalRead(inputPin); // read input value from PIR sensor
Serial.println(val);
if (val == HIGH) { // check if the input is HIGH

digitalWrite(fanPin, HIGH); // turn FAN on
MyLed(HIGH, LOW, LOW, 3000); // light 1st group of LEDS
MyLed(LOW, HIGH, LOW, 3000); // light 2nd group of LEDS
MyLed(LOW, LOW, HIGH, 3000); // light 3rd group of LEDS


MyLed(HIGH, HIGH, HIGH, 500); // blink all LEDS
MyLed(LOW, LOW, LOW, 500);
MyLed(HIGH, HIGH, HIGH, 500); // blink all LEDS
MyLed(LOW, LOW, LOW, 500);
MyLed(HIGH, HIGH, HIGH, 500); // blink all LEDS

digitalWrite(audioPin, HIGH); // turn AUDIO on
delay(2000);
digitalWrite(audioPin, LOW); // turn AUDIO off
MyLed(LOW, LOW, LOW, 500);
MyLed(HIGH, HIGH, HIGH, 500); // blink all LEDS
MyLed(LOW, LOW, LOW, 500);
MyLed(HIGH, HIGH, HIGH, 1500); // turn on all LEDS

if (pirState == LOW) { // we have just turned on
Serial.println("Motion detected!"); // We only want to print on the output change, not state
pirState = HIGH; }
} else {
digitalWrite(ledPin1, LOW); // turn 1st group of LEDS off
digitalWrite(ledPin2, LOW); // turn 2nd group of LEDS off
digitalWrite(ledPin3, LOW); // turn 3nd group of LEDS off
digitalWrite(fanPin, LOW); // turn FAN off delay(300);

if (pirState == HIGH){ // we have just turned off
Serial.println("Motion ended!"); // We only want to print on the output change, not state
pirState = LOW; }
}
}

Step 8: Decoration

I let you use your imagination for your Halloween decoration. This is what I did, helped by my wife and the four kids ;-)

I started to carve 2 large Jack O'Lantern pumpkins. I added a slit in the back, which is not visible but let you slide the electric cables to insert the flameless led candles inside.

Then all electronic components (breadboards with NodeMCU, breadboard with L293D, halloween sound machine) have to go inside our bucket, a.k.a our DIY Halloween robot. It is a bit messy with all cables, so secure cables inside at different junction points with electrical tapes here and there. The smartphone battery that powers everything has to remain outside, and easily accessible to be removed or changed.

Finally, decoration time!

I installed the 2 carved large pumpkins, and a small one, on a table covered by a black plastic tarpaulin. In the middle I added our Halloween robot with inside all the electronic components, and on the side the smartphone battery. Then I arranged the fan, with the large plastic spider positionned on it so the legs move when the fan is working, and I arranged the leds.

I added spider web all over the table and the various items. Make sure to spread the web spider as much as possible: the thinner, the better effect. Be carefull to leave plenty of room behind the fan: nothing should have a risk to get caught behind the fan.

And I completed by various plactic toys: spiders, snake, and bats.

Plug the battery, wait for 30 seconds for calibration.

Ready ! Et voila ! You can wait for the kids of your neighborood to ring at your door!