Tuesday

Arduino Uno Basics - AnalogReadSerial


I have been fiddling with Arduino Uno since I got a new Arduino Kit a few days ago. It was quite exiting for me as I have studied Electronics in my Polytechnic college. It was never as exiting as it is today. There is a lot of material available on the net as well as on Youtube if you are doing experiments with Arduino. What I am doing here is assembling all that together to help you get started with Arduino if you are new to Arduino.


I hope you already possess an Arduino Kit. If not and if you are in India, you can take a look at the Kit that I bought on Amazon.in 


 Once you have a Arduino Kit, the next thing you need is the Arduino software, that you can install on your computer from Arduino's website from this link.


We will need a 10 Kilo Ohms Potentiometer for this experiment. The Pot that comes with the Arduino Kit is probably a Linear Pot. You will also receive a Breadboard, Arduino Uno board and wires. We will connect them as shown in this figure.


This is the Pot that I got in my Kit. The B10K indicates that it is a Linear Taper Potentiometer ( Here in India ) and it's maximum resistance is 10 Kilo Ohms. There is a knob for you to rotate and three pins to connect.



The two pins at the ends are for the power supply. We are going to connect it with 5V socket on Arduino. You can attach any end to 5V and the opposite end to Ground. They are interchangeable. The middle pin is for the Signal or Output. The varying resistance of the Potentiometer can be measured from this middle pin. When we power up the Pot, the varying resistance translates into varying voltage and it is available on the middle pin. When the resistance is zero the voltage would be 5V, and when the resistance is 10K the voltage is zero. 


So let us understand the Pot connections. Generally there is a visible notch on the right side of the potentiometer. That will be the Left side if you hold the Pot with its knob in front of you. So if you turn the knob towards the knob, that is to the left, it would be in zero resistance position. You can confirm it by measuring the resistance using a multimeter. Measure the resistance between the pin on the notch's side and the middle pin. And the resistance between the opposite pin and the middle pin would be 10 Kilo Ohms. This will be our initial position.  Why I chose this to be the initial position because the initial resistance between the 5V pin and the Signal would be 10K and thus our signal output would then be 0V. As we will turn the knob Clockwise, we will start getting higher voltage and thus the output on the computer's screen would be from 0 to 1023. This would satisfy our logical expectation of turning something from Low to High.  




Now while connecting the power supply connect the negative/ Ground wire, generally black wire is used for this, to this pin. We will use a red wire for the opposite pin. as shown in the figure.



Here you can see the socktes of Arduino Uno board. These are labelled "Power" We will connect the black wire to any of the two Gnd sockets, and the Red wire will go to the 5V socket. You can call them Pins/Ports/sockets/ points whatever makes you understand better. I will be referring to these points where we will connect wires to Arduino Board by any of these names, so don't be confused, they all mean the same at least for me. 

The middle pin of the Potentiometer will be connected to Pin A0 which is an Analog port on Arduino Uno.




Once you have connected the Potentiometer to the Breadboard and the wires to the Arduino board, you can connect the Arduino Board to the computer's USB port. And then open the Arduino IDE. 



 

Open the first example by clicking on Examples > 01 Basics > AnalogReadSerial.

  
You see the menu icons on the top of the screen. The first one is to verify the program, do it. You will see a message "Done Compiling" at the bottom of the screen. Then click on the next icon, that is for Uploading this software on the Arduino Board. when complete you should see the message "Done Uploading" at the bottom of the screen.


Now open the menu Tools - Serial Plotter in the Arduino IDE. You should see a new window as in the figure below. Now if you rotate the knob of the potentiometer you should see a varying graph on your screen. The values of this graph are between 0 and 1023. That is the digital conversion of the 0 to 5V output that is received on the middle pin of the potentiometer. This voltage is converted to a number by the ADC circuit on Arduino Board. It is Analog to Digital Conversion.

The output of this conversion is accessed by the AnalogRead() function in the program. And the values are received on your computer through the Serial.begin(9600)  function.


 You can also see these values in the numbers form from  ( Tools - Serial Monitor ) 




  

Featured Post

Creating Games in Scratch for ICSE Class 6

An Introduction to Creating Games in Scratch  for ICSE Class 6 Hello friends, I hope you have already read the previous post on An Int...