Arduino LED Project
Oscar Macdonald
The Project:
The
Arduino uses a row of 8 LEDs that will turn on or off every 10 milliseconds depending on the
amplitude (loudness) of an audio signal, which is detected using an
Arduino compatible microphone module. The microphone sends a voltage between 0 and 5 to the Arduino, which converts the voltage into a number between 0 and 1023. The 8 LEDs each represent a Byte of
Binary data, and the total combination of possible on/off states of the LEDs
result in a total of 255 unique frequencies (any amplitude greater than 255 will result in all lights being on). This is different from other
projects that people have done; some people choose to make each light turn on
as the audio becomes louder. I chose the ‘binary’ representation because it is
an interesting way to show how audio can be ‘recorded’ onto a computer using
binary.
![]() |
| finished project. |
![]() |
| Fritzing Diagram |
![]() |
| Schematic |
In the above video, the microphone is detecting noise (tapping the microphone) and the LEDs are outputting.
In the above video, I used an alternate code (not part of this project) that shows the increase in noise by turning on the lights in sequence. Also shows a serial output from the arduino, that shows the microphone detecting noise.
C Code:
/* Code written by Oscar Macdonald
* Initial code adapted from Amanda Ghassaei (http://www.instructables.com/id/Arduino-Audio-Input/)
* Inspiration from mashendavideo (https://www.youtube.com/watch?v=YMJFigrKXpw)
* Credit:
* Campbell McDowall
* William Smail
* Peter Brook
* 17/03/2016
*
* This arduino sketch uses an Arduino Compatible Microphone Sound Sensor Module
* (Catalogue #:XC4438) from Jaycar Electronics, to receive audio input,
* return an amplitude measurements in volts between 0 - 1023,
* and display the number in binary form on the LEDs on the breadboard.
*/
int A0input;//storage for A0 data
void setup(){
// Each pin represents a different binary digit
pinMode(5, OUTPUT); // 1
pinMode(6, OUTPUT); // 2
pinMode(7, OUTPUT); // 4
pinMode(8, OUTPUT); // 8
pinMode(9, OUTPUT); // 16
pinMode(10, OUTPUT); // 32
pinMode(11, OUTPUT); // 64
pinMode(12, OUTPUT); // 128
Serial.begin (9600); // for testing purposes, allows an arduino to send information back to the computer
}
void loop(){
A0input = analogRead(0);//get new value from A0
Serial.println(A0input);// For testing purposes, sends back an ASCII value (0-1023) that can be easily read
int binary[] = {0, 0, 0, 0, 0, 0, 0, 0}; // array of binary values
int index = 0; // used in the loop for the array
while(A0input > 0) // this loop converts the input to a binary value
{
binary[index++] = A0input % 2;
A0input = A0input / 2;
}
for(int i = sizeof(binary); i > 0; i--)
{
if (binary[i] == 1)
{
digitalWrite(i + 4, HIGH); // turns the light on if the binary value is 1
}
else // binary[i] == 0
{
digitalWrite(i + 4, LOW); // turns the light off if the binary value is 0
}
}
delay(10);
}
Reflection
The idea originally came
from a brainstorming session in the first week of class. Every time I came up
with an idea I would write it down. I decided that an audio input would have
enough complexity to be a sufficient challenge, it could be adapted to include
LEDs in multiple ways, and it would be satisfying to have the Arduino respond
to voice or music.
I conducted some research on
the subject of Arduinos and audio input. The first article I came across was an
Instructables article by amandaghassaei (1). This article was inspiring and the
list of materials was so detailed it made it look like it was an easy project
to build; half the materials came with the original sparkfun kit and the rest
were easy to obtain.
After attempting to recreate
the circuit I realized I was out of my depth; I couldn’t understand the circuit
diagram included on the website, and the images of the breadboard were
unfocused and therefore hard to replicate. I gave up on this approach but my
time wasn’t entirely wasted: I had some new circuit parts and I had learnt
valuable information about audio input and amplifying audio input (without an
amplifier, the audio will output between -2.5 and 2.5 volts, so it needs to be
amplified to sit between 0 and 5).
![]() |
| Photo by amandaghassaei (1)This isn’t art school, we’re not here to take photos out of focus! A shot from directly above would have been more instructive. |
I found a second Arduino
audio tutorial on youtube (2) which looked a lot less complicated and didn’t
require any extra components. After replicating their circuit I tried to get an
audio signal. The audio input wire was loosely touching the 6.5mm audio pin
without a proper socket or join, and there was a lot of interference from other
sources. Touching the audio input wire to the positive pin of the XLR connector
of the microphone. Thanks to Campbell McDowall, I discovered the Arduino
Compatible Microphone Sound Sensor Module that was available for purchase. This
solved both the problem of the complex circuit which would take up valuable
space on the breadboard (1) and the microphone incompatibility with the Arduino
(2).
After creating a circuit
with the module and testing for audio, initially the output of the Arduino
(using serial.println()) was constantly between 50-52. After configuring the
circuit, more research and consultation, I discovered that the potentiometer on
the module had to be configured to the right setting so the audio would be
detected (3). After configuring the potentiometer the serial output began to
show more relatable figures, and there was a change in the output when the
microphone was tested. This output is not as accurate as I would like (the LEDs
do not respond to the human voice in any observable way) but given more time or
other materials this could be changed.
![]() |
| A serial monitor of the analogue output, showing the microphone is working. |
I created a segment of code
which converts the output of the microphone to binary values, and each LED
represents a single binary value, so that any reading between 0 and 255 would
give a binary value. I decided to use this LED output to add originality to my
project and also as a replication of very simple data storage. I realized that
the microphone could only detect the amplitude of the audio, not the frequency,
so I have adjusted the goal of the project to detect amplitude instead.
If I did this project again
I would use a larger breadboard so there was ample room for all the circuit
components, and even to add more LEDs to make a larger range of binary data (to
cover all 1024 different values). I would also have spent more time configuring
the potentiometer so the microphone would detect the right amplitude
(preferably human speech). With a more sensitive / correctly configured
microphone this project could be used for cool projects like tone password
doors: a door that only unlocks when the correct tune is played on a piano.
This would rely on frequency rather than amplitude of audio, which might be
beyond the scope of Arduinos, but there are more tutorials online which seem to
think it is possible.
I would like to acknowledge
Campbell McDowall for his support and advice. I would also like to thank
William Smail and Peter Brook for their assistance with the microphone and
their advice.
References:
3.
https://www.youtube.com/watch?v=aa3F4ALaEok






No comments:
Post a Comment