Arduino Analog Inputs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this tutorial I'm going to teach you what is the difference between a digital and an analog signal show how the Arduino reads analog values and finally I will show you how to read values from a potentiometer up until now you were used to a requite high-low through in false logic signals on the Arduino for example to blink a LED these logical values are nothing more than a signal that can only assume zero and a max voltage which in the Arduino Uno is 5 volts in many boards the high level is 3.3 volts although the Arduino can read and write these digital signals not all devices work with digital logic let's consider a potentiometer which is a manually adjustable variable resistor that acts as a variable voltage divider in this example I'm reading the values from a pot using an oscilloscope you can control the output voltage of the potentiometer by changing the knob position as you can see this is not a logic signal with a high or low value but an analog signal that in this case you can vary from 0 up to almost 5 volts you probably know a lot of analog components there are temperature sensors photo resistors microphones potentiometers and many others how to read analog values the element that enables an Arduino to read analog values is an ADC or analog to digital converter an ADC is a piece of hardware that converts an analog value to a digital value I'm going to try to explain what an ADC does in the simplest way I can imagine here you can see an example of a sine wave that ranges between 0 & 5 volts the analog signal is continuous in time and it is necessary to convert this into a flow of digital values in order to do this we consider a set of time instances in a given interval this is called same sampling in other words we take a sample from time to time the number of samples acquired per second is called the sampling rate in this chart I'm showing only 3 samples the next step is to cover the analog value of each sample into a digital value here's how it works let's divide our signal into 2 horizontal sections for each sample if it's analog value falls into the upper section it is converted into the digital value 1 but if the value Falls in the bottom section the digital value is 0 let's convert it the first sample falls into the upper region so it's a 1 the second sample falls into the bottom region so it's a 0 finally the value of the last sample falls into the bottom region which corresponds to the digital value 0 we have just converted an analog signal to a digital one with a 1 bit accuracy this process is called quantization let's look at the same example but with 4 regions or to beat accuracy in this example we can convert a range of infant analog values from 0 to 5 volts to a range of finite digital values from 0 to 3 nonetheless this isn't very precise if we were to record a microphone input to digital just like this we wouldn't get studio-quality the more horizontal subdivisions we have the more accuracy we can have finally the Arduino has a set of functionalities that allow the conversion of analog values to digital ones it contains a 10-bit ADC with six separate inputs this means you can convert the value between 0 and 5 volts on the Arduino Uno to a digital value that ranges between 0 and 1000 and 23 the Arduino also provides a function that interacts with the ADC the analog grid function next I will create a small demonstration on how to use the Arduino ADC in this example I will be reading the analog value of a potentiometer and then print the values in the computer using RINO's serial communication for this demonstration you will need an Arduino and a potentiometer of course do not forget a breadboard and some wires here is the configuration I used power and ground go to either sides of the potentiometer the order doesn't matter the output of the potentiometer is in the middle which is what we want to read with the arduino z DC in this example I'm using the Arduino mega but feel free to use any other Arduino since the software is the same for all of them now for the code let's start with our blank sketch with the setup and loop functions start by registering the pin where you connected the bots output to keep the code clean and tidy do not forget this must be an analog pin next initialize the serial component of the Arduino this is the part that allows the communication with a computer this will be the next videos topic for now set the serial to a speed of 9600 bits per second in the loop function we want to read the value of the ADC each iteration and then print it to the screen use the analog read function and indicate which pin to read ours is stored in the pot variable next we just have to print the value to the screen to print values from the Arduino you just have to type serial dot print or serial dot print line the first one prints the string without breaking a line the second prints a string and then creates a line break in this sketch I'll print a string and then the potentiometer value which is stored in the pot value variable finally just create a little delay so we don't see too many prints in the screen after uploading the code to the Arduino in the arduino ide go to tools and click on the serial monitor option it will open this window on the bottom right corner this is a small tool that detects data sent by the arduino serial and then prints it to the screen as you can see the arduino is printing the value 0 because my pot is at the max position when i turn the knob it changes the internal resistance increasing the output voltage this value is read by the arduino as a DC and then printed by serial to the computer thanks for watching and don't forget to subscribe
Info
Channel: HackTheWorld
Views: 32,439
Rating: 4.9749217 out of 5
Keywords: arduino, tutorial, analog, input, analogRead, electronics, learning, uno, mega, potentiometer, breadboard, resistor, adc, signal
Id: cmc-BPtkdAU
Channel Id: undefined
Length: 6min 8sec (368 seconds)
Published: Sat Aug 04 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.