can your lcd do this - lcd brightness control with pwm

Control the Brightness of an LCD Backlight using PWM with Arduino

You’ve probably seen the brightness control on your TV or PC monitor, but how do you do the same thing with your LCD projects without the need to manually adjust a variable resistor. Well we can easily control the brightness of an LCD backlight using PWM.

Using pulse width modulation allows you to vary power by changing the pulse width size. In this way we can either increase or reduce power to the LED backlight of an LCD display and vary it’s brightness.

In this tutorial, we will build a circuit using an arduino board connected to an LCD display and use one of the microcontroller pins to change the brightness of the LCD’s LED backlight.

 

 

 

How do you adjust the LCD Backlight Brightness

Adjusting the LCD brightness with the push of a button can quite easily be done by using the pulse wide modulation function of a microcontroller. We use this function, with a set number of brightness presets and a push button so the user can change them.

Components needed to Control the LCD Backlight

To do this project, we need a few components, starting with an Arduino board:

  • Arduino UNO board
  • LCD Display (1602)
  • Push button
  • 47k ohm resistor (I’ve chosen 47k as that was what I had)
  • 10k variable resistor
  • Breadboard
  • Hookup wire.

Wiring up the LED brightness control circuit

We then wire up the circuit following the schematic below.

 

schematic of lcd brightness control

 

Code to Contol the LED Brightness

Then we upload the following source code to the board.

 

#include <LiquidCrystal.h>

LiquidCrystal lcd(8,9,4,5,6,7);
int backlight_pin10 = 10;
int brightness = 128;
int button1 = 2;
int buttonState = 0;

void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print(“Backlight”);
lcd.setCursor(0,1);
lcd.print(“Brightness”);

pinMode(backlight_pin10, OUTPUT);         // sets pin10 as output
pinMode(button1, INPUT);

}

void loop() {

analogWrite(backlight_pin10,brightness);  // PWM values from 0 to 255 (0% – 100% duty cycle)

buttonState = digitalRead(button1);
delay(200);

if (brightness == 256)
{
brightness = 0;
}

if (buttonState == HIGH)
{
brightness = brightness + 32;

}

}
The source code uses the analogWrite command, to utilize the pulse width modulator function where we feed the pulse from pin 10 to  the LCD display’s backlight LED power pin.

There are 256 levels of brightness we can use.  Where level 0 is the lowest that turns the backlight fully off, to 255 which turns the backlight fully on.

In this example we initially set the PWM to 128 which is the 50% brightness level. This is so there is some backlight brightness to initially be able to read the LCD display.  Then when the user sees fit, they can change the LCD’s brightness by pressing the brightness button repeatedly until the brightness reaches the desired level. Each time the button is pressed, the brightness variable is incremented by the number 32. Using the number 32 gives the user 8 levels of brightness to choose from.

We also put in a condition statement (if  statement) to detect when the brightness variable reaches over 255. Once the brightness variable is larger than 255, it is reset back to 0 and switches the backlight off.  This is done so the user can cycle through all brightness levels using only one button. The user just keeps pressing the button until the brightness level they want is reached.

So now you know how to make an LCD backlight brightness control for your projects.

 

Control the Brightness of an LCD Backlight using PWM with Arduino | Summary

Using the PWM function of the microcontroller allows us to change an LED brightness level programmatically with the use of an external variable resistor. It is a nice elegant solution to just press a button instead of turning a knob to adjust screen brightness.

Thanks for spending your time to read this article. If you haven’t already watched the embedded video tutorial above, I suggest you might like to watch it to see the project working in practice.

Please also subscribe to the Smart Microcontroller Channel to be the first to know when my latest electronics videos are released !