Welcome to the Lights, Music, Code project!
For the supplies you'll need, check out Video 1!
For the software you'll need, check out Video 2!
To assemble the components, check out Video 3!
And for the code you need, see below!
To upload this code to your Arduino, open the Arduino app and create a new file (aka, sketch). Copy and paste the below into the new sketch (removing the basic sketch code). Then click the checkmark on the sketch toolbar to verify the code is solid, and click the arrow pointing to the right to upload. Play that funky music and enjoy!
// Lights, Music, Code!
// http://a.co/a5NY2FB
int input = A0; // Pin for Arduino input/Sensor Analog Output - AO
int threshold = 800; // Minimum value to light up LEDs
int sensorvalue = 0; // Start with a sensor reading of zero
// This sets up digital pins 3, 4, and 5 of the Arduino to control the LEDs
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
// This loop function reads the sensor output and controls the lights!
void loop() {
sensorvalue = analogRead(input); // Read the analog value from the sensor
//Compare the analog value we read with threshold
// If it's above the threshold, turn the LEDs on, if not turn them off
if (sensorvalue >= threshold) {
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
}
else {
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
}
To upload this code to your Arduino, open the Arduino app and create a new file (aka, sketch). Copy and paste the below into the new sketch (removing the basic sketch code). Then click the checkmark on the sketch toolbar to verify the code is solid, and click the arrow pointing to the right to upload. Play that funky music and enjoy!
// Lights, Music, Code!
// http://a.co/a5NY2FB
int input = A0; // Pin for Arduino input/Sensor Analog Output - AO
int threshold = 800; // Minimum value to light up LEDs
int sensorvalue = 0; // Start with a sensor reading of zero
// This sets up digital pins 3, 4, and 5 of the Arduino to control the LEDs
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
// This loop function reads the sensor output and controls the lights!
void loop() {
sensorvalue = analogRead(input); // Read the analog value from the sensor
//Compare the analog value we read with threshold
// If it's above the threshold, turn the LEDs on, if not turn them off
if (sensorvalue >= threshold) {
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
}
else {
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
}