Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano-Controlled Audio Player with Interactive LED Effects

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Controlled Audio Player with Interactive LED Effects

Circuit Documentation

Summary

The circuit in question is designed to integrate an Arduino Nano with a DFPlayer Mini MP3 module, a WS2812 RGB LED strip, and various other components including resistors, a pushbutton, a USB female port, an electrolytic capacitor, a speaker, and a 3.5mm audio jack. The Arduino Nano serves as the central microcontroller, running embedded code to control the LED strip and handle audio playback through the DFPlayer Mini. The circuit is powered by a lithium battery with a charging circuit and includes a toggle switch for power control. The pushbutton is used to trigger audio playback, and the resistors are used for signal conditioning and current limiting.

Component List

Arduino Nano

DFPlayer Mini

Resistor (1k Ohms)

Resistor (330 Ohms)

3.5mm Audio Jack 3 Pin

USB Female Port

Pushbutton

Electrolytic Capacitor (1uF)

Speaker

TRRS 3.5mm Jack Breakout

WS2812 RGB LED Strip

Lithium Battery with Charging Circuit (3.7V)

Toggle Switch

Wiring Details

Arduino Nano

DFPlayer Mini

Resistor (1k Ohms)

Resistor (330 Ohms)

3.5mm Audio Jack 3 Pin

USB Female Port

Pushbutton

Electrolytic Capacitor (1uF)

Speaker

TRRS 3.5mm Jack Breakout

WS2812 RGB LED Strip

Lithium Battery with Charging Circuit (3.7V)

Toggle Switch

Documented Code

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

// Pin Definitions
#define LED_PIN    19   // Pin for WS2812 (FastLED) Data line
#define NUM_LEDS   12   // Number of WS2812 (FastLED) LEDs
#define BRIGHTNESS 255  // LED brightness (0-255)
#define BUTTON_PIN 7    // Pin for the button

// FastLED Object Setup
CRGB leds[NUM_LEDS];    // Array to hold LED colors

// DFPlayer Mini setup
SoftwareSerial mySoftwareSerial(10, 11);  // RX (Pin 10), TX (Pin 11)
DFRobotDFPlayerMini myDFPlayer;

// Variables for controlling the coin lights
int coinCyclePosition = 0;
long coinTimer = 0;
static int coinTimeLimit = 780;
bool coinOneArray[] = {0, 1, 1, 0, 1, 1, 1, 1};
bool coinTwoArray[] = {1, 1, 0, 1, 1, 0, 1, 0};
bool coinThreeArray[] = {1, 1, 1, 0, 0, 0, 0, 1};

// Variables for controlling the sound
long breathingTimer = -4600;
static int breathingTimeLimit = 4600;
bool isRandomPlaying = false;   // To track if random audio is playing
bool buttonPressed = false;     // To track button press for debounce

void setup() {
  Serial.begin(9600);

  // Initialize DFPlayer Mini
  mySoftwareSerial.begin(9600);
  if (!myDFPlayer.begin(mySoftwareSerial)) {
    Serial.println("DFPlayer Mini not detected.");
    while (true);
  }

  // Set DFPlayer volume (0 to 30)
  myDFPlayer.volume(20);

  // Initialize FastLED
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);

  // Initialize the button
  pinMode(BUTTON_PIN, INPUT_PULLUP);  // Button pin with internal pull-up

  // Light start-up sequence
  lightStartUp();

  delay(1000);

  // Play startup sound
  myDFPlayer.play(2);  // Play sound file 2 (assuming the file is named 0002.mp3 on the SD card)
  delay(2700);

  // Set initial state of some LEDs for the coin effect
  leds[0] = CRGB::Red;
  leds[4] = CRGB::Green;
  leds[5] = CRGB::Red;
  leds[6] = CRGB::Red;
  leds[7] = CRGB::Green;
  leds[8] = CRGB::Green;
  leds[9] = CRGB::Red;
  leds[10] = CRGB::Green;
  leds[11] = CRGB::Green;
  FastLED.show();
}

void lightStartUp() {
  // Flash LEDs in sequence as a startup animation
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Red;
    FastLED.show();
    delay(100);
    leds[i] = CRGB::Black;
    FastLED.show();
    delay(100);
  }
}

void loop() {
  // Check if the button is pressed and no sound is playing
  if (digitalRead(BUTTON_PIN) == LOW && !buttonPressed && !isRandomPlaying) {
    buttonPressed = true;  // Debounce to avoid multiple triggers
    playRandomSound();
  }

  // If random sound is not playing, handle breathing sound
  if (!isRandomPlaying && millis() - breathingTimer > breathingTimeLimit) {
    breathingSound();
  }

  // Coin light cycle logic
  if (millis() - coinTimer > coinTimeLimit) {
    coinLight();
  }

  // Check if random sound has finished playing
  checkForTrackEnd();

  // Reset button press after it is released
  if (digitalRead(BUTTON_PIN) == HIGH) {
    buttonPressed = false;
  }
}

void breathingSound() {
  Serial.println("Playing...Breathing sound");
  myDFPlayer.play(1);  // Play breathing sound file 1 (assuming the file is named 0001.mp3 on the SD card)