Embedded Systems: Laboratory Manual
Embedded Systems: Laboratory Manual
(EL-419)
LABORATORY MANUAL
____________________________________________________________________________________________________________________________________________________________
To demonstrate sound detection using Arduino with bar graph and clap
switch
Learning Objective:
1. Interfacing of sound sensor with Arduino
2. Designing Clap Switch using Sound Detector and Arduino
3. Designing Bar Graph using Sound Detector and Arduino
Equipment Required:
1. Personal Computer
2. Arduino
Background:
Sound Detector:
The Sparkfun Sound Detector is a small and very easy to use audio sensing board with three different
outputs. The sound detector not only provides an audio output, but also a binary indication of the
presence of sound, and an analog representation of its amplitude. The 3 outputs are simultaneous and
independent, so you can use as many or as few as you want at once. The envelope output allows you to
easily read amplitude of sound by simply measuring the analog voltage.
Gain can be adjusted with a through-hole resistor, to change the threshold of the binary (gate) output pin
as well. Each of the three output signals is present on the .1" header at the edge of the board. They are
active simultaneously. If you aren't using one in your particular application, simply leave that pin
disconnected.
Page 2 of 10
Lab Manual of ‘Embedded Systems Lab’
The gain of the sound sensor can be adjusted by connecting the external resistor at the terminals of the
R17 on sound detector board.
Page 3 of 10
Lab Manual of ‘Embedded Systems Lab’
Page 4 of 10
Lab Manual of ‘Embedded Systems Lab’
We're going to start plotting...values! Arduino comes with a cool tool called the Serial Plotter. It
can give you visualizations of variables in real-time. This is super useful for visualizing data,
troubleshooting your code, and visualizing your variables as waveforms.
When you call Serial.println(value), the Serial Plotter will put that variable on the plot. The Y-Axis
of the plot auto-resizes.
If you want to plot multiple variables, you'll need a Serial.println(value) call for each of the
variables, separated by a Serial.print(" ") or Serial.print("\t"):
Serial.print(variable1);
Serial.print(" ");
Serial.println(variable2);
Page 5 of 10
Lab Manual of ‘Embedded Systems Lab’
Lab Exercise
Task # 1: Connect the sound detector according to the circuit diagram shown above in
Figure 2. Read the outputs of sound sensor and plot these outputs on serial plotter.
(Taking one output at a time). Take the snapshots of the output to attach with the lab
manual.
Task # 2: Clap Circuit
Write the Arduino code and design the circuit which can activate the three LED’s
connected with Arduino Digital Pins.
Code:
bool state=HIGH;
void setup()
{
pinMode(A3,INPUT);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(8,OUTPUT);
Serial.begin(9600);
}
void loop()
{
float value;
value=analogRead(A3);
Serial.println(value);
value=(value/1024)*5;
Serial.println(value);
if(value>3.3)
{
digitalWrite(13,state);
digitalWrite(12,state);
digitalWrite(8,state);
state=!state;
}
}
Circuit:
Page 6 of 10
Lab Manual of ‘Embedded Systems Lab’
void loop()
{
float value;
value=analogRead(A3);
Serial.println(value);
value=(value/1024)*5;
Serial.println(value);
if(value>2.5)
{
digitalWrite(13,HIGH);
}
if(value>2.81)
{
digitalWrite(12,HIGH);
}
if(value>3.12)
Page 7 of 10
Lab Manual of ‘Embedded Systems Lab’
{
digitalWrite(11,HIGH);
}
if(value>3.43)
{
digitalWrite(10,HIGH);
}
if(value>3.74)
{
digitalWrite(9,HIGH);
}
if(value>4.05)
{
digitalWrite(8,HIGH);
}
if(value>4.36)
{
digitalWrite(7,HIGH);
}
if(value>=4.97)
{
digitalWrite(6,HIGH);
}
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
}
Circuit:
Page 8 of 10
Lab Manual of ‘Embedded Systems Lab’
Page 9 of 10
Lab Manual of ‘Embedded Systems Lab’
To demonstrate
the elementary
skills to conduct
experiments
With minor With major Partially performs Does not
using embedded Correctly mistakes mistakes the tasks work
C and python performs the tasks performs the performs the
2 programming tasks tasks
techniques to
interface various
sensors and
actuators with
microcontrollers
Page 10 of 10