PUMKIN LIGHITING WITH SOUND EFFECT

by bijoybarua01 in Circuits > Arduino

101 Views, 0 Favorites, 0 Comments

PUMKIN LIGHITING WITH SOUND EFFECT

20251012_110927(1)[1].jpg
Halloween Pumking #halloween #pumpkin #arduino #3dprinting #pumpkinseason #halloweendecor



This Prototype Pumkin Decorating, when Motion Detect its, play different type sound with RGB Led strip Effect.


Supplies

sd card.jpg
speaker.jpg
nano.jpg
pir sensor.jpg
cable.jpg
adepter.jpg
mist maker.jpg
led strip.jpg
pumkin.jpg

Circuit

Halloween CKT (1).png
  1. Motion Sensor Pin D2
  2. DF player Busy pin Arduino D4
  3. Led Pin D6
  4. Rx D11
  5. TX D10
  6. VIN (7-12VDC)

VCC-5v

GND -GND

Google Drive

SD Card Setup

audio.PNG
sd formet.PNG
  1. Formet SD Card : FAT32
  2. all audio file rename number serial

Arduino Code

arduino code.PNG

Arduino Code :

  1. Motion Sensor Pin D2
  2. DF player Busy pin Arduino D4
  3. Led Pin D6



  1. Code Explain:
#define NUM_LEDS 30 .........Number of Led in strip
SoftwareSerial mySerial(10, 11); // RX, TX for DFPlayer.....Rx pin connect 1K resistor , Tx pin connect Rx
int totalTracks = 32;......select how many audio file in sd card
uint8_t userBrightness = 150; (100-250) when You change the value led strip light brightness control
dfplayer.volume(20); (10-30) when volume 25/30 increase some time arduino not response because of power issues.

#include <SoftwareSerial.h>

#include <DFRobotDFPlayerMini.h>

#include <Adafruit_NeoPixel.h>

#define PIR_PIN 2

#define BUSY_PIN 4

#define LED_PIN 6

#define NUM_LEDS 30

SoftwareSerial mySerial(10, 11); // RX, TX for DFPlayer

DFRobotDFPlayerMini dfplayer;

Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

// Flags

volatile bool motionDetectedISR = false;

bool pirReadyForNext = true;

bool isPlaying = false;

bool isSleeping = false;

int lastTrack = 0;

int totalTracks = 32;

// LED / effect variables

uint8_t userBrightness = 150;

uint8_t flickerVals[NUM_LEDS];

enum State {IDLE, FADE_IN, PLAYING, FADE_OUT};

State currentState = IDLE;

unsigned long lastEffectUpdate = 0;

const unsigned long effectInterval = 50;

unsigned long lastEffectChange = 0;

const unsigned long effectChangeInterval = 1000;

unsigned long lastActivityTime = 0;

const unsigned long sleepTimeout = 30000; // 30 sec idle = sleep

int currentEffect = 0;

// Fade control

unsigned long fadeStartTime = 0;

const unsigned long fadeDuration = 500;

int fadeTarget = 0;

// Forward declarations

void pirISR();

void playRandomTrack();

void runEffects();

void halloweenEffect();

void warmFlickerEffect();

void runFade();

void goToSleep();

void wakeUpDFPlayer();

uint32_t Wheel(byte WheelPos);

void setup() {

pinMode(PIR_PIN, INPUT);

pinMode(BUSY_PIN, INPUT);

strip.begin();

strip.show();

strip.setBrightness(userBrightness);

for (int i = 0; i < NUM_LEDS; i++) flickerVals[i] = userBrightness / 2;

mySerial.begin(9600);

Serial.begin(115200);

if (!dfplayer.begin(mySerial)) {

Serial.println("DFPlayer not responding!");

while (true);

}

dfplayer.volume(20);

dfplayer.disableLoopAll();

attachInterrupt(digitalPinToInterrupt(PIR_PIN), pirISR, RISING);

Serial.println("Nano-friendly Halloween controller ready!");

}

void loop() {

// Wake if motion detected during sleep

if (isSleeping && digitalRead(PIR_PIN) == HIGH) {

wakeUpDFPlayer();

isSleeping = false;

pirReadyForNext = true;

Serial.println("Woke from sleep!");

}

// PIR one-shot

if (motionDetectedISR && !isSleeping) {

noInterrupts();

motionDetectedISR = false;

interrupts();

if (currentState == IDLE && pirReadyForNext) {

playRandomTrack();

currentState = FADE_IN;

fadeStartTime = millis();

fadeTarget = userBrightness;

lastEffectUpdate = millis();

lastEffectChange = millis();

currentEffect = 0;

pirReadyForNext = false;

lastActivityTime = millis();

}

}

// Reset one-shot when PIR goes LOW

if (!pirReadyForNext && digitalRead(PIR_PIN) == LOW) {

pirReadyForNext = true;

}

// Sleep mode trigger

if (!isSleeping && millis() - lastActivityTime > sleepTimeout && currentState == IDLE) {

goToSleep();

}

// State machine

switch (currentState) {

case FADE_IN:

runFade();

halloweenEffect();

if (millis() - fadeStartTime >= fadeDuration) {

strip.setBrightness(userBrightness);

currentState = PLAYING;

}

break;

case PLAYING:

halloweenEffect();

if (digitalRead(BUSY_PIN) == HIGH) { // Track finished

currentState = FADE_OUT;

fadeStartTime = millis();

lastActivityTime = millis();

}

break;

case FADE_OUT:

runFade();

halloweenEffect();

if (millis() - fadeStartTime >= fadeDuration) {

strip.clear();

strip.show();

currentState = IDLE;

}

break;

case IDLE:

default:

strip.clear();

strip.show();

break;

}

}

// PIR interrupt

void pirISR() {

motionDetectedISR = true;

}

// Random track

void playRandomTrack() {

int track;

do {

track = random(1, totalTracks + 1);

} while (track == lastTrack && totalTracks > 1);

lastTrack = track;

dfplayer.play(track);

Serial.print("Playing Track: ");

Serial.println(track);

}

// Halloween flicker + warm orange/purple tones

void halloweenEffect() {

unsigned long now = millis();

if (now - lastEffectUpdate >= effectInterval) {

lastEffectUpdate = now;

for (int i = 0; i < NUM_LEDS; i++) {

int change = random(-8, 9);

int newVal = flickerVals[i] + change;

newVal = constrain(newVal, userBrightness / 3, userBrightness);

flickerVals[i] = (uint8_t)((flickerVals[i] * 3 + newVal) / 4);

// Mix of orange and purple for Halloween

if (i % 2 == 0)

strip.setPixelColor(i, flickerVals[i], flickerVals[i] / 3, 0); // orange

else

strip.setPixelColor(i, flickerVals[i] / 3, 0, flickerVals[i]); // purple

}

strip.show();

}

}

// Fade transitions

void runFade() {

unsigned long now = millis();

float progress = (float)(now - fadeStartTime) / fadeDuration;

progress = constrain(progress, 0, 1);

if (currentState == FADE_IN) {

strip.setBrightness((int)(progress * fadeTarget));

} else if (currentState == FADE_OUT) {

strip.setBrightness((int)((1.0 - progress) * userBrightness));

}

}

// Sleep and wake functions

void goToSleep() {

Serial.println("Entering sleep mode...");

dfplayer.sleep(); // Put DFPlayer into low power

strip.clear();

strip.show();

isSleeping = true;

}

void wakeUpDFPlayer() {

dfplayer.wakeUp();

dfplayer.volume(20);

Serial.println("DFPlayer awake!");

}

// Color wheel helper

uint32_t Wheel(byte WheelPos) {

WheelPos = 255 - WheelPos;

if (WheelPos < 85) return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);

else if (WheelPos < 170) {

WheelPos -= 85;

return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);

} else {

WheelPos -= 170;

return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);

}

}

Code Upload

20251012_203248.jpg
  1. Install all essential libraries
  2. Compile Code
  3. select port.
  4. upload code


Pumpkin Setup

20251012_110558.jpg
20251011_123657.jpg
20251011_123644[1].jpg

Hold For PIR Sensor

Final Show

20251012_110927(1).jpg
20251012_110607.jpg
Halloween Pumking #halloween #pumpkin #arduino #3dprinting #pumpkinseason #halloweendecor

Troubleshooting

Problem....................... Solution

  1. When external power using arduino on/not turn on: Try to use 5v adapter connect to 5v+ arduino or (7-12) V connect arduino Vcc pin.
  2. Wnen DF player volume (25-30) set its not working; Try to use max 20, if use only 1 power supply
  3. USB connect work fine, when use external power supply not working.

Make sure power supply Vcc- GND connect Properly and try to 3/4-time plug /unplug power cord

4.When led strip brightness 200+ set arduino stuck; try to set led brightness max 200, when only 1 power supply