Jump to content

LED Blinking: Difference between revisions

From cognifront
CogWikiEditor (talk | contribs)
CogWikiEditor (talk | contribs)
No edit summary
Line 1: Line 1:
===Interfacing LED Bar with ESP32===
===Interfacing LED Bar with Arduino UNO===


'''Interfacing LED Bar with ESP32''' demonstrates how an LED bar can be connected to an ESP32 board and controlled using digital output pins.
'''Interfacing LED Bar with Arduino UNO''' demonstrates how an LED bar can be connected to an Arduino UNO board and controlled using digital output pins.


An '''LED''' (Light Emitting Diode) is a semiconductor device that emits light when it is forward biased.
An '''LED''' (Light Emitting Diode) is a semiconductor device that emits light when it is forward biased.
Line 10: Line 10:
* '''Cathode (−)''' – negative terminal
* '''Cathode (−)''' – negative terminal


A current-limiting resistor is used while interfacing LEDs with the ESP32 to limit the current flowing through the LED.
A current-limiting resistor is used while interfacing LEDs with the Arduino UNO to limit the current flowing through the LED.


== Introduction to LED ==
== Introduction to LED ==
Line 31: Line 31:
|}
|}


A current-limiting resistor is connected between the LED and the ESP32 board to limit the current.
A current-limiting resistor is connected between the LED and the Arduino UNO to limit the current.


== LED Bar ==
== LED Bar ==
Line 72: Line 72:
== Connections ==
== Connections ==


The LED bar is interfaced with the ESP32 using four digital data pins.
The LED bar is interfaced with the Arduino UNO using four digital data pins.


{| class="wikitable"
{| class="wikitable"
! Device
! Device
! Pin
! Pin
! ESP32
! Arduino UNO
! Function
! Function
|-
|-
| LED Bar
| LED Bar
| Data Pin 1
| Data Pin 1
| ESP32 GPIO
| D3
| LED control
| LED control
|-
|-
| LED Bar
| LED Bar
| Data Pin 2
| Data Pin 2
| ESP32 GPIO
| D4
| LED control
| LED control
|-
|-
| LED Bar
| LED Bar
| Data Pin 3
| Data Pin 3
| ESP32 GPIO
| D12
| LED control
| LED control
|-
|-
| LED Bar
| LED Bar
| Data Pin 4
| Data Pin 4
| ESP32 GPIO
| D13
| LED control
| LED control
|-
|-
| LED Bar
| LED Bar
| VCC / Common Anode
| VCC / Common Anode
| Supply
| +5V
| Power
| Power
|-
|-
Line 110: Line 110:
| Ground
| Ground
|}
|}
'''Note:''' The exact ESP32 GPIO numbers depend on the circuit/program used for the practical.


== Current Limiting Resistor ==
== Current Limiting Resistor ==
Line 117: Line 115:
A current-limiting resistor is used with the LED to prevent excessive current from flowing through it.
A current-limiting resistor is used with the LED to prevent excessive current from flowing through it.


The resistor is connected between the LED and the ESP32 output.
The resistor is connected between the LED and the Arduino UNO output.


The resistor helps protect the LED and the ESP32 GPIO from excessive current.
The resistor helps protect the LED and the Arduino UNO digital output from excessive current.


== Safety Precautions ==
== Safety Precautions ==
Line 128: Line 126:
* Check the polarity of the LED bar.
* Check the polarity of the LED bar.
* Ensure that the connections are correct before applying power.
* Ensure that the connections are correct before applying power.
* Then connect the ESP32 board to the PC or laptop.
* Then connect the Arduino UNO board to the PC or laptop.
* Do not connect the LED directly to an ESP32 GPIO without suitable current limiting.
* Do not connect the LED directly to an Arduino UNO digital output without suitable current limiting.


== Interfacing Diagram Using Breadboard ==
== Interfacing Diagram Using Breadboard ==


The LED bar is connected to the ESP32 through the required data pins.
The LED bar is connected to the Arduino UNO through the required data pins.


The LED bar's common terminal is connected according to its configuration.
The LED bar's common terminal is connected according to its configuration.
Line 171: Line 169:


<center>
<center>
'''ESP32 → Digital Output Pins → LED Bar → LEDs ON/OFF'''
'''Arduino UNO → Digital Output Pins → LED Bar → LEDs ON/OFF'''
</center>
</center>


== Working ==
== Working ==


The ESP32 controls the LED bar using digital output pins.
The Arduino UNO controls the LED bar using digital output pins.


During operation, the program alternately changes the state of the LED control pins.
During operation, the program alternately changes the state of the LED control pins.
Line 192: Line 190:
</center>
</center>


The process repeats continuously, causing the LED bar to change between its two output states at one-second intervals.
The process repeats continuously, causing the LED bar to change between its two output states.


== Timing ==
== Timing ==


The LED bar is controlled with a delay of '''one second''' between the two output states.
The LED bar is controlled with a delay of '''one second''' between the first output state and the second output state.
 
The program uses a '''1000 ms''' delay when the LEDs are HIGH and a '''500 ms''' delay when the LEDs are LOW.


The sequence is:
The sequence is:


<center>
<center>
'''All Pins HIGH → 1 second delay → All Pins LOW → 1 second delay → Repeat'''
'''All Pins HIGH → 1000 ms delay → All Pins LOW → 500 ms delay → Repeat'''
</center>
</center>


== Program Codes ==
== Program Codes ==
<pre>
<pre>
#define LED_PIN 3
#define LED_PIN 3
Line 234: Line 235:


</pre>
</pre>
== Observation ==
== Observation ==


After connecting the ESP32 to the LED bar and running the program, observe the LED bar output.
After connecting the Arduino UNO to the LED bar and running the program, observe the LED bar output.


The LED control pins alternate between '''HIGH''' and '''LOW''' states.
The LED control pins alternate between '''HIGH''' and '''LOW''' states.


The output changes after every '''one second'''.
The LEDs remain in the HIGH state for '''1000 ms''' and in the LOW state for '''500 ms'''.


The LEDs turn ON or OFF according to the configuration of the LED bar and the logic applied to its control terminals.
The LEDs turn ON or OFF according to the configuration of the LED bar and the logic applied to its control terminals.
Line 246: Line 248:
== Result ==
== Result ==


The ESP32 successfully interfaces with the LED bar and controls the LED output using digital GPIO pins.
The Arduino UNO successfully interfaces with the LED bar and controls the LED output using digital GPIO pins.


The LED bar output alternates between the two programmed states with a delay of one second.
The LED bar output alternates between the two programmed states with a '''1000 ms''' HIGH duration and a '''500 ms''' LOW duration.

Revision as of 17:17, 3 September 2026

Interfacing LED Bar with Arduino UNO

Interfacing LED Bar with Arduino UNO demonstrates how an LED bar can be connected to an Arduino UNO board and controlled using digital output pins.

An LED (Light Emitting Diode) is a semiconductor device that emits light when it is forward biased.

An LED has two terminals:

  • Anode (+) – positive terminal
  • Cathode (−) – negative terminal

A current-limiting resistor is used while interfacing LEDs with the Arduino UNO to limit the current flowing through the LED.

Introduction to LED

LED stands for Light Emitting Diode.

An LED is a p-n junction diode that emits light when it is forward biased.

The typical characteristics considered for the LED in this practical are:

Parameter Value
Required voltage Approximately 1.7 V
Required current 5–20 mA

A current-limiting resistor is connected between the LED and the Arduino UNO to limit the current.

LED Bar

An LED bar consists of multiple LEDs arranged together in a single package.

In this practical, the LED bar contains 4 LEDs.

The LEDs can be controlled by applying suitable digital signals to their terminals.

The LED bar can have two commonly used configurations:

  1. Common Anode
  2. Common Cathode

Common Anode

In a Common Anode LED bar, the anode terminals of all the LEDs are connected together and connected to the positive supply VCC.

The individual LEDs are controlled through their cathode terminals.

Common Anode → VCC (+5 V)

By controlling the cathode terminals, the individual LEDs can be switched ON or OFF.

Common Cathode

In a Common Cathode LED bar, the cathode terminals of all the LEDs are connected together and connected to Ground (0 V).

The individual LEDs are controlled through their anode terminals.

Common Cathode → Ground (0 V)

By controlling the anode terminals, the individual LEDs can be switched ON or OFF.

Connections

The LED bar is interfaced with the Arduino UNO using four digital data pins.

Device Pin Arduino UNO Function
LED Bar Data Pin 1 D3 LED control
LED Bar Data Pin 2 D4 LED control
LED Bar Data Pin 3 D12 LED control
LED Bar Data Pin 4 D13 LED control
LED Bar VCC / Common Anode +5V Power
LED Bar GND / Common Cathode GND Ground

Current Limiting Resistor

A current-limiting resistor is used with the LED to prevent excessive current from flowing through it.

The resistor is connected between the LED and the Arduino UNO output.

The resistor helps protect the LED and the Arduino UNO digital output from excessive current.

Safety Precautions

  • First, make all the connections according to the circuit diagram.
  • Check the LED bar configuration before connecting the supply.
  • Use a suitable current-limiting resistor with the LEDs.
  • Check the polarity of the LED bar.
  • Ensure that the connections are correct before applying power.
  • Then connect the Arduino UNO board to the PC or laptop.
  • Do not connect the LED directly to an Arduino UNO digital output without suitable current limiting.

Interfacing Diagram Using Breadboard

The LED bar is connected to the Arduino UNO through the required data pins.

The LED bar's common terminal is connected according to its configuration.

For a Common Anode LED bar, the common anode is connected to the positive supply.

For a Common Cathode LED bar, the common cathode is connected to ground.

Configuration Common Terminal LED Control
Common Anode VCC Cathode terminals
Common Cathode GND Anode terminals

Algorithm

The following algorithm is used to interface and control the LED bar:

  1. Start the Arduino IDE.
  2. Declare integer variables for the four data pins of the LED bar.
  3. In the void setup(), configure all the LED pins as OUTPUT.
  4. In the void loop(), make all the LED pins HIGH.
  5. Give a delay of one second.
  6. Make all the LED pins LOW.
  7. Give a delay of one second.
  8. Repeat the process continuously.

The overall operation is:

Arduino UNO → Digital Output Pins → LED Bar → LEDs ON/OFF

Working

The Arduino UNO controls the LED bar using digital output pins.

During operation, the program alternately changes the state of the LED control pins.

First, all the required LED pins are made HIGH.

HIGH → LED control

After a delay of one second, all the LED pins are made LOW.

LOW → LED control

The process repeats continuously, causing the LED bar to change between its two output states.

Timing

The LED bar is controlled with a delay of one second between the first output state and the second output state.

The program uses a 1000 ms delay when the LEDs are HIGH and a 500 ms delay when the LEDs are LOW.

The sequence is:

All Pins HIGH → 1000 ms delay → All Pins LOW → 500 ms delay → Repeat

Program Codes

#define LED_PIN 3
#define LED_PIN1 4
#define LED_PIN2 12
#define LED_PIN3 13

void setup()
{
  pinMode(LED_PIN, OUTPUT);
  pinMode(LED_PIN1, OUTPUT);
  pinMode(LED_PIN2, OUTPUT);
  pinMode(LED_PIN3, OUTPUT);
}

void loop()
{
  digitalWrite(LED_PIN, HIGH);
  digitalWrite(LED_PIN1, HIGH);
  digitalWrite(LED_PIN2, HIGH);
  digitalWrite(LED_PIN3, HIGH);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  digitalWrite(LED_PIN1, LOW);
  digitalWrite(LED_PIN2, LOW);
  digitalWrite(LED_PIN3, LOW);
  delay(500);
}

Observation

After connecting the Arduino UNO to the LED bar and running the program, observe the LED bar output.

The LED control pins alternate between HIGH and LOW states.

The LEDs remain in the HIGH state for 1000 ms and in the LOW state for 500 ms.

The LEDs turn ON or OFF according to the configuration of the LED bar and the logic applied to its control terminals.

Result

The Arduino UNO successfully interfaces with the LED bar and controls the LED output using digital GPIO pins.

The LED bar output alternates between the two programmed states with a 1000 ms HIGH duration and a 500 ms LOW duration.