Potentiometer Interfacing with Arduino
What is a Potentiometer?
A potentiometer (often called a "pot") is a three-terminal variable resistor used to adjust voltage or control electrical devices like volume on audio equipment or brightness on lights.
Image of Potentiometer:-
Task 1:- print the value of the potentiometer on LCD.
Code:-
#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,5,4,3,2);
int pot=A0;
int a;
void setup ()
{
lcd.begin(16,2);
pinMode(pot,INPUT);
}
void loop ()
{
a=analogRead(pot);
lcd.setCursor(0,0);
lcd.print(a);
delay(1000);
lcd.clear();
}
Output:-
Task 2:- Turn on the led if the potentiometer value is greater than 500.
Code:-
int led=12;
int pot=A0;
int a;
void setup ()
{
pinMode(led,OUTPUT);
pinMode(pot,INPUT);
}
void loop ()
{
a=analogRead(pot);
if (a>=500)
{
digitalWrite(led,HIGH);
}
else
{
digitalWrite(led,LOW);
}
}
Output:-
0 Comments