control display backlighting in software for Sainsoft LCD2004 I2C

I'm making a prototype home automation gizmo with a brand new Arduino Uno (Rev. 3), a Sainsmart LCD2004 I2C display, and a three button interface menu system.

I want to be able to adjust backlighting of the LCD in software besides just on and off. Maybe the best idea would be to have it automatically dim in low lighting via a light sensor, but for now I'd like to just give the user an option to cycle through choices of "high" --> "medium" --> "low" --> "off" --> "high" (etc.), and to have it dim after 5 minutes of inactivity.

I spent several hours just getting the LCD to work-- AND by the way: MANY thanks to the advice of many who've gone through this lonely valley of hell before me (sellers not really supporting their products, as fm says). So now, after many hours of scouring the forums and elsewhere for hints on backlighting, I find myself asking for more specific advice.

Does anyone know how I control backlighting via software? Is it a simple undocumented command? I hope so.

I've read some old posts about how you need to connect the backlight via an NPN transistor to an analog pin and vary the voltage, so I am starting to think this is a hardware and software problem...

Here's a picture of an identical I2C "backpack" board. On the right are the four pins for I2C, power and ground. On the left are two pins connected with a slip-on jumper. I pulled the jumper off on mine and saw the backlight go off, so I assume this is where I would connect the transistor. The upper pin is connected via a trace to pin 15 on the LCD board, and the lower pin is connected to the bottom left pin of the PCF8574T IC. I found a 2N4401 NPN transistor from dipmicro. Would that work? How do I connect it?

Thanks in advance for your help. Sorry for being such a total newbie, and for asking several questions in one post. This is my first post, my first Arduino project, and I am excited about joining this supportive community of DIYers.

--sam

OK, I generally point out that you are unlikely to need more than two brightness levels. This may be ON and OFF, or may be bright and dim. I doubt you need four levels, but maybe three if you want to allow for day and night use, and turn it off to "save power" (generally only ever meaningful if you are operating from batteries).

Not having the time to look through my display library for that particular module, all you need to do is to connect a 1k resistor from an Arduino pin to whichever side of the LED that is switched - pin 15 or 16. In fact, just try each connection and see what happens, the 1k resistor cannot do any damage. Adjust the resistor value to suit your intermediate brightness, minimum 330 Ohms.

Thank you Paul__B. Your solution has beauty in its simplicity. So, please tell me if I understand correctly: If I wanted two levels of dimness, I could connect two different resistors from pin 15 (or 16) of the display to two separate digital pins on the Arduino, then in the sketch tell it to digitalWrite "HIGH" to either of the pins to select the dimness level.

Still, I think it might look cool to have the backlight fade gradually, but is it worth the extra coding?

thanks again, --sam

swinch: Still, I think it might look cool to have the backlight fade gradually, but is it worth the extra coding?

That, is for you to decide. :grinning:

Yes, and I've decided I will buy that NPN transistor and experiment with it to see if I can make it work. Once I figure it out I will report back, in case anyone else may want to know how to do this. Thanks again.

I followed Paul__B’s suggestion, pulled the LED jumper off my 2004A and put 5V on each pin through a 330Ohm resistor. In my case it was the pin closest to the edge of the board that drove the backlight.

For grins I hooked it up to Pin 3 (PWM capable) on my ARD and ran the following sketch. Yes, you can dim the backlight with a PWM output through a resistor. I don’t think it’s quite as bright when full on but works great for my needs, this is a total vanity thing but also had this itch to scratch.

Run the sketch, attach to serial, determine what your desired ranges are and bias your code accordingly.

#define LCD 3
int i;

void setup()
{
Serial.begin(115200);
pinMode(LCD,OUTPUT);
}

void loop()
{
for (i = 0; i < 26; i++) {
int bright = i * 10;
analogWrite(LCD,bright);
Serial.println(bright);
delay(500);
}
}

Cheers!

leem