PIR Sensor Halloween Decoration: Motion-Activated Ghost

Project Overview

Create a fun Halloween decoration that comes to life when trick-or-treaters approach. When the PIR sensor detects motion, the ghost lights up with eerie LEDs, plays spooky sounds, and can even move using a servo motor.

Difficulty: Beginner
Estimated time: 2 hours
Estimated cost: $20-30

How It Works

A PIR sensor detects motion. When triggered, the system activates LEDs (in the ghost’s eyes or body), plays a spooky sound through a speaker, and optionally moves a servo to make the ghost shake or wave. After a few seconds, it returns to standby mode.

Materials Needed

  • Arduino Uno or Nano (1)
  • HC-SR501 PIR sensor (1)
  • DFPlayer Mini MP3 module (1)
  • MicroSD card (with spooky sound files)
  • Small speaker (3W, 4-8Ω)
  • LEDs (white or color, 2-4)
  • Resistors (220Ω for LEDs)
  • Servo motor (SG90, optional for moving ghost)
  • White fabric (for ghost costume)
  • Wire or PVC pipe (for ghost frame)
  • Jumper wires
  • Power supply (5V 2A or battery pack)

Circuit Diagram

Connection Table

Component Pin Arduino Pin
PIR Sensor VCC 5V
PIR Sensor GND GND
PIR Sensor OUT Digital Pin 2
DFPlayer Mini VCC 5V
DFPlayer Mini GND GND
DFPlayer Mini TX Digital Pin 11
DFPlayer Mini RX Digital Pin 10 (via 1kΩ resistor)
DFPlayer Mini SPK+ Speaker (+)
DFPlayer Mini SPK- Speaker (-)
LEDs (parallel) Anodes Digital Pin 9 (through 220Ω)
LEDs Cathodes GND
Servo VCC (red) 5V
Servo GND (brown) GND
Servo Signal (orange) Digital Pin 3

Preparing Sound Files

  1. Format microSD card as FAT32.
  2. Create folder named “01” (if using DFPlayer in folder mode).
  3. Add sound files named “001.mp3”, “002.mp3”, etc.
  4. Suggested sounds: ghost moan, spooky laugh, howling wind, scream.
  5. Files should be MP3, 44.1kHz, 128kbps for best compatibility.

Arduino Code

// Halloween Motion-Activated Ghost
// Lights up and plays sounds when motion detected

#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include <Servo.h>

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
Servo ghostServo;

const int pirPin = 2;
const int ledPin = 9;
const int servoPin = 3;

unsigned long lastTriggerTime = 0;
const unsigned long effectDuration = 5000; // 5 seconds of activity
bool isActive = false;

// Spooky sound files (track numbers)
const int ghostMoan = 1;
const int spookyLaugh = 2;
const int howlingWind = 3;
const int scream = 4;

void setup() {
  Serial.begin(9600);
  
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  
  digitalWrite(ledPin, LOW);
  
  ghostServo.attach(servoPin);
  ghostServo.write(90);  // Center position
  
  // Initialize DFPlayer
  mySoftwareSerial.begin(9600);
  
  if (!myDFPlayer.begin(mySoftwareSerial)) {
    Serial.println("DFPlayer error - check wiring");
    while (true);
  }
  
  myDFPlayer.volume(25);  // 0-30
  Serial.println("DFPlayer ready");
  
  Serial.println("Halloween Ghost Ready");
  Serial.println("Waiting 60 seconds for PIR warm-up...");
  delay(60000);
}

void activateGhost() {
  Serial.println("BOO! Ghost activated!");
  
  isActive = true;
  lastTriggerTime = millis();
  
  // Turn on LEDs
  digitalWrite(ledPin, HIGH);
  
  // Randomly choose a sound
  int randomSound = random(1, 5);  // 1-4
  myDFPlayer.play(randomSound);
  
  // Move servo for shaking effect (if attached)
  for (int i = 0; i < 3; i++) {
    ghostServo.write(60);
    delay(150);
    ghostServo.write(120);
    delay(150);
  }
  ghostServo.write(90);  // Return to center
  
  // Alternate LED blinking for extra spookiness
  for (int i = 0; i < 3; i++) {
    digitalWrite(ledPin, LOW);
    delay(100);
    digitalWrite(ledPin, HIGH);
    delay(100);
  }
}

void deactivateGhost() {
  isActive = false;
  digitalWrite(ledPin, LOW);
  ghostServo.write(90);
  Serial.println("Ghost resting...");
}

void loop() {
  bool motionDetected = digitalRead(pirPin) == HIGH;
  
  if (motionDetected && !isActive) {
    activateGhost();
  }
  
  if (isActive && (millis() - lastTriggerTime > effectDuration)) {
    deactivateGhost();
  }
  
  delay(50);
}

Ghost Construction

Frame

  1. Use wire hanger or PVC pipe to create a frame about 2-3 feet tall.
  2. Mount servo motor at the top if using moving ghost.
  3. Attach LEDs at eye positions.
  4. Position PIR sensor at chest height facing forward.

Costume

  1. Drape white fabric (old sheet or cheesecloth) over the frame.
  2. Cut eye holes or use transparent material over LEDs.
  3. Drape the fabric to create a ghost shape.
  4. Secure with tape or wire ties.

Placement

  • Place near entrance or path where trick-or-treaters will walk.
  • Position PIR sensor to detect at 2-3 meters.
  • Hide electronics under the ghost’s fabric or in a box.

Optional Enhancements

Color-Changing LEDs

Use WS2812B addressable LEDs for spooky color effects:

#include <FastLED.h>
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];

// In activation:
for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB(255, 0, 255); // Purple
}
FastLED.show();

Smoke Effect

Add a small fog machine or ultrasonic mist maker for an eerie effect when triggered.

Blinking Eyes

Use two LEDs independently for a blinking effect:

digitalWrite(leftEyePin, HIGH);
delay(200);
digitalWrite(rightEyePin, HIGH);
delay(200);
digitalWrite(leftEyePin, LOW);
delay(200);
digitalWrite(rightEyePin, LOW);

Installation Steps

  1. Assemble electronics: Build circuit on breadboard and test.
  2. Load sounds: Copy MP3 files to microSD card.
  3. Build ghost frame: Create structure and attach servo.
  4. Mount components: Attach PIR, LEDs, speaker to frame.
  5. Add fabric: Drape fabric over frame.
  6. Power up: Connect battery or USB power.
  7. Test: Walk in front to trigger the ghost.

Safety Tips

  • Keep electronics away from water (if outdoors, protect from rain).
  • Use battery power for outdoor setups to avoid extension cords tripping hazards.
  • Ensure PIR sensor lens is not blocked by fabric.
  • Test sound volume to ensure it's spooky but not too loud for young children.
  • Position so children can approach safely.

Project Extensions

  • Motion tracking: Use multiple PIR sensors to track movement across yard.
  • Remote control: Add Bluetooth to trigger ghost from phone.
  • Interactive responses: Add different sounds for different motion patterns.
  • Projection mapping: Add projector to cast ghost images on walls.
  • Wireless sync: Use ESP-NOW to synchronize multiple decorations.

Conclusion

This motion-activated ghost is a fun and engaging Halloween decoration that delights trick-or-treaters. With simple materials and basic electronics, you can create a memorable spooky experience.

Leave a Reply

Your email address will not be published. Required fields are marked *