In this tutorial, we will learn how to control or adjust the blinking time of an LED using a potentiometer and Arduino. We control the delay time of LED blinking, we replace the value of the delay time from the potentiometer reading.

We read Analog value by analogRead  Function. The voltage is adjusted by the potentiometer.

Video Tutorial

Components List

  • Potentiometer
  • Arduino Uno
  • LED
  • Resistor

Potentiometer Pinout

potentiometer-pinout

Pin Connections

Potentiometer and LED PinsArduino Pins 
5v or Vin5V
GNDGND
VoutA0
LED anodeD5
LED cathodeGND

***Use of Resistor with LED is mandatory otherwise LED will burst.***

Circuit Diagram of Arduino Potentiometer Interface

Circuit Diagram LED Blinking Control by Potentiometer

The Code

/*
   LED Blinking Control by Potentiometer
   For more details, visit: https://techzeero.com/arduino-tutorials/led-blinking-control-by-potentiometer/

   Blink an LED at a rate set by the position of a potentiometer
*/
const int potPin = 0; // select the input pin for the potentiometer
const int ledPin = 5; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup()
{
  pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
  Serial.begin(9600);
}
void loop() 
{
  val = analogRead(potPin); // read the voltage on the pot
  digitalWrite(ledPin, HIGH); // turn the ledPin on
  delay(val); // blink rate set by pot value (in milliseconds)
  digitalWrite(ledPin, LOW); // turn the ledPin off
  delay(val); // turn led off for same period as it was turned on
  Serial.println(val);
}

The Output

Output of LED Blinking Control by Potentiometer

«« Previous How to use Potentiometer with Arduino
Next »» How to use an LCD Display with Arduino

Our Youtube Channel