Introduction: Interactive Halloween Pumpkin (Arduino Based)

About: A maker and electronics enthusiast.


A pumpkin that glows, shakes and screams... [video]

It's Halloween, so naturally we had to have a project related to that.

The idea is to have a pumpkin, which senses presence of a person trying to get to the candies, and then employs various "scary" effects as the person gets closer and closer to boo them away.

This is how it works:

  1. When no one is around the pumpkin is "asleep"
  2. Using microphone and two motion sensors (hidden in the corners of its mouth), the pumpkin "wakes up" if a sound or motion is detected
  3. Upon woke up, the pumpkin "winks" its eye (or eyes) briefly and "buzzes". This is a hint to an unsuspecting candy hunter, that something is going on over there...
  4. As the person approaches, the pumpkin uses ultrasonic distance sensor (hidden in its nose) to let the unsuspecting victim come closer
  5. At about 2 meters, the pumpkin starts "glowing" red, blue or green to scare the weakest candy hunters away.
  6. The bravest ones approach further, and are greeted with scary red eyes, glowing red light and a LOUD SCARY YELL at about 50 centimeters away...

If this does not scare most away, I don't know what will...

Step 1: PARTS

You will need the following to build interactive pumpkin:

  1. HALLOWEEN Grand Venture Pumpkin JOL Candy Pail Bucket Blow Mold (or similar) - on Ebay
  2. Arduino Compatible Uno R3 Rev3 Development Board - on
  3. Prototype Shield DIY KIT for Arduino (or similar) - on
  4. 5mW 650nm Red Laser Diode Module Head (5-Pack) - on
  5. 2 x 50mm Asfour Feng Shui Crystal Ball Prisms - on
  6. 2 x HC-SR501 Pyroelectric Infrared PIR Motion Sensor Detector Module - on
  7. HC-SR04 Ultrasonic/Sonar Distance Sensor Module - on
  8. 2 x DC 5V 3200RPM Electric Mini Vibrating Motors - on
  9. LM386 Arduino Compatible Digital Microphone/Sound Sensor Module - on
  10. 5mm Round Head Common Cathode RGB Light LED Emitting Diode - on
  11. 74HC02 NOR Gate - on
  12. L293D 16-pin Integrated Circuit IC Motor Driver - on
  13. SD SDHC Card MP3 Player Board Module TTL - on
  14. SD Card for audio MP3 files (capacity depends on how many different files you want to have)
  15. LM386 Audio Amplifier Module 200 Times 5-12V 10K Adjustable Resistance - on
  16. 5W 8 Ohm Rectangular Internal Magnet Speaker - on
  17. Resistors, wires, soldering equipment and supplies
  18. Hot glue gun and LOTS of glue sticks
  19. Sharp knife set - similar to this set: Xacto X5282 Basic Knife Set
  20. USB cable for powering up the components

Step 2: EYES

Cut out eye sockets on the pumpkin with a sharp knife with a diameter to accommodate the front of crystal.

Pumpkin "eyes" are assembled by attaching 5mW 650nm Red Laser Diode Module to the back of Asfour Feng Shui Crystal Ball Prism using hot glue. The multi-facet prism creates multiple reflections of the laser beam, and produces quite menacing look.

Attach the resulting eye assembly to the inside of the pumpkin using glue gun with lots of hot glue.

Parts: 5mW 650nm Red Laser Diode Module Head, 50mm Asfour Feng Shui Crystal Ball Prism


Two infra-red motion sensors are placed at the corners of pumpkin mouth.

Cut two holes at the corners of pumpkin mouth and place the sensors in such a way that you can adjust sensitivity and detection pause later.

Attach the sensors with hot glue.

Signal from motion detectors and sound sensor is used to activate (wake up) Arduino microcontroller (via hardware interrupt on pin 2). More about electronics later...

Part: HC-SR501 Pyroelectric Infrared PIR Motion Sensor Detector Module


Ultrasonic distance sensor is located in the "nose" of the pumpkin, which gives it a look similar to piggies from the Angry Birds game (albeit orange).

Same mounting process as with motion sensors: cut two holes, glue the sensor in place with hot glue.

Part: HC-SR04 Ultrasonic/Sonar Distance Sensor Module


We used 3 color common cathode LED to make pumpkin glow.

To make the glowing a little brighter and scarier, the LED is positioned on top of a circular disk, made from cardboard, and covered with foil for better reflection.

Reflective disk with 3 color LED is positioned behind the pumpkin's mouth to glow through the cut-out teeth.

The "glow" effect is achieved via controlling RGB LED pins via Arduino PWM pins. Please refer to pin-out and sketch steps for details.

Parts: 5mm Round Head Common Cathode RGB Light LED Emitting Diode, Resistors.


To make pumpkin scarier and allow glowing to really show through, we cut out little squares in pumpkin's mouth, to give it a "missing teeth" look.


To make pumpkin wake up not only on motion, but on loud sound as well, we added a sound sensor, which is glued with a double-sided tape to the inside of the pumpkin close to the top.

Part: LM386 Arduino Compatible Digital Microphone/Sound Sensor Module


Scary sounds are played by the MP3 board via amplifier.

The sound board is attached to the Arduino board, the amplifier is located closer to the speaker, and the speaker is located at the in the back at the top of the pumpkin. Cut out a few parallel holes to let the sound through.

Part: LM386 Audio Amplifier Module 200 Times 5-12V 10K Adjustable Resistance, 5W 8 Ohm Rectangular Internal Magnet Speaker


To make the pumpkin even scarier, the idea was to make it shake in addition to glow lights.

Two eccentric motors are attached to the top of pumpkin to give it a shake.

Unfortunately, because crystals turned out to be heavier than we expected, and we had to use counterweights to prevent pumpkin from tipping over, the eccentric motors appeared to be too weak to actually shake the pumpkin - they just give it a nice buzzing vibration. You might want to find a bigger motors or heavier eccentric weights on them...

Parts: 5V 3200RPM Electric Mini Vibrating Motor

Step 10: SOUNDS

Scary sounds are played via MP3 board.

We chose SD SDHC Card MP3 Player Board Module TTL because it has an SD card slot, and could play files randomly. THe board supports various control modes. We used serial interface for the simplicity of use, although it does present a slight challenge during sketch upload time. Not too inconvenient though.

The MP3 board has very specific requirements for file names and locations. In our case, we just placed properly named files in the root folder of the FAT16 formatted SD card, and let the board handle random selection by itself.

Please refer to Sketches and Files section below for sound files.

Part: SD SDHC Card MP3 Player Board Module TTL


The last, but not least part of the pumpkin is Arduino Uno, motor control and wake-up triggering circuit.

All circuitry is assembled on the Arduino Compatible Uno R3 Rev3 Development Board

Eccentric motors are controlled via L293D chip, which conveniently supports 2 motors.

The wake-up interrupt circuit consists of 74HC02 NOR gate, to which outputs from 2 motion sensors and sound sensor are connected.

Please refer to the electronic schematics step for connection details.

Triggering logic: if any of the motion sensor signals are HIGH, or sound sensor signal is HIGH, wake up the device (due to use of NOR gate, the resulting signal is LOW, so this is an Active Low configuration).


Schematics picture, attached to this steps, depicts interconnection of the pumpkin electronic components.

This schematic was created with Fritzing software. Please refer to Sketches and Files step for the actual fritzing file.


Fitting the components in:

It is not easy to fit all the components inside the pumpkin via top opening. We actually had to cut the back of the pumpkin open, and sealed it back with hot glue after everything was installed.


Unfortunately, the crystal prisms turned out to be heavy, and pumpkin was tipping over on its face with crystals attached. To balance the pumpkin, we had to attach D-size batteries to the back of the pumpkin.


Finally, when everything was in place and tested, we covered the pumpkin with a meshed protective cover from the 120mm fan.


Below is pinout for the Arduino board at the heart of "interactive" part:

d00 MP3 board TRx
d01 MP3 board RSx
d02 Motion Sensors and Sound Sensor IRQ input from NOR gate
d03 Red LED (PWM)
d04 Right Eye laser
d05 Eccentric motor1 L293D enable (PWM)
d06 Eccentric motor2 L293D enable (PWM)
d07 Left Eye laser
d08 Sonic Sensor echo pin
d09 MP3 Device ready interrupt pin
d10 Blue LEDn (PWM)
d11 Green LED (PWM)
d12 Sonic Sensor trigger pin


Three aspects of the sketch are worth mentioning:

DirectIO library

Not only DirectIO library makes reading from and writing to Arduino pins much faster, it also allows treating pins as variables.

Instead of writing

	digitalWrite(13, HIGH);  	

use can just write


PinChangeInt library

PinChangeInt gives you access to pin interrupts on all Arduino pins. This library was essential for coding ultrasonic measurement routine without the use of pulseIn function.
There is nothing wrong with pulseIn per se, except the fact that it is blocking function, i.e., until the edge of the pulse is detected (or until a timeout) nothing else is going on. Since pumpkin sketch is written with cooperative multitaskling in mind, this is unacceptable.

Instead of using pulseIn, the ultrasonic process is broken into major 3 steps:

  1. Trigger the ultrasonic pulse
  2. Trap echo pin interrupt on the RAISING edge (start counting microseconds)
  3. Trap echo pin interrupt on the FALLING edge (stop counting microseconds)

While echo is travelling, microcontroller can run other tasks.

Please refer to Sketch for more details.

TaskScheduler library

TaskScheduler implements cooperative multitasking for Arduino microcontrollers.

Once you use TaskScheduler, programming Arduino transforms into defining a number of "tasks" that your device needs to do, and interactions between them.

For instance, the pumpkin needs to do the following:

    1. Detect Motion
    2. Measure Distance
    3. "Wink" eyes when motion is detected
    4. "Glow" 3 color LED when certain distance is detected
    5. ":Scream" when someone is really near

In addition, 3 specific "hardware" tasks are necessary

    1. Task to control Eyes (wink and blink)
    2. Task to control Motors (vibrate for a specific time)
    3. Task to control LED (glow)

Each of the functions above is created as a task. For instance:

Scheduler ts;
Task tMotion(0, 1, &MotionDetectedCallback, &ts);

task tMotion runs once, and calls method MotionDetectedCallback, which is responsible for deciding what needs to happen once motion is detected based on the distance.

Task tTimeout(TASK_TIMEOUT, 1, &TimeoutCallback, &ts);

task tTimeout puts pumpkin back to sleep if no activity took place for 1 minute.

Task tDistance1(TASK_DIST_INTERVAL, -1, &DistanceTriggerCallback1, &ts);

Task tDistance runs every 100 milliseconds and triggers ultrasonic distance measuring.

No special coordination is required between independent tasks since Scheduler is taking care of it.
Explicit dependencies between the tasks are reflected in the callback methods code, e.g.,:

void MotionDetectedCallback() {  
  tTimeout.restartDelayed();   // Set overall timeout to put device to sleep if inactive
  tDistance1.enableIfNot();    // Start distance measuring	
  if ( tScream.isEnabled()  || tFlash.isEnabled() || tWink.isEnabled() ) return;
  tWink.set(TASK_WINK, 1, NULL, &WinkOnEnable, &WinkOnDisable);

once motion is detected, the Motion detection task:

  1. Resets the timeout task
  2. Enables distance measuring (if was not enabled already)
  3. Checks if pumpkin is already winking, glowing or screaming
  4. If not, starts "winking" task

For more details on TaskScheduler please refer to the documentation page on

For more details please also refer to the Sketch page.



DirectIO library is available on Github

PinChangeInt library is available on Arduino Playground

TaskScheduler library is available on Github (and via library manager starting with Arduino IDE v 1.6.6)

DlpFilter (Digital Low Pass) library is available here.


Version 1.0.0 of the sketch is available here.

SCHEMATICS (Fritzing):

Schematics are available here. (Note: please refer to Schematics tab only - nothing else was edited)


Sample MP3 audio file


HC-SR501 Infrared Motion Detector

SD SDHC Card MP3 Player Board Module TTL

L293D 16-pin Integrated Circuit IC Motor Driver

HC-SR04 Ultrasonic/Sonar Distance Sensor Module

74HC02 NOR Gate

Make It Glow! Contest

Participated in the
Make It Glow! Contest

Halloween Decor Contest 2015

Participated in the
Halloween Decor Contest 2015

Pumpkin Challenge

Participated in the
Pumpkin Challenge