This Article shows you how to read analog input from the physical world using a potentiometer. A potentiometer (also called pot for short) is a straightforward mechanical device whose shaft may be twisted to vary the resistance it offers. You may measure the amount of resistance a potentiometer produces as an analogue value by applying voltage to the potentiometer and into an analogue input on your board. In this post, you will establish serial communication between your Arduino and a computer running the Arduino Software (IDE) and then check the status of your potentiometer.
Components Required
- Arduino Board
- Bread Board
- Jumper Wires
- Potentiometer - 10k Ohm
- Computer/Laptop with Arduino IDE
Circuit
The potentiometer's three wires must be connected to your board. The first connects to ground from one of the potentiometer's outer pins. The second connects to 5 volts from the potentiometer's other outside pin. The third connects the analogue pin A0 to the potentiometer's center pin.
![]() |
Circuit Diagram of Analog Signal Reading. |
The amount of resistance on either side of the wiper, which is attached to the centre pin of the potentiometer, can be adjusted by rotating the potentiometer's shaft.The voltage at the centre pin is altered as a result. The voltage at the centre pin approaches 5 volts when the resistance between the centre and the side connected to 5 volts is close to zero (and the resistance on the other side is close to 10k ohm). When the resistances are reversed, the centre pin's voltage approaches zero volts, or ground. This voltage serves as the analogue input that you are reading.
Code
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}
Comments
Post a Comment