Rachana Jain
Published © LGPL

Spooky Motion-Activated Halloween Pumpkin Using Arduino Nano

Scare your Halloween trick-or-treater with a motion-activated spooky pumpkin! Powered by Arduino Nano, DFPlayer Mini, PIR sensor, and LEDs!

BeginnerFull instructions provided1 hour77
Spooky Motion-Activated Halloween Pumpkin Using Arduino Nano

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
DFPlayer - A Mini MP3 Player
DFRobot DFPlayer - A Mini MP3 Player
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Speaker: 3W, 4 ohms
Speaker: 3W, 4 ohms
×1
5 mm LED: Red
5 mm LED: Red
×1
Abdi Automation BC547 Transistor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Schematic Diagram

Schematic Diagram

Code

Halloween_V0.ino

C/C++
Upload this code to your Arduino Nano
/* 
Code to run DF player Using Arduino NANO for Halloween
Using Soft Serial LIbrary and DFRobotDFPlayerMini Library
The Detection is done Using PIR sensor which Leads to Scary Voices Randomly run which are stored in the SD card in folder named "01"
*/

#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

#define PIR_SENSOR_INPUT 3
#define LED_OUTPUT 2
#define LED_DELAY 300
#define TOTAL_DELAY_REQUIRED 8

// Initialize software serial on pins 10 and 11
SoftwareSerial mySoftwareSerial(10, 11);  // RX, TX
DFRobotDFPlayerMini myDFPlayer;

unsigned int previousTime = 0;
bool boMotionDetected = false;
int soundCounter = 0;
int delayCounter = 0;

void setup() {
  // Serial communication with the module
  mySoftwareSerial.begin(9600);
  pinMode(PIR_SENSOR_INPUT, INPUT);  // declare PIR sensor pin as input pin
  pinMode(LED_OUTPUT, OUTPUT);       // LED Output
  if (myDFPlayer.begin(mySoftwareSerial)) {
    ledON();
    ledOFF();
    myDFPlayer.volume(25);  // Volume 20
  }
}

void loop() {
  if ((digitalRead(PIR_SENSOR_INPUT) == HIGH) && (boMotionDetected == false)) {
    // Ramdomly Run Sacry voices on SD card
    soundCounter = (soundCounter++ % 7) + 1;
    myDFPlayer.play(soundCounter);  // there are total 8 voices in folder 01 of memory card , voices are named 001.mmp3, 002.mp3
    boMotionDetected = true;
    delayCounter = 0;
  }
  ledON();
  ledOFF();
  checkTime();
}

void ledON() {
  if (boMotionDetected == true) {
    digitalWrite(LED_OUTPUT, HIGH);
    delay(LED_DELAY);
  }
}

void ledOFF() {
  if (boMotionDetected == true) {
    digitalWrite(LED_OUTPUT, LOW);
    delay(LED_DELAY);
  }
}

void checkTime() {
  if (boMotionDetected == true) {
    if( delayCounter++ > TOTAL_DELAY_REQUIRED){
      boMotionDetected = false;
    }
  }
}

Credits

Rachana Jain
11 projects • 8 followers
I'm an avid Arduino and electronics enthusiast with a passion for tinkering, experimenting, and bringing innovative ideas to life.
Contact

Comments

Please log in or sign up to comment.