Code
int ledPin=9;
int potPin=A0;
int potValue;
int pinValue;
int DT=1000;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(potPin, INPUT);
Serial.begin(9600);
}
void loop()
{
potValue=analogRead(potPin);
Serial.println(potValue);
delay(DT);
pinValue=(255.0/1023.0)*potValue;
analogWrite(ledPin,pinValue);
}
LED Control with Potentiometer using Arduino
In the field of electronics and programming, controlling an LED with a potentiometer is important too. By varying the resistance of the potentiometer, you can change the brightness of the LED. We will interface an LED (light-emitting diode) to the Arduino UNO board. An LED is a simple diode that emits light with a forward bias. We control the brightness of an LED by interfacing a potentiometer with it. We write a program in the Arduino IDE and download it to the microcontroller board.