How To Use A Potentiometer Arduino
Howdy friend's, welcome to the some other tutorial of How to Electro. In this tutorial, we will know, how to use potentiometer with arduino.
We will too know most the potentiometer (Detailed data of the potentiometer will exist in the upcoming tutorials) along with analogRead() function, variables and Serial function. And then friend's, permit's brainstorm.....
H.T.E. Highlighted :- Above is the video of the whole tutorial in hindi.
Potentiometer
Potentiometer is a type of resistor, which has a sliding or rotating contact which rotates over a resistive fabric, forms a adjustable voltage divider. We will know well-nigh the voltage divider in the upcoming tutorials.
Construction
It consists of a sliding contact, which slides over a resistive material. The sliding contact is also known as wiper or slider , which is connected to a knob, and rotates along with the knob.
In that location are 3 terminals coming from the potentiometer, in which middle final is connected to the slider or wiper , and is known equally signal/wiper/slider/output pivot , and the another two are connected to the both ends of the resistive cloth respectively.
And these all are bundled properly within a covered construction, forming a total potentiometer.
Working
Information technology works as an adjustable voltage divider, when all the terminals of the potentiometer are continued in the circuit. The connection will be similar, the bespeak pivot of the potentiometer is continued to the output, and some other two terminals is connected to +5V and 0V respectively. We tin connect whatever final of the potentiometer excluding signal pin , to the +5V or 0V. When working as a voltage divider, its output voltage is a fraction of the input voltage. We volition know about this in the voltage divider tutorial. We can read the diverse outputs from the indicate pivot by rotating the knob.
Information technology also works as a variable resistor ( variable resistor means, that the resistance value changes due to an cause. e.g. LDR, potentiometer etc.) , when merely ii of its terminals are connected to the circuit, including indicate pin and one of the end of the resistive textile. We can use this property to modify the effulgence of light by rotating the knob. The connection of this wil be like, the signal pin is connected to +5V or output, and the another pin is connected to output or +5V respectively. At present, by rotating the knob, we tin can modify the resistance of the potentiometer, and hence, the effulgence of LED can also be controlled.
Uses
The potentiometer is available in various designs specific for diverse purposes.
e.g. trimmer, variable resistor etc.
It is used to command volume, control brightness of light, control speed of fan, manually defining the value etc.
Connecting the Circuit
Connection
The circuit consists of merely a few components, namely, arduino, potentiometer and some wires. We had to connect potentiometer'' terminal of one side to +5V and terminal of another side to GND. The betoken pin of the potentiometer is connected to the analog pin A0, which receives output from the potentiometer, and we will use this to catechumen into an integer value.
Working
The potentiometer works as a voltage divider here, as we had used all its terminals. The +5V is supplies to the potentiometer and it goes to the ground via a resistive cloth, every bit the some other stop is connected to the GND. When we rotate the knob, the resistance of the voltage divider changes, every bit nosotros rotate it clockwise, the resistance increases, and decreases when rotated anti-clockwise. This change in resistance provides unlike output from the signal pivot , which slides over the resistive material, and we utilise this output to catechumen information technology into integer value programatically.
Code uploading and Reading value
int POTpin = A0;
int POTvalue = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
POTvalue = analogRead(POTpin);
Serial.println(POTvalue);
delay(100);
}
In the above code, beginning ii line of lawmaking is used for declaring two variables, 1 for declaring the input pivot ( the pin to which signal pin of the potentiometer is connected ), and the another is used for storing the value from the potentiometer. Both of these stores integer type value, so these are assigned int blazon , and each of these has given unique names, then that we tin can use it anywhere, within the code.
void setup()
This function runs once, when the arduino is turned on or reset button is pressed, and stores all the initialization, that need to be run once, similar pivot way setup, starting of series communication etc. In the above code, it contains Series.begin(9600) function which is used to start the serial communication, and information technology takes the baud rate of the communication as it's parameter for reading the values and sending it. The default baud charge per unit for the serial monitor is 9600.
void loop()
This function runs consecutively, till the arduino is powered off. All the code or function, that needs to be consecutively used must be used inside this.
e.m. Turning light on or off, controlling the motor etc.
In the above lawmaking, it contains iii lines of code, in which starting time is of reading the value of the potentiometer, 2d is to send it to the serial monitor, and third line sets the filibuster for 100 ms. Allow'due south know most these in details.....
i.
POTvalue = analogRead(POTpin);
This line of code contains analogRead() part, which reads the value given at the analog pin ( the pin number is specified every bit it parameter, which information technology had to read ) and converts into an integer range of 0-1023 ( 0 for 0V and 1023 for +5V ). POTpin is specified as information technology's parameter, which is an integer blazon variable and stores the pin number A0 .
The output value is then, assigned to the variable with proper noun POTvalue . Now, we can employ the name of this variable to read the value stored in it.
2.
Series.println(POTvalue);
This line of lawmaking contains Serial.println(POTvalue) function, which is a serial blazon function, and information technology is used to ship some value to the serial monitor, and displays to the user. Information technology takes the value, nosotros want to display to the user, as it's parameter.
POTvalue is specified as it'south parameter, whose value has been changed by the previous line of code, and hence the value of the potentiometer is displayed to the user.
iii.
delay(100);
This line of lawmaking contains delay(100) function, which is used to add delay to the arduino i.e. it stops the arduino for specified time in ms declared in it'south parameter, before going to the next line of lawmaking.
Hence, in the above lawmaking, 100ms is used as the parameter, so, the arduino volition await for 100ms before re-running the loop.
We had now learnt, how to utilise potentiometer with arduino, and besides know the way of reading the value of the potentiometer.
And then friend's, that's all for this tutorial. Hope u enjoyed it.
Cheers
HowtoElectro ( Samridh Sharma )
How To Use A Potentiometer Arduino,
Source: https://howtoelectro.plussmiley.com/2018/08/using-potentiometer-with-arduino.html
Posted by: oconnellsilth1993.blogspot.com
0 Response to "How To Use A Potentiometer Arduino"
Post a Comment