Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

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

Image 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

  • 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

  • D6 connected to the base of the TIP120 transistor through a 200 Ohm resistor
  • D2 connected to the GATE pin of the Sound Detector
  • A0 connected to the ENVELOPE pin of the Sound Detector
  • D7-D12 connected to various GPIO pins on the Adafruit Audio FX Mini Sound Board for sound control
  • 3V3 provides power to the Sound Detector and the Adafruit Audio FX Mini Sound Board
  • GND connected to the common ground of the circuit

Sound Detector

  • VCC connected to 3.3V from the Arduino Nano
  • GND connected to the common ground of the circuit
  • GATE connected to D2 on the Arduino Nano
  • ENVELOPE connected to A0 on the Arduino Nano

TIP120 Hi-Current Darlington Transistor

  • BASE connected to D6 on the Arduino Nano through a 200 Ohm resistor
  • COLLECTOR connected to the negative (-) pin of the Power LED
  • EMITTER connected 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 D6 on 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

  • VIN connected to the positive (+) terminal of the 12V power supply
  • GND connected to the common ground of the circuit
  • GPIO0_1 to GPIO0_6 connected to D7-D12 on the Arduino Nano for sound control
  • R_AC connected to one pin of the Loudspeaker

Loudspeaker

  • One pin connected to R_AC on 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