Step 1: Making The LED Lights Dance To Your Music: Headphone
Step 1: Making The LED Lights Dance To Your Music: Headphone
Objective here is to use the A/D converter on Arduino to read input sound and
light up a set LEDs to reflect the level of the sounds volume. The LEDs are
controlled from Digital pins 3, 4, 5,6. They are turned on based on what the
level of input is from the Analog 0 pin, which is connected to theHEADPHONE
jack.
Parts:
1x Arduino
4x LEDs
4x 390 ohm resistors
1x 10k trimpot
1xHEADPHONE jack
1x 10uF Capacitor
//LED LIGHT dance
#define soundpin 8 // reads the power from theLIGHT sensor from
Analog input 0
#define LED1 3 // 4 Leds LED's on Digital output pins 3,4,5,6
#define LED2 4
#define LED3 5
#define LED4 6
int sound;
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
// Provide power by using the analog inputs as normal digital pins.
pinMode(soundpin, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
}
void loop()
{
sound=analogRead(soundpin); // this samples the sound constantly
if((sound)>200)
{
digitalWrite(LED1,HIGH); // set the LEDs on
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
}
else if((sound)>150)
{
digitalWrite(LED1,HIGH); // set the LED on
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,LOW); // set the LED off
}
else if(sound>100)
{
digitalWrite(LED1,HIGH); // set the LED on
digitalWrite(LED2,HIGH);
digitalWrite(LED3,LOW); // set the LED off
digitalWrite(LED4,LOW);
}
else if(sound>50)
{
digitalWrite(LED1,HIGH); // set the LED on
digitalWrite(LED2,LOW); // set the LED off
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
}
else
{
digitalWrite(LED1,LOW); // set the LEDs off
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
}
Serial.println(soundpin); //output for serial monitor
delay(25); // And a shot delay
}
Step 2: Interfacing the relay modules to the Arduino
The default state of the relay when the power is off for COMM
(power) to be connected to NC (normally closed), this is the
equivalent of setting the 4 Relay boards IN pin to HIGH (has +5v
sent to it) It is a safety feature to notuse the NC connector in-case
you Arduino looses power it will automatically turns off all the
devices connected to the relay. When you have something
connected to the relays NO (Normally Open) connector and you set
the corresponding IN pin to LOW (0v), power will flow in from the
COMM connector and out of the NO connectorpowering your device..