Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Embedded Systems

(EL-419)

LABORATORY MANUAL

Lab # 03: To demonstrate sound detection using Arduino with


bar graph and clap switch

Student Name: Muneeb Zafar

Roll No: F178390 Group No: 08 Section: BEE8-B

____________________________________________________________________________________________________________________________________________________________

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, CHINIOT-


FAISALABAD
Lab Manual of ‘Embedded Systems Lab’

EXPERIMENT 3 Date Perform: 22/03/2021

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.

Figure 1: Sound Detection Sensor

Page 2 of 10
Lab Manual of ‘Embedded Systems Lab’

Pins Description of Sound Detector:


Pin Function
VCC Connect to 5V on Arduino
GND Connect to GND on Arduino
Produces the analog voltage output directly proportional to the pitch of the sound.
AUDIO
In complete silent it produces the output 2.5V.
Produces the analog voltage output directly proportional to the sound sensed by
ENVELOPE
the sound detector.
Produces the binary output either HIGH or LOW. When there is low sound, it
GATE
produce LOW output, else HIGH.

The gain of the sound sensor can be adjusted by connecting the external resistor at the terminals of the
R17 on sound detector board.

Lowering the gain


It’s most likely that you’ll find the detector to be too sensitive. In testing the board for this write up,
noisy air conditioning and music in the next office were enough to set it off. To make the board less
sensitive, you can lower the preamplifier gain by populating R17 in parallel with R3.

R3 Value R17 Value Arithmetic Gain Gain (dB)


100K - 100 40
100K 100K 50 33
100K 47K 32 30
100K 22K 18 25
100K 10K 9 19
100K 4.7K 4 13
100K 2.2K 2 6

Page 3 of 10
Lab Manual of ‘Embedded Systems Lab’

Raising the Gain:


If you want to make the sound detector more sensitive, so that it will be activated by quieter sounds, you
can use R17 as defined below.

R17 Value Arithmetic Gain Gain (dB)


100K 100 40
220K 220 46
470K 470 53
1Meg 1000 60

Simple Circuit Diagram:


The simple circuit showing the connection between the Arduino and Sound Detector is shown below;

Figure 2: Circuit Connections

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’

Task # 3: Bar Graph


Write the Arduino code and design the circuit which can emulate the bar graph. Connect
the 8 to 10 LED’s with digital pins of Arduino. LED’s should turn ON in proportion to
the sound amplitude sensed by the sensor.
Code:
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(A3, INPUT);
Serial.begin(9600);

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’

EL419 – EMBEDDED SYSTEMS LAB


To enable the students to write effective C and python language programs to interface various sensors and
actuators with microcontrollers by utilizing the modern IT tools. Likewise, enabling students to
understand the role of RTOS in embedded system to schedule tasks, synchronize tasks, manage resources,
and create threads to efficiently solve the engineering problems.
CLO Statement ↓ Exemplary Proficient Developing Beginning Novice

Page 9 of 10
Lab Manual of ‘Embedded Systems Lab’

Score → (5) (4) (3) (2) (1)


Behaves
responsibly Takes ownership Actively works Partially work Needs help from Does not
within team or and Works and participates and participate in others group to work
individually, and actively in group group discussions complete assigned
1 throughout the lab discussions. task
perform the
experiment
safely

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

CLO MARKS OBTAINED


1
2

Lab Engineer Signature: _______________

Page 10 of 10

You might also like