5
votes

How to dim the backlight on an 20x4 LCD Display with the i2c connected to an Arduino uno?

I use the LiquidCrystal_I2C.h library and I can turn on and of the light with lcd.backlight(); and lcd.noBacklight();

But I don't want to turn off completely the backlight: I want to dim it.

3
Arduino has its own stackexchangewhackamadoodle3000
Please add information on your hardware setup.Gerhard

3 Answers

0
votes

Simple answer : You can't.

Complex Answer : You can use a BJT controlled by PWM to change/adapt the brightness.

4
votes

Maybe a bit late, but I’d like to note that it is certainly possible to dim the backlight on LCDs that come with an I2C adaptor. It’s as simple as wiring the upper pin (the one labeled LED) of the I2C board to a PWM pin in the Arduino. Using analogWrite() will vary the LED brightness from 0 (LED off) to 255.

Here’s a simple sketch (for a 16 x 2 LCD) to demonstrate this:

#include <LiquidCrystal_I2C.h>

#define BRIGHTNESS_PIN      6   // Must be a PWM pin

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

byte brightness = 0;
bool sense = 1;

void setup()
{
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    lcd.print("Here's some text");
}

void loop()
{
    analogWrite(BRIGHTNESS_PIN, brightness);
    delay(10);

    if(sense) {
        if(brightness < 255) {
            brightness++;
        } else {
            sense = 0;
        }
    } else {
        if(brightness > 0) {
            brightness--;
        } else {
            sense = 1;
        }
    }
}
0
votes

U can play around with lcd.backlight(); and lcd.noBacklight();

example

lcd.backlight(); delay(1); lcd.noBacklight(); delay(1);

It dims!