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)
- 220Ω resistors (for LEDs)
- Servo motor (SG90, optional)
- 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 |
TX
Digital Pin 11
DFPlayer Mini |
RX
Digital Pin 10 (via 1kΩ)
DFPlayer Mini |
SPK+
Speaker (+)
DFPlayer Mini |
SPK-
Speaker (-)
LEDs (parallel) |
Anodes
Digital Pin 9 (via 220Ω)
Servo |
Signal
Digital Pin 3
表
Arduino Code
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include <Servo.h>
SoftwareSerial mySoftwareSerial(10, 11);
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;
bool isActive = false;
const int ghostMoan = 1;
const int spookyLaugh = 2;
void setup() {
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
ghostServo.attach(servoPin);
ghostServo.write(90);
mySoftwareSerial.begin(9600);
if (!myDFPlayer.begin(mySoftwareSerial)) {
while (true);
}
myDFPlayer.volume(25);
delay(60000);
}
void activateGhost() {
isActive = true;
lastTriggerTime = millis();
digitalWrite(ledPin, HIGH);
int randomSound = random(1, 3);
myDFPlayer.play(randomSound);
for (int i = 0; i < 3; i++) {
ghostServo.write(60);
delay(150);
ghostServo.write(120);
delay(150);
}
ghostServo.write(90);
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);
}
void loop() {
bool motionDetected = digitalRead(pirPin) == HIGH;
if (motionDetected && !isActive) {
activateGhost();
}
if (isActive && (millis() - lastTriggerTime > effectDuration)) {
deactivateGhost();
}
delay(50);
}
Ghost Construction
Frame
- Use wire hanger or PVC pipe to create a frame about 2-3 feet tall
- Mount servo motor at the top if using moving ghost
- Attach LEDs at eye positions
- Position PIR sensor at chest height facing forward
Costume
- Drape white fabric (old sheet or cheesecloth) over the frame
- Cut eye holes or use transparent material over LEDs
- Drape the fabric to create a ghost shape
- Secure with tape or wire ties
Installation Steps
- Assemble electronics on breadboard and test
- Load sound files to microSD card
- Build ghost frame and attach servo
- Mount PIR, LEDs, and speaker to frame
- Drape fabric over frame
- Connect battery or USB power
- Walk in front to trigger the ghost
Project Extensions
- Use WS2812B addressable LEDs for color-changing effects
- Add a small fog machine for an eerie effect
- Use multiple PIR sensors to track movement across yard
- Add Bluetooth to trigger ghost from phone
- 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.