Arduino Nano-Controlled Sound-Activated LED Light with Phase-Dependent Audio Feedback
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary of the Circuit
This circuit is designed to control a high-current Power LED with an Arduino Nano microcontroller, responding to sound input detected by a Sound Detector module. The Arduino Nano also interfaces with an Adafruit Audio FX Mini Sound Board to play different sounds based on the detected sound's timing, which is interpreted as different phases of operation. A TIP120 Darlington Transistor is used to switch the high-current LED, and a resistor is included to limit the base current of the transistor. The circuit is powered by a 12V power supply, which directly powers the LED and the Adafruit Audio FX Mini Sound Board, while the Arduino Nano is powered via its 3V3 pin. The Loudspeaker is driven by the Adafruit Audio FX Mini Sound Board to output audio signals.
Component List
Arduino Nano
- Microcontroller board based on the ATmega328P
- Provides GPIO pins for interfacing with other components
- Powered by 3.3V from the circuit
Sound Detector
- Detects sound levels and provides digital (GATE) and analog (ENVELOPE) outputs
- Powered by 3.3V from the Arduino Nano
TIP120 Hi-Current Darlington Transistor
- Used to switch the high-current LED on and off
- Controlled by the Arduino Nano through a resistor
Power LED 12V 10W 0.8-0.9A
- High-power LED for lighting applications
- Powered directly by the 12V power supply
Resistor (200 Ohms)
- Limits the base current of the TIP120 transistor
12V Power Supply
- Provides power to the circuit
Adafruit Audio FX Mini Sound Board
- Stores and plays audio files
- Interfaces with the Arduino Nano for control signals
- Powered directly by the 12V power supply
Loudspeaker
- Outputs audio signals from the Adafruit Audio FX Mini Sound Board
Wiring Details
Arduino Nano
D6connected to the base of the TIP120 transistor through a 200 Ohm resistorD2connected to the GATE pin of the Sound DetectorA0connected to the ENVELOPE pin of the Sound DetectorD7-D12connected to various GPIO pins on the Adafruit Audio FX Mini Sound Board for sound control3V3provides power to the Sound Detector and the Adafruit Audio FX Mini Sound BoardGNDconnected to the common ground of the circuit
Sound Detector
VCCconnected to 3.3V from the Arduino NanoGNDconnected to the common ground of the circuitGATEconnected toD2on the Arduino NanoENVELOPEconnected toA0on the Arduino Nano
TIP120 Hi-Current Darlington Transistor
BASEconnected toD6on the Arduino Nano through a 200 Ohm resistorCOLLECTORconnected to the negative (-) pin of the Power LEDEMITTERconnected to the common ground of the circuit
Power LED 12V 10W 0.8-0.9A
+connected to the positive (+) terminal of the 12V power supply-connected to the collector of the TIP120 transistor
Resistor (200 Ohms)
- One end connected to
D6on the Arduino Nano - The other end connected to the base of the TIP120 transistor
12V Power Supply
+connected to the positive (+) pin of the Power LED and the VIN pin of the Adafruit Audio FX Mini Sound Board-connected to the common ground of the circuit
Adafruit Audio FX Mini Sound Board
VINconnected to the positive (+) terminal of the 12V power supplyGNDconnected to the common ground of the circuitGPIO0_1toGPIO0_6connected toD7-D12on the Arduino Nano for sound controlR_ACconnected to one pin of the Loudspeaker
Loudspeaker
- One pin connected to
R_ACon the Adafruit Audio FX Mini Sound Board - The other pin connected to the common ground of the circuit
Documented Code
// Define pins for each phase
int lightPin = 6; // Single light pin
int soundPinOnPhase1 = 12; // Sound when light turns on in Phase 1
int soundPinOffPhase1 = 11; // Sound when light turns off in Phase 1
int soundPinOnPhase2 = 10; // Sound when light turns on in Phase 2
int soundPinOffPhase2 = 9; // Sound when light turns off in Phase 2
int soundPinOnPhase3 = 8; // Sound when light turns on in Phase 3
int soundPinOffPhase3 = 7; // Sound when light turns off in Phase 3
int soundSensorPin = 0;
int threshold = 100; // Clap detection threshold
unsigned long lastClapTime = 0; // Time of last clap
int currentPhase = 0; // Track current phase
bool lightState = false; // Light state (on or off)
// Setup pins in setup()
void setup() {
pinMode(lightPin, OUTPUT); // Set light pin
pinMode(soundPinOnPhase1, OUTPUT); // Set sound pin for Phase 1
pinMode(soundPinOffPhase1, OUTPUT);
pinMode(soundPinOnPhase2, OUTPUT); // Set sound pin for Phase 2
pinMode(soundPinOffPhase2, OUTPUT);
pinMode(soundPinOnPhase3, OUTPUT); // Set sound pin for Phase 3
pinMode(soundPinOffPhase3, OUTPUT);
digitalWrite(soundPinOnPhase1, HIGH); // Start sound pins HIGH (off)
digitalWrite(soundPinOffPhase1, HIGH);
digitalWrite(soundPinOnPhase2, HIGH);
digitalWrite(soundPinOffPhase2, HIGH);
digitalWrite(soundPinOnPhase3, HIGH);
digitalWrite(soundPinOffPhase3, HIGH);
}
void loop() {
// Detect clap
int sensorValue = analogRead(soundSensorPin);
if (sensorValue > threshold) {
unsigned long currentTime = millis();
unsigned long timeBetweenClaps = currentTime - lastClapTime;
// Determine the phase based on time between claps
if (timeBetweenClaps > 10000) {
currentPhase = 1; // Phase 1 for > 10 seconds
} else if (timeBetweenClaps > 5000) {
currentPhase = 2; // Phase 2 for 5-10 seconds
} else {
currentPhase = 3; // Phase 3 for < 5 seconds
}
// Toggle light and trigger sound based on the current phase
if (!lightState) {
turnOnLightWithSound();
} else {
turnOffLightWithSound();
}
lastClapTime = currentTime; // Update clap time
delay(300); // Debounce delay
}
}
// Function to turn on light and trigger corresponding sound
void turnOnLightWithSound() {
digitalWrite(lightPin, HIGH); // Turn on light
if (currentPhase == 1) {
digitalWrite(soundPinOnPhase1, LOW); // Play sound for Phase 1
delay(500);
digitalWrite(soundPinOnPhase1, HIGH); // Stop sound
} else if (currentPhase == 2) {
digitalWrite(soundPinOnPhase2, LOW); // Play sound for Phase 2
delay(500);
digitalWrite(soundPinOnPhase2, HIGH); // Stop sound
} else if (currentPhase == 3) {
digitalWrite(soundPinOnPhase3, LOW); // Play sound for Phase 3
delay(500);
digitalWrite(soundPinOnPhase3, HIGH); // Stop sound
}
lightState = true; // Update light state
}
// Function to turn off light and trigger corresponding sound
void turnOffLightWithSound() {
digitalWrite(lightPin, LOW); // Turn off light
if (currentPhase == 1) {
digitalWrite(soundPinOffPhase1, LOW); // Play sound for Phase 1
delay(500);
digitalWrite(soundPinOffPhase1, HIGH); // Stop sound
} else if (currentPhase == 2) {
digitalWrite(soundPinOffPhase2, LOW); // Play sound for Phase 2
delay(500);
digitalWrite(soundPinOffPhase2, HIGH); // Stop sound
} else if (currentPhase == 3) {
digitalWrite(soundPinOffPhase3, LOW); // Play sound for Phase 3
delay(500);
digitalWrite(soundPinOffPhase3, HIGH); // Stop sound
}
lightState = false; // Update light state
}
This code controls the lighting and sound effects of the circuit based on the detection of claps. The lightPin controls the TIP120 transistor to switch the Power LED on and off. The soundPinOnPhaseX and soundPinOffPhaseX pins control the Adafruit Audio FX Mini Sound Board to play sounds corresponding to the light being turned on or off in different phases. The