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.
D6
connected to the base of the TIP120 transistor through a 200 Ohm resistorD2
connected to the GATE pin of the Sound DetectorA0
connected to the ENVELOPE pin of the Sound DetectorD7-D12
connected to various GPIO pins on the Adafruit Audio FX Mini Sound Board for sound control3V3
provides power to the Sound Detector and the Adafruit Audio FX Mini Sound BoardGND
connected to the common ground of the circuitVCC
connected to 3.3V from the Arduino NanoGND
connected to the common ground of the circuitGATE
connected to D2
on the Arduino NanoENVELOPE
connected to A0
on the Arduino NanoBASE
connected to D6
on the Arduino Nano through a 200 Ohm resistorCOLLECTOR
connected to the negative (-) pin of the Power LEDEMITTER
connected to the common ground of the circuit+
connected to the positive (+) terminal of the 12V power supply-
connected to the collector of the TIP120 transistorD6
on the Arduino Nano+
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 circuitVIN
connected to the positive (+) terminal of the 12V power supplyGND
connected to the common ground of the circuitGPIO0_1
to GPIO0_6
connected to D7-D12
on the Arduino Nano for sound controlR_AC
connected to one pin of the LoudspeakerR_AC
on the Adafruit Audio FX Mini Sound Board// 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