“While working on a new project Ive came across a problem where I wanted to control the backlight and the contrast of an 1602 LCD display through an Arduino but the display was really flickery.
In a typical use case, the display contrast is adjusted through a variable resistor as per the datasheet. In such case, through the resistor we can adjust the voltage that is seen on the V0 pin and the contrast is adjusted accordingly. With the Arduino, the best thing we can output is a PWM signal with a different cycle but unfortunately the module is not happy displaying that.
Before going into the schematic how we can fix this, let me explain you the code that I’m using.
The first thing we need to do is to include the Liquid Crystal library so we can connect to the display. Next, we setup the LCD with the pins that we have our display connected to and additionally we define the pins that we have our backlight and contrast pins connected to. The contrast control pin on the display is V0 and it is connected to pin 6 on the Arduino and the backlight control pin is marked as A and since this is basically an LED, it is connected through a 220 Ohm resistor to pin 10 on the Arduino.
In the Setup function we first set the brightness on the display to the max and then we start communication with the LCD. To make sure that it is working correctly, we display a message of “hello world” and we wait for about half a second so we can verify that the output is OK.
Very often, depending on the state of the V0 pin, you might face the issue of not having anything displayed even though the expectation was different. The reason for this is the contrast pin value. If the contrast is set too high, the display is barely visible so we need to decrease it.
In the loop section of the code we first clear out the contents of the LCD and since we gonna programmatically change the contrast we display a text and in a loop we update the pin output and display the current value to the display on the second row.”