Hi Arduino Peeps:
To switch the LCD backlight off and on rather use the following:
I used a 2N2222 NPN transistor with hFE = 75; R1 works out to be 1 Ohm and R2 = 3.9K. This allows for a collector current, which flows through the backlight, of 85 mA. This is enough to light up most LCDs (16 x 2 character).
The code is simple. I use analog pin, A0. Just to test your setup:
/* Author: Solomon Smit
Date: 23 Nov 2012
This code is just to test the backlight on-off setup using a NPN
The following calculations:
Check the datasheet of the LCD what is the forward voltage drop
of the backlight. Normally between 4.2V - 4.9V.
Mine, the LMB162ABC is 4.9V.
Also check the forward current (max) for the backlight.
Mine is 150 mA.
Now: Ohm's Law:
R1 = (5 - 4.9)/0.150 = 0.67 Ohm.
Choose R1 = 1 Ohm
Implies, Iforward = (5-4.9)/1 = 100 mA.
Now Choose Transistor, Q1:
I use 2N2222A, with hFE = 75 for Vcc = 5V at 150mA;
Now Calculate R2:
Ieb = (Iec/hFE)
Ieb = 0.1/75 = 1.33 mA
Thus, R2 = 5/0.00133 = 3 759 Ohm
Choose R2 = 3.9k;
int backLight = A0;
//No need to setup analogue pin
//Switch the analogue pin A0 high for a short time
//Switch the analogue pin A0 off