LED Brightness Control with Arduino

The LCD (16×2) to display the LED brightness. Shortly, in this project we’ll control an LED brightness using a potentiometer.

The LED brightness will be displayed on the LCD screen using a progress bar.

Introducing the LCD:

The simplest and inexpensive way to display information is with an LCD (liquid crystal display).

Circuit Diagram:

These are found in everyday electronics devices such as vending machines, calculators, parking meters, printers, and so on.

These are ideal for displaying text or small icons. The figure below shows a 16×2 LCD front and pin details.

This LCD has 2 rows, and each row can display 16 characters. It also has LED backlight to adjust the contrast between the characters and the background.

The next table shows a brief description of each pin of the LCD display.

Sr. No Pin No. Pin Name Pin Type Pin Description Pin Connection
1 Pin 1 Ground Source Pin This is a ground pin of LCD Connected to the ground of the MCU/ Power source
2 Pin 2 VCC Source Pin This is the supply voltage pin of LCD Connected to the supply pin of Power source
3 Pin 3 V0/VEE Control Pin Adjusts the contrast of the LCD. Connected to a variable POT that can source 0-5V
4 Pin 4 Register Select Control Pin Toggles between Command/Data Register Connected to a MCU pin and gets either 0 or 1. 0 -> Command Mode 1-> Data Mode
5 Pin 5 Read/Write Control Pin Toggles the LCD between Read/Write Operation Connected to a MCU pin and gets either 0 or 1. 0 -> Write Operation 1-> Read Operation
6 Pin 6 Enable Control Pin Must be held high to perform Read/Write Operation Connected to MCU and always held high.
7 Pin 7-14 Data Bits (0-7) Data/Command Pin Pins used to send Command or data to the LCD. In 4-Wire Mode Only 4 pins (0-3) is connected to MCU In 8-Wire Mode All 8 pins(0-7) are connected to MCU
8 Pin 15 LED Positive LED Pin Normal LED like operation to illuminate the LCD Connected to +5V
9 Pin 16 LED Negative LED Pin Normal LED like operation to illuminate the LCD connected with GND. Connected to ground

LED Brightness control Code:
Copy the following code and upload it to your Arduino board.

The code is well commented so that you can easily understand how it works, and modify it to include in your own projects.

include LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int potPin = A0; int ledPin = 6;
int potValue = potentiometer
int brightness = 0;
int i = 0;

pBar[8] =
{
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};

void setup()

{
OUTPUT pinMode(ledPin, OUTPUT);
rows: lcd.begin(16, 2);
LCD lcd.print(" LED Brightness");
lcd.createChar(0, pBar);
}
void loop() 
{
lcd.clear();

lcd.print(" LED Brightness");
lcd.setCursor(0,1);
potValue = analogRead(potPin);

brightness=map(potValue, 0, 1024, 0, 255);
bightness analogWrite(ledPin, brightness);
pBari=map(brightness, 0, 255, 0, 17);
bar for (i=0; i<pBari; i++)
{
lcd.setCursor(i, 1); lcd.write(byte(0));
}
delay(750);
}

Subramanian
Subramanian

Subramanian MK, currently serving as a workshop instructor at Sakthi Polytechnic College, Erode Tamil Nadu. With a career spanning 25 + years, Subramanian MK has dedicated himself to advancing knowledge in Electronics and Communication Engineering (ECE). His passion for exploring new technologies has led to the development of numerous projects, showcasing expertise in IoT and PCB design.

Articles: 504

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

×

Hi, How can I help you?

×