• nithya7rns

Control the Flashing Rate of An Led Using A Potentiometer

Flashing of LED is usually used in #signaling applications. Let's say we are driving to the Supermarket in our car and want to park it in a very small place available since we were late. We have a parking sensor that will guide us with the distance between the wall and our car. At the same time, if we observe, we see the LED lights present on the side of the car as indicators start blinking at a faster rate when we start nearing the wall.


So here the Flashing of the LEDs along with the #buzzer tone is used for signaling. This is just one of the many applications of Flashing LEDs at a varying rate. Let us now learn how the circuit behind this designed and how it works. We start with the list of components required.


In this article, we are going to design the circuit using two different #microcontrollers. One circuit with Arduino and the other using NodeMCU. So when we are going to describe the working of the circuit, the article will be divided into two based on the type of microcontroller used. But the list of Hardware required will be the same except the microcontrollers which will be separately used for each of the two circuits. Here we go.


Hardware Requirements


  1. Arduino UNO

Develop a stronger concept in Arduino through this article:- What is Arduino?


Arduino UNO
Arduino UNO

Arduino board is a microcontroller that is used to accept inputs from sensors connected and provide an output action on the desired device connected to it. The sensor inputs can be that from light-detecting sensors, flame sensors, temperature sensors, etc. The output function done by the devices can be turning on an LED, the sound of a buzzer, or a Serial monitor display.

Buy Arduino UNO from here.


2. NodeMCU

NodeMCU
NodeMCU

NodeMCU is a platform provided for #IoT. It basically includes firmware (computer software that contains instructions and controls the hardware) which runs on Esp8266 WiFi SoC (software on-chip). It is open-source firmware available for prototyping and developing kits. MCU means a Micro-Controller Unit. The device contains GPIO (General Purpose Input Output) pins which send and receives data on connection to other devices.


The specifications of the Esp12e module are:

  • 32-bit lx106 RISC Microprocessor.

  • 80MHz-160MHz, the adjustable clock frequency.

  • Supports Arctic OS(Operating System).

  • 1 KB Internal RAM.

  • 4 MB External flash.

  • 2.5V to 3.6V, 3.3V onboard.

  • 600 milliAmp Regulator.

  • 80 milliAmp Operating Current.

  • 20 microAmp Current in sleeping Mode.

  • 17 GPIO pins (which include ADC channels, 2 UART Interfaces, 4 PWM outputs, LED, Reset button, etc.).

Buy NodeMCU from here.


NOTE: We don't require both Microcontrollers for building one circuit. The circuit designs are done separately and are explained further in the Article.


3. LED


Build your technical concepts in LED by this article:- Light Emitting Diode


LED
LED

Light Emitting Diode is a commonly used light source. It is a #semiconductor. When current flows through it, LED emits light.


Buy LED from here.


4. Jumper Wires


Jumper Wires
Jumper Wires

These are the main components that are used to establish the connections between different devices of the circuit.


Buy Jumper Wires from here.


5. Resistor



 220 Ohm Resistor
220 Ohm Resistor

Resistors are passive devices that restrict the flow of current or divide the voltage through the circuit. The resistor used for the proper functioning of this circuit is a 220 Ohm Resistor.

Buy Resistors from here.


6. Potentiometer

Potentiometer
Potentiometer

A potentiometer is a device that is used for varying resistance in a circuit. It usually consists of three terminals and sliding or rotating contact that further act as an adjustable #voltage divider for the device.


Buy a Potentiometer from here.


7. Breadboard


Breadboard
Breadboard

The breadboard is the basic component of any circuit building process. All components, be it input sensors or output display devices are connected to the Arduino or any other microcontrollers using wired connections through a breadboard. The holes in the breadboard are in series. There are various sizes like full-sized, half-sized, and mini breadboards.

Buy Breadboard from here.


8. Screwdriver


Screwdriver
Screwdriver

It is basically a tool used for installing or removing the screws that are used in fixing machines, instruments, etc. In this circuit, we are going to use the screwdriver as a handle to control the potentiometer by rotating it.


Buy Screwdriver from here.



Circuit Type 1 - Using Arduino UNO


Circuit connections



Circuit diagram using Arduino
Circuit diagram using Arduino

The circuit connections for this device is simple to understand.


The Positive terminal of the LED is connected to the Digital PIN (3) of the #Arduino. The Negative terminal of the LED is connected to the ground line of the Breadboard through the resistor, which is assigned by connecting the GND terminal of Arduino to the hole of a particular line in the breadboard.


Similarly, another Line of the breadboard is declared as a Power supply line by connecting the 5V terminal of the LED to a hole of a particular line of the Breadboard. There are three terminals of the #Potentiometer. The first terminal is connected to the Power supply line of the Breadboard. The middle/second terminal is connected to the analog PIn (A0) of the Arduino board. The third terminal is connected to the ground line of the Breadboard.


The potentiometer is fitted with the Screwdriver that acts as a handle to control the rotation of the Potentiometer contact. Finally, the Arduino Board is interfaced with the system in which the #IDE is present and the code is written.


Code


The code description is as follows.


#define LED 3 
#define Potentio A0

Defining values using the symbol makes the value constant throughout the program execution. Two values are declared to be constant, they are the Digital PIN value that is connected to the LED, and the Analog PIN value that is connected to the second terminal of the Potentiometer.

int analogData=0;

An integer variable is declared and initialized to 0 which will further be the Analog inputs from the Potentiometer.

void setup() {
  Serial.begin(9600);

The setup( ) function is used to start the Serial communication, which is done using Serial. begin( ) function that takes in the Baud rate and assigns modes for the components connected.

 pinMode(LED, OUTPUT);                      
  pinMode(Potentio,INPUT);                  
}

The flashing of the LED is going to be controlled and seen as Output. Hence the pin mode of LED is set to be Output. The Potentiometer is going to give values as input when we vary/rotate the contact of the device. Hence assigned as Output. The setup( ) function ends here.

void loop() {
  analogData=analogRead(Potentio);            
  Serial.println(analogData); 

The loop( ) function starts and the variable "analogData" is going to store the input values from the Potentiometer which taken using the analogRead( ) function. The same input data is printed on the Serial monitor using the Serial. println( ) function.

digitalWrite(LED, HIGH);                   
  delay(analogData); 

The LED is set to HIGH using the digitalWrite( ) function at the start. Here the delay is given following the Analog value given as input from the #Potentiometer. The working of the same will be explained later.

  digitalWrite(LED, LOW);                     
  delay(analogData);                               
}

The LED is then turned OFF according to the input from the Potentiometer. by giving these delays, the #Blinking of the LED happens.


Note that the larger the delay, the slower the #LED blinks, and vice-versa.


COMPLETE CODE:


#define LED 3                                //Defining LED at pin no 3 
                                               of Arduino.
#define Potentio A0                          //Defining Potentiometer 
                                       at pin no A0 of the Arduino uno.

int analogData=0;

void setup() {
  Serial.begin(9600);                        // Started serial communication at baud rate of 9600.
   
  pinMode(LED, OUTPUT);                      // Defining LED pin as output.
  pinMode(Potentio,INPUT);                   // Defining Potentio as input.
}

void loop() {
  analogData=analogRead(Potentio);           // Reading analog data                             
                                        from analog pin of arduino uno.
  Serial.println(analogData);                // Printing analog               
                                         data recived from analog pin.
  digitalWrite(LED, HIGH);                   // turn the LED on (HIGH       
                                                is the voltage level).
  delay(analogData);                         // wait for some 
                                                     time
  digitalWrite(LED, LOW);                    // turn the LED off by 
                                             making the voltage LOW.
  delay(analogData);                         // wait for some time
}

For the complete code for this program, download the following document.


controlling_flashing_rate
.txt
TXT • 1KB

Note: Please change the file format to .ino(Arduino IDE) format before you upload the code to the Arduino board.


Working



Circuit when the LED is OFF
Circuit when the LED is OFF

The potentiometer is nothing but a resistive device that produces a continuously variable voltage output that corresponds to the change in the rotating/sliding contacts. In this circuit, the voltage is supplied to the LED from the Arduino board, and control of the supply is with the potentiometer which will send the variable voltage to the LED and causes a change in the #Flashing rate.


Looking at the working, first, the LED is glowing at the beginning of the functioning of the circuit. The potentiometer is being controlled by using a #Screwdriver as a handle. When the resistance is varied, the continuously varying voltage is given as the output of the Potentiometer. This is the Analog data read from the Potentiometer and displayed on the Serial #Monitor.


The amount of output given in terms of the #Analog Data from the Potentiometer decides the delay that is supposed to be given in between every blink or Flash of the LED. So the delay( ) function takes the analog value as a delay. We know that digital values can be only 0s and 1s. But for Analog input/output values the range is from 0 to 1023 showing the Lowest and highest possible values respectively.


The serial monitor will show the values ranging between 0 and 1023 when we rotate the potentiometer contact. So we can state that when the output voltage value from the Potentiometer is high, the higher is the delay and the Flashing rate is slower. When we control the potentiometer to decrease the output value, the delay will be less and the LED blinks at a faster Flashing Rate and every value will be seen as an output on the #Serial Monitor.


Circuit when it Powered ON
Circuit when it is Powered ON

The video given below shows an explained version of the circuit building, working of the code, and display of output for better understanding.


Project video By - Harshit Gupta



Circuit Type 2 - Using NodeMCU


Circuit connections


Circuit diagram using NodeMCU
Circuit diagram using NodeMCU

The lines for Ground and Power supply are separately selected on the Breadboard by connecting the Ground terminal and the 5V Power supply to the breadboard respectively.


The positive terminal of the LED is connected to #GPIO PIN 5 of the NodeMCU and the negative terminal of the LED is connected to the ground line of the breadboard through the resistor. The first terminal of the Potentiometer is connected to the ground line of the breadboard. The second/middle terminal is connected to the #ADC (Analog to Digital convertor) of NodeMCU and the third terminal is connected to the 5V power supply line on the breadboard.


The potentiometer is fitted with the Screwdriver that acts as a handle to control the rotation of the Potentiometer contact. Finally, the NodeMCU is interfaced with the system in which the #IDE is present and the code is written.


Code


#define LED D1                                
#define Potentio A0                          

Defining values using the symbol makes the value constant throughout the program execution. The PIN of the NodeMCU to which LED is connected is defined as D1 and the PIN of the NodeMCU to which one of the terminals of the Potentiometer is connected is defined as A0.

int analogData=0;

An integer variable is declared and initialized to 0 which will further be the Analog inputs from the Potentiometer.

void setup() {
  Serial.begin(9600);  

The setup( ) function is used to start the Serial communication, which is done using Serial. begin( ) function that takes in the Baud rate and assigns modes for the components connected.

  pinMode(LED, OUTPUT);                
  pinMode(Potentio,INPUT);               
}

The flashing of the LED is going to be controlled and seen as Output. Hence the pin mode of LED is set to be Output. The Potentiometer is going to give values as input when we vary/rotate the contact of the device. Hence assigned as Output. The setup( ) function ends here.

void loop() {
  analogData=analogRead(Potentio);            
  Serial.println(analogData);   

The loop( ) function starts and the variable "analogData" is going to store the input values from the Potentiometer which taken using the analogRead( ) function. The same input data is printed on the Serial monitor using the Serial. println( ) function.

 digitalWrite(LED, HIGH);                  
  delay(analogData);  

The LED is set to HIGH using the digitalWrite( ) function at the start. Here the delay is given following the Analog value given as input from the Potentiometer. The working of the same will be explained later.

  digitalWrite(LED, LOW);                  
  delay(analogData);                                
}

The LED is then turned OFF according to the input from the Potentiometer. by giving these delays, the Blinking of the LED happens.

Note that the larger the delay, the slower the LED blinks, and vice-versa.

COMPLETE CODE:


#define LED D1                                //Defining LED at pin no     
                                                D0 of NodeMCU
#define Potentio A0                          //Defining Potentiometer 
                                           at pin no A0 of the NodeMCU.

int analogData=0;

void setup() {
  Serial.begin(9600);                        // Started serial 
                                    communication at baud rate of 9600.
   
  pinMode(LED, OUTPUT);                      // Defining LED pin as 
                                                output.
  pinMode(Potentio,INPUT);                   // Defining Potentio as 
                                                input.
}

void loop() {
  analogData=analogRead(Potentio);           // Reading analog data 
                                               from analog pin NodeMCU.
  Serial.println(analogData);                // Printing analog 
                                          data recived from analog pin.
  digitalWrite(LED, HIGH);                   // turn the LED on (HIGH  
                                              is the voltage level).
  delay(analogData);                         // wait for some 
                                                  time
  digitalWrite(LED, LOW);                    // turn the LED off by 
                                              making the voltage LOW.
  delay(analogData);                         // wait for some 
                                                   time
}

For the complete code for this program, download the following document.


controlling_flashing_rate
.txt
TXT • 1KB

Note: Please change the file format to .ino(Arduino IDE) format before you upload the code to the Arduino board.


Working


Circuit when the LED is OFF
Circuit when the LED is OFF

The potentiometer is nothing but a resistive device that produces a continuously variable voltage output that corresponds to the change in the rotating/sliding contact. In this circuit, the voltage is supplied to the LED from the ESP8266 #NodeMCU board, and control of the supply is with the potentiometer which will send the variable voltage to the LED and causes a change in the Flashing rate.

Looking at the working, first, the LED is glowing at the beginning of the functioning of the circuit. The potentiometer is being controlled by using a Screwdriver as a handle. When the resistance is varied, the continuously varying voltage is given as the output of the Potentiometer. This is the Analog data read from the Potentiometer and displayed on the Serial Monitor.

The amount of output given in terms of the Analog #Data from the Potentiometer decides the delay that is supposed to be given in between every blink or Flash of the LED. So the delay( ) function takes the analog value as a delay. We know that digital values can be only 0s and 1s. But for Analog input/output values the range is from 0 to 1023 showing the Lowest and highest possible values respectively.

The serial monitor will show the values ranging between 0 and 1023 when we rotate the potentiometer contact. So we can state that when the output voltage value from the Potentiometer is high, the higher is the delay and the Flashing rate is slower. When we control the potentiometer to decrease the output value, the delay will be less and the LED blinks at a faster Flashing Rate and every value will be seen as an output on the Serial Monitor.


Circuit when it is Powered ON
Circuit when it is Powered ON

The video given below shows an explained version of the circuit building, working of the code, and display of output for better understanding.


Project video By - Harshit Gupta

The Flashing rate project is easy to understand, but at the same time it is has a high application rate. By this, we mean that it has been implemented in many devices and circuits. As discussed, this circuit is usually used for signaling purposes. Signaling is not only in vehicles, it can also be in Circuitry boards like Arduino, where the built-in LED flashes when the code is being uploaded to the board and stops when it is complete. Similarly, there are many applications. Find out more and use this circuit on your own devices. Kudos!!

SEE ALSO: