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. NoPin No.Pin NamePin TypePin DescriptionPin Connection
1Pin 1GroundSource PinThis is a ground pin of LCDConnected to the ground of the MCU/ Power source
2Pin 2VCCSource PinThis is the supply voltage pin of LCDConnected to the supply pin of Power source
3Pin 3V0/VEEControl PinAdjusts the contrast of the LCD.Connected to a variable POT that can source 0-5V
4Pin 4Register SelectControl PinToggles between Command/Data RegisterConnected to a MCU pin and gets either 0 or 1. 0 -> Command Mode 1-> Data Mode
5Pin 5Read/WriteControl PinToggles the LCD between Read/Write OperationConnected to a MCU pin and gets either 0 or 1. 0 -> Write Operation 1-> Read Operation
6Pin 6EnableControl PinMust be held high to perform Read/Write OperationConnected to MCU and always held high.
7Pin 7-14Data Bits (0-7)Data/Command PinPins 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
8Pin 15LED PositiveLED PinNormal LED like operation to illuminate the LCDConnected to +5V
9Pin 16LED NegativeLED PinNormal 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: 514

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?

×