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

Arduino Nano-Controlled Sound-Activated LED Light with Phase-Dependent Audio Feedback

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Controlled Sound-Activated LED Light with Phase-Dependent Audio Feedback

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

Sound Detector

TIP120 Hi-Current Darlington Transistor

Power LED 12V 10W 0.8-0.9A

Resistor (200 Ohms)

12V Power Supply

Adafruit Audio FX Mini Sound Board

Loudspeaker

Wiring Details

Arduino Nano

Sound Detector

TIP120 Hi-Current Darlington Transistor

Power LED 12V 10W 0.8-0.9A

Resistor (200 Ohms)

12V Power Supply

Adafruit Audio FX Mini Sound Board

Loudspeaker

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