Experiment 3 - Potentiometer
Experiment 3 - Potentiometer
Experiment No. 3
Experiment No 3 Student ID
Date Student Name
Aim/Objective:
The main objective of this experiment is,
A. To read potentiometer data and print on the Serial Monitor
B. To interface potentiometer with LED.
Components required:
Software Hardware
Arduino UNO Board
Tinkercad Arduino UNO Cable
Arduino IDE (To be installed in Laptop) Potentiometer - 1
LED (Red-1, Green-1, Blue-1)
Resistors – 2 (1KΩ each)
Jumper wires
Description:
The potentiometer is a device that is used to measure the voltage or electric potential.
It provides a variable resistance when the shaft of the device is turned.
Here, we will measure the amount of resistance as an analog value produced by the
potentiometer. We will connect the potentiometer to the Arduino UNO board and will
measure the state of the potentiometer. The required code will be uploaded from our
computer to the Arduino board.
The variable resistance measured by the potentiometer can be easily read as an analog
value into the Arduino board.
The potentiometer is a three-terminal device. It has a rotating contact that acts as an
adjustable voltage divider.
The potentiometer structure consists of a sliding contact (called wiper), a resistive
element, electrical terminals, and housing.
The sliding contact moves along the resistive element, while the housing consists of the
wiper and the element.
Working: The fixed input voltage is applied across the two ends terminal of a
potentiometer, which further produces the adjustable output voltage at the wiper or
slider.
As the slider moves from one end to another, the divider can vary the output voltage
from maximum to Ground.
Page | 2
The connection of potentiometer with Arduino board is shown below:
Pre-Requisites:
Electronics fundamentals
Basic knowledge about Arduino Pins
Pre-Lab:
1. What is the usage of potentiometer in interfacing Arduino?
The potentiometer is a device that is used to measure the voltage or electric potential.
It provides a variable resistance when the shaft of the device is turned.
2. How to control potentiometer with Arduino?
The typical potentiometer will have 3 pins, two power supply pins (+5V and GND),
and one pin that connects to an analog input pin on your Arduino to read the value
output.
3. What is the limit of potentiometer in Arduino?
The value can be read as an analog value, with the Arduino board. The value goes from
0 to 1023 depending on the rotation of the knob on the potentiometer.
4. What are the two main types of potentiometers?
There are two main types of potentiometer, linear potentiometers and rotary
potentiometers.
5. How to code potentiometer in Arduino?
To code a potentiometer in Arduino, you need to first connect the potentiometer to the
Arduino board. The potentiometer has three pins: the first one (usually on the left)
connects to 5V, the second one (in the middle) connects to an analog input pin on the
Arduino, and the third one (usually on the right) connects to ground (GND).
In-Lab:
Procedure:
First make sure that the Arduino is powered off.
Plug the potentiometer on the breadboard, with each leg on an independent line. Note:
some potentiometers have a different layout, with 2 pins facing one side, and the middle
pin facing the other side. In this case, plug the potentiometer in the middle of the
breadboard so it will be easier to add wires to the circuit.
Connect one of the external leg of the potentiometer to the ground of the Arduino
(GND).
Connect the other external leg to the power supply (5V).
Plug the middle leg to an analog pin of the Arduino, for example here A0.
Page | 3
Program:
void loop()
{
int sensorValue = analogRead(potpin);
Serial.println(sensorValue);
delay(10);
}
#define LED_PIN 6
#define POTENTIOMETER_PIN A0
void setup()
{
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int potentiometerValue = analogRead(POTENTIOMETER_PIN);
int brightness = map(potentiometerValue,0,1023,0,255);
Serial.print("LED Brightness Value is:: ");
Serial.println(brightness);
analogWrite(LED_PIN, brightness);
}
Page | 4
Connection Diagram:
Program A:
Program B:
Page | 5
Results:
Post-Lab:
Page | 6
Experiment No 3 Student ID
Date Student Name
Program:
/*
* Code for making one potentiometer control 3 LEDs, red, grn and blu, or one tri-color LED
* The program cross-fades from red to grn, grn to blu, and blu to red
*/
// INPUT: Potentiometer should be connected to 5V and GND
// OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins
// Program variables
int redVal = 0; // Variables to store the values to send to the pins
int grnVal = 0;
int bluVal = 0;
void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
}
// Main program
void loop()
Page | 7
Experiment No 3 Student ID
Date Student Name
{
potVal = (potVal * 3) / 4; // Normalize to 0-255
redVal = 256 - potVal; // Red from full to off
grnVal = potVal; // Green from off to full
bluVal = 1; // Blue off
}
else // Upper third of potentiometer"s range (682-1023)
{
}
analogWrite(redPin, redVal); // Write values to LED pins
analogWrite(grnPin, grnVal);
analogWrite(bluPin, bluVal);
}
Page | 8
Evaluator Remark (if Any):
Marks Secured: out of 50
Page | 9