Fun things for kids: How to make led projects with Arduino and sound
Hello!!!
Welcome to Makersgeneration, your go-to destination for STEAM projects for kids and where scientific activities are being taught.
For today's project, we will be working on a very cool Arduino LED project known as LED Audio Visualizer. This system listens to music played, converts the sound to pulse, and then synchronizes it with series of connected LEDs. Sounds really Cool right!!!?
Keep reading, let's learn how to make this together!
LED audio visualizer
An LED audio visualizer is a device or system that uses LEDs (Light-Emitting Diodes) to create visual patterns and effects that are synchronized with audio or music. The visualizer analyzes the audio input, such as the amplitude or frequency of the sound, and translates it into visual representations displayed through the LEDs.
LED audio visualizers can be implemented using various platforms and programming languages. Popular options include Arduino, Raspberry Pi, or dedicated microcontrollers that support LED control libraries.
LED audio visualizers can range from simple DIY projects to more complex commercial products, with varying levels of sophistication and capabilities.
Project requirements
Arduino Nano/Uno board
Compatible USB cable
Breadboard
2 red LEDs
3 yellow LEDs
2 green LEDs
220 ohms resistors - 7
10k ohms resistors - 2
Jumper wires
3.5mm headphone jack (or an old earpiece)
Building the circuit
Let's put together our circuit following the steps below:
Step 1
Assemble your LEDs and connect them to your Arduino via the 220 ohms resistors (Resistors are used to reduce the 5v going from Arduino to LED which can damage the LEDs).
The longer legs of each LED are connected to pins D2 - D8 of Arduino accordingly via resistors.
Step 2
Take an old headphone you no longer use and cut off the part with the earpiece.
You should see three wires - One wire is for Ground, while the other two are for the Left (L) and the Right (R) earpieces.
If the colors of the wires are Red, Blue, and Brown - the Red and Blue are for the earpieces while the Brown wire is Ground
Step 3
Join the L and R wires together and attach them to a jumper cable for easy connection. Similarly, attach the Ground wire with a jumper cable.
Headphone wires are attached to jumper cables for easy connection.
Step 4
Now, let's add a filter circuit to enable us to get good readings from our music source (a phone in this case).
This circuit consists of two 10K resistors and a 10uF capacitor connected as shown below:
Arduino code for audio LED visualizer
// Initialize pins and variables
int led[7] = {2, 3, 4, 5, 6, 7, 8}; // LED pins
int audioJack = A0; // Audio jack L/R
int audioRead, i // Music values read, variable for i
void setup(){
Serial.begin(9600); // Initialize Serial communication
for (i=0; i<7; i++){ // Set pins D2 - D8 to Output
pinMode(led[i], OUTPUT);
}
}
void loop(){
// Read values from audio jack
audioRead = analogRead(audioJack);
// Print audioRead values on Serial monitor
Serial.println(audioRead);
// Sync audio values with number of LEDs using "mapint" function.
// 500 = music off and 650 = my music is loud.
// Use "audioRead" data printed on your serial monitor to set yours.
// 0, 7 = number of LEDs
int audioReadMap = mapint(audioRead, 500, 650, 0, 7);
// When there's no music, turn off all LED
if (audioReadMap == 0){
for (i=0; i<7; i++){
digitalWrite(le[i], LOW);
}
}
// Turn on/off LED according to music volume
else{
for (i=0; i < audioReadMap; i++){
digitalWrite(led[i], HIHG);
}
for (i=i; i<7; i++){
digitalWrite(led[i], LOW);
}
}
}
// Function to map(scale) "audioRead" values with number of LEDs
int mapint(int x, int in_min, int in_max, int out_min, int out_max){
return(x-in_min)*(out_max - out_min) / (in_max - in_min) + out_min;
}
To run the code:
Open the Arduino IDE, copy the code above, and paste it into the IDE's open window.
Navigate to Tools >> Select Board type (Arduino Uno or Nano) >> Select the correct Port assigned to your board.
How it works
This project uses an headphone jack hokked up to a music play to pick up signals. This signals is then converted to pulses which can be processed by an Arduino board through analog A0 in this case. The Arduino then uses these information to turn on/off LEDs according to the beat or volume of the music.
Demo video
Once your code is successfully uploaded to the Arduino, plug the headphone jack into your music device and see how the LED reacts!!
As can be seen in the video above - When the music starts playing on the phone, the LEDs light up according to the volume of the music, and when the music is paused the LEDs go off.
Alright!! That was it for today. Hope you learnt something.
Don't forget to check back for more cool RGB LED projects like this one.
Online summer camp and summer camps in Takoma Park Maryland
You and your children are looking for nice activities to have fun and learn new things and skills. Come join us starting in May and this summer for more online coding courses for kids such as:
Python coding for kids and teens
Coding for elementary school students
Make video games
Electronics
Digital modeling (Create cars, rockets, rings, etc) for 3D printing and much more with the following link: Online summer camp
And the STEM summer camp in Maryland for your kids is organized in Takoma Park Maryland nearby Washington DC to have fun and learn more about robotics, coding, droning, and more. Check the link right here:
Other cute things to make and hand-crafts for kids
If you are looking for more ideas for easy STEM activities to do at home, take a look at these other activities:
Follow us on Facebook and the newsletter for weekly activities
If you are looking for daily STEM ideas for kids, don't forget to subscribe to the newsletter (at the bottom of the page) and the Facebook group if you want more weekly STEM-related activities for education. Such as electronics, 3D printing, chemistry, coding, robotics, and more. If you want to learn how to make a robot at home, learn how to code, Learn how to make video games, and how to use electronics, please join the newsletter and the Facebook group (Create and build and learn STEM with fun projects).
Come back for more STEM-related articles for kids and adults. ;-)
We can be reached at: contact@makersgeneration.net if any questions.
See you on soon.
Comments