Hello and welcome to SciJoy, let’s explore
how to get this analog signal into something that you and your computer can understand. [Intro – Airplane Mode by Josh Woodward] It is an called an analog signal, because
it is analogous, or a close representation, to what is happening in the environment. When we feel temperature, we don’t just
feel a high and a low, like a digital signal would. We feel everything in between. A temperature
sensor needs to be able to feel the whole spectrum this is why we need to use an analog sensor. But an Arduinos speak in digital form using binary. This means we have to translate
our analog signal into a digital one using an analog-to-digital converter. Let’s first look at an overview of the process
of translating stimuli in the environment to data we can use. Then we will break down
each step. A stimulus happens in the real world like shining light on a photosensor, heating a
temperature sensor, or pushing down on a pressure sensor. This is going to change the electrical property of the sensor. In each of these cases, it is going to change the resistance of the sensor. This change in resistance then is also going to alter the voltage across your circuit. Now let’s turn this voltage value into something that the computer can use. The analog-to-digital converter creates “voltage buckets.” The converter samples the incoming analog signal and is going to place it into on of these buckets. Each of these buckets is associated with a
code word. This word is linked to an integer (whole number). This integer is told to you and to the computer program. You can turn this integer back into a voltage value, and that will be associated with a temperature, pressure, brightness, or some other physical quantity. This might sound like a long complicated process, but you only need to do one or two steps in
the beginning and the end. The Arduino and computer do the rest. Step 1 of this process is building your circuit.
You can use our resources, SparkFun, Adafruit, community forms, and data sheets. This will all help you will building your circuits. And we are going to have a lot more videos along the way. Step 2 is the voltage drop across the sensor this is going to be read by the analog pins on the Arduino. Step 3 the ADC samples the signal.
It samples the analog signal at regular intervals and holds on to this values as it translated
it to a digital value. The process is called sample-and-hold. The faster the sampling,
the smoother the recreated curve is. Step 4 the ADC quantizes you signal.
There are an infinite number of possible voltages when looking at an analog
signal. There are only two voltage levels when looking at a digital signal. The ADC compromises and creates N
number of buckets for the voltage values to be thrown into. We need to understand how binary and decimal systems compare. If I told you to pick a 1 digit number in the decimal system, you’d pick any number from 0 to 9. because it is a base 10 system. If I told you to pick a number in the binary system, you could only pick 0 or
1 since its s a base 2 system. You can see that a 1 digit number has 2 options in binary and a 2 digit number has 4 options and a 3 digit number had 8 options.
This is more easily written 2^n . The number of buckets is (2^n)-1 since we
start at zero. This is why the photon in the previous video has both 255 and 4095 as options
for an along values. It had an 8 bit and a 12 bit converter. The more buckets, meaning the higher the resolution,
the closer the converted curve is to the original. Let’s look an example. We have an 3 bit converter and with a maximum of 5 voltage across our circuit and 7 buckets to work with. These are the associated code words with each voltage value. and their decimal numbers.
This is how all of them are linked. The converter on the Arduino Uno does successive approximation. It guesses a voltage
value and compares it to the voltage from the incoming signal. The comparator asks if the sampled signal is greater than the guess. Through this guess and check method
a code “word” is produced. As we saw, this code word is linked to both a decimal number and a voltage value. The decimal number is what is sent to you computer. So all you will ever see from a 3 bit converter is a number from 0 to 7. Step 5 is converting that decimal number back
into a voltage. We already know how to get the associated
voltage value from our table. We can also use the equation V=Vmax*Output/bitResolution. Step 6 you have to relate this voltage back
to a physical quality. You can use the data sheet or calibrate the
sensor yourself to determine the relationship between the physical quantity and voltages.
If we look at this temperature sensor data sheet, we can use two points off the line
associated with our sensor to create an equation. Or you can increase or decrease the temperature on the sensor and see the corresponding output voltage
and create your own line. Then you can take this and make a simple equation to put in your code. Looking at this temperature graph, we can pick two points and find the equation of this
line. Where y is the voltage and x is the temperature of the sensor. You find the slope m, by using this equation. We get a slope of .0095. Then you can find the y-intercept, b, by plugging in one of the points. Our intercept is .52. We will know what our voltage is from our
code, so we can solve this equation for x, which is the temperature we are finding. If you put this in your code, the program
will always convert for you and you don’t have to do any more math. If you’d like to learn more about the internal
workings of ADCs, you can click this playlist. We will be adding videos to it explaining
binary math, logic gates, most significant and least significant bits. All of which give
you a good foundation for understanding electronics. You can chat with us on these social media platforms or in the comments below. You can
support us Patreon.com/SciJoy. And remember, keep exploring.