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.
D7
connected to PushbuttonD10
connected to DFPlayer Mini TXD11/MOSI
connected to 1k Ohm ResistorVIN
connected to power supply net (USB Female VCC, Toggle Switch COM, WS2812 5V, DFPlayer Mini VCC, Electrolytic Capacitor +)GND
connected to ground net (Lithium Battery V-, Pushbutton Pin 1, USB Female GND, WS2812 GND, DFPlayer Mini GND, Electrolytic Capacitor -)A5
connected to 330 Ohm ResistorVCC
connected to power supply netTX
connected to Arduino Nano D10RX
connected to 1k Ohm ResistorGND
connected to ground netDAC_R
connected to TRRS 3.5mm Jack Breakout Ring1DAC_L
connected to TRRS 3.5mm Jack Breakout TipL
connected to Speaker +R
connected to Speaker +GND
connected to Speaker -VCC
connected to power supply netGND
connected to ground netPin 2
connected to Arduino Nano D7Pin 1
connected to ground net+
connected to power supply net-
connected to ground net+
connected to both 3.5mm Audio Jack L and R-
connected to 3.5mm Audio Jack GNDRing1
connected to DFPlayer Mini DAC_RTip
connected to DFPlayer Mini DAC_LRing2
connected to DFPlayer Mini GND5V
connected to power supply netGND
connected to ground netDIN
connected to 330 Ohm ResistorV+
connected to Toggle Switch L1V-
connected to ground netL1
connected to Lithium Battery V+COM
connected to power supply net#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)