in this tutorial I'm going to show you
how you can use the sound sensor
to show audio on the serial plotter
for this tutorial you'll need an Arduino
a sound sensor and 3 jumper wires male-to-female
before we deep dive into building the
circuit I like to explain how this sound sensor works
in front of the sound sensor is a microphone
and also a potentiometer which I'll explain later
some can be seen as sound waves
and our sensor captures these sound waves
with his microphone
these sound waves are translated into  resistance
and it's resistance is exactly the same as the amount of sound
this means that where is a lot of sound then there is also a high resistance
and where is almost silence
there's almost no resistance
this means that when we apply 5V 
to our board
that the sensor sends 5V to the OUT 
when there is a low resistance
so when there is almost no sound
and it sends around 0V 
when there is a lot of sound
our board has a certain boundary to determine whether
the signal will be seen as LOW or HIGH
so here you can see that everything
above the boundary will be seen as LOW
and everything below the boundary will
be seen as HIGH
the potentiometer I mentioned earlier can be turned clockwise and counterclockwise
this will adjust the level of this boundary
so you can move it up
or you can move it down
when you run the sketch and you see 
only zeros or only ones
this probably means you have to 
adjust the potentiometer
to a certain level where you can see the
ones and zeros depending on the sound
we're now going to build the circuit
the first step is to connect our sensor
to the jumper wires
the green wire is connected to the OUT
the blue one to the GND
ground
and the red one to the VCC
we're continuing by connecting 
the jumper wires to our Arduino
the red wire is connected to the 5V
the blue one to the GND
and the green one to digital pin 8
we're now ready to have a look at the code
the code is pretty straightforward
on line 17 we define the OUT_PIN constant
and we set it to number 8 which
is the pin number on the Arduino
the setup() is also pretty straightforward
we just initialise the serial monitor
then in the loop() we print the value
we've read on the OUT_PIN
and we do this with digitalRead() on the OUT_PIN
and print it to the serial monitor
if I send this to my Arduino
and I open, here in tools, the serial monitor
we see all the numbers printin from line 24
and when I'm silent...
you see only ones
and when I talk you see all these zeros going on
it's not continuously zeros
because the Arduino is very fast
and between words I have a small piece of silence
so that's what you see here
but the zeros and ones are not so interesting
so what I'm going to do instead of
opening the serial monitor
I open the serial plotter
and now you can see all the zeros and ones 
here in a chart, but it's not very interesting
you can see when I say something
you can see when there is a silence
it's not very interesting, we want to know more
about the intensity of the sound
what I'm going to do is change the code a bit
so you can actually see a graph
where you can see the intensity of the sound
and that's what I'm going to show you now
so I've changed the code a little bit
and what I did here was adding on line 18,
the SAMPLE_TIME
what are we going to do
is to sample the audio
and the number here in SAMPLE_TIME is the number 
of milliseconds of a sample
this means is that every 10ms
we take a sample and we count
within those 10 milliseconds
how much ones we've seen from the sound sensor
because we're using timing we're
going to use millis()
so we have three variables
one to save the current time
one to save the last timestamp
and the elapsed milliseconds since the last time
we also need to store somewhere the value of 
the amounts of ones within the sample time
so we have here a sampleBufferValue
and that one is 0 of course
the setup() is the same
and we've changed the loop()
a little bit with some calculation
so we start by grabbing the current millis here the millis timestamp at the moment,
and store it in millisCurrent
then we can calculate the elapsed time since the last time sample was started
then we read the OUT_PIN 
and if this one is LOW
that means there is sound
we increase the sampleBufferValue but this happens
this happens continuously, but we're not printing it
immediately to the serial monitor
therefore is this if on line 38
we check if the elapsed time is larger
than the SAMPLE_TIME
if so, then we print the sampleBufferValue 
to our serial monitor
monitor if so we reset the sampleBufferValue to 0
and we set millisLast lost to the last time stamp
and that's the same as millisCurrent
which we've taken here from the millis()
so I'm going to upload this to my Arduino
and then I'm opening the serial monitor
and you will see a lot of different numbers
previously we had a zeros and ones
but now there is also a counter going on
which shows us how much time I've talked 
in the sample time of 10ms
but it's also not so interesting since it's a bunch of numbers
so we're going to open the serial plotter
and while I'm talking you see
there is a difference in the amplitude of the chart
so if I talk very silent
or HARDER
then you can see the difference in the amplitude
so that's quite nice, we've found a way
with sampling to show audio in the Arduino plotter
so that's it for this tutorial
if you have any questions
you can leave them in the comments
in the description of this video
you'll find a link to the course material
the course material contains the code,
the circuit diagram
and also a list with all the components used
I see you in the next video!
you
