Measure the potentiometer values 

Many of the devices that we use in our daily life contain a rotating knob that helps the user adjust the settings of these devices.


It's simply a variable resistance called a potentiometer. The device can understand the change in the potentiometer value and then change a certain output.


In this tutorial, we will use the Arduino to display the potentiometer values in percentage and display them on your computer!


Overview


Rotary potentiometers are a type of variable resistance that allows you to adjust the resistance and therefore, the voltage. They are used in several applications, such as adjusting audio volume or light brightness.


It is very simple and easy to apply.


Let’s see together!


Getting the items


For this project you will need the following components you can buy them from our store.

Sale Off
Voltaat Arduino Uno R3 (Voltaat Version)
45 QAR
Sale Off
Voltaat Rotary Potentiometer
1 QAR
Sale Off
Voltaat Full-size Breadboard
20 QAR
Sale Off
Voltaat Jumper Wires - Male to Male (40 Pack)
10 QAR

Wiring it up


To set up the potentiometer in the correct way, follow the instructions below. The image demonstrates how to connect the wires between the potentiometer and the Arduino. Once the potentiometer and the Arduino are connected to each other, connect the Arduino to your computer using the USB cable.



Connections from the Rotary potentiometer to the Arduino:

• potentiometer GND pin → Arduino GND pin

• potentiometer out pin → Arduino A0 pin

• potentiometer VCC pin → Arduino 5V pin 


Coding


The function of this sketch is to read the rotary potentiometer values and display them in percentage on your computer through the Arduino IDE.


Let's test out the code together; it is easy to understand and you don't need to add any libraries.


/*
Voltaat learn (https://www.voltaat.com/pages/voltaat-learn)
Link for full tutorial: https://bit.ly/3SFxQbQ

Tutorial: Measure the potentiometer values

The function of this sketch is to read the rotary potentiometer values
and display them in percentage on your computer

Connections from the Rotary potentiometer to the Arduino:
• potentiometer GND pin → Arduino GND pin
• potentiometer out pin → Arduino A0 pin
• potentiometer VCC pin → Arduino 5V pin
*/


//Define the variable PotentiometerRead to Analog Input Pin A0
#define PotentiometerRead A0

//Commands inside void setup run once
void setup()
{
//Start the serial monitor at 9600 baud rate (9600 bits per second)
Serial.begin(9600);
}

//Commands inside void loop run forever
void loop()
{
//Read the analog value from the potentiometer out pin and assign it to the variable Read
int Read =analogRead(PotentiometerRead);
//Convert the value to percentage
int percentage =map(Read,0,1023,0,100);
//Print to serial monitor
Serial.print("The Potentiometer at ");
Serial.print(percentage);
//Print "%" to the serial monitor and then add a new line
Serial.println("%");
//wait for 100ms
delay(100);
}

Testing it out




Now you must have correctly wired the potentiometer to the Arduino as we explained in the wiring section, as well as uploaded the code to your Arduino board.


You may now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.



The serial monitor is a great tool that can facilitate communication between the computer and the Arduino. It can allow us to send and receive different commands, as well as view information directly from the Arduino.


Now, as we see in the following image, the serial monitor displays the potentiometer values in percentage. You can change the resistance value by rotating it and see the new outcome right away on your computer.


You should also make sure you have chosen the right baud rate (9600) as specified in the code.


Resources 


Arduino Code

Fritzing Wiring file

Related Tutorials


LCDs are used in a range of everyday applications, including the automobile radio and the house air conditioning remote. They display data and let you control it through menus.


A servo motor is just a simple DC motor with certain modifications. When you look at it, you'll notice that it has several gears and an electronic circuit.


In this tutorial, we will learn how to use a PNP transistor to operate a DC motor. It will provide the motor with the necessary power.