Delay LCD backlight turn off

Thanks a lot, Tom, seems what I need: Multivibrator - Wikipedia.

Would you recommend some precise model of transistors I can use to implement the circuit? I've never used any, before.

There isn't really a specific one, any "NPN Epitaxial Silicon" Transistor will do. The BC547 is a good choice - its sort of your bog standard NPN transistor.

An alternative would be to use an NE555 timer chip. These are 8 pin IC's which are dirt cheap and can be used to make a monostable circuit.

In this circuit a 555 is setup as a monostable circuit with an output pulse time determined by the equation:
Ton = 1.1 * R1 * C1 as shown in the image. Here is a graph to help select the resistor and capacitor:

R2 is just a pullup resistor for the push button in that diagram, so a resistor of anywhere between 10k and 100k should do nicely.

The 555 is capable of sourcing 200mA of current which should be more than enough for the backlight. This means you could just connect the anode of the backlight to pin 3 of the NE555 and the cathode via a suitably sized resistor to ground.

If you use a 555 its best to avoid the original 555's and choose a CMOS version instead, the original 555's need massive decoupling capacitors (100uF electrolytic + 10uF ceramic is about right - the chip glitches upto 0.4A !!). ICM7555 can only provide 100mA only though but doesn't crowbar the supply voltage in this way.

but consumes two pins of the Arduino

Do you have one analog pin available? You can use one analog pin as an input and output at the same time with some clever code. Basically you read switch as an input a few times a second, then switch it to an output for the rest of the time:

Sample code: (run this a few times a second in your main loop):

    digitalWrite(analogpin, LOW);     //turn off LED
    pinMode(analogpin, INPUT);    //change the pin to input
    backlightread = analogRead(analogpin);
    backlightread = analogRead(analogpin); //take a second reading to let the ADC stabilize
    if (backlightread >400) backlight = TRUE; else backlight = FALSE;        
    pinMode(analogpin, OUTPUT);      //change pin back to output
    digitalWrite(analogpin, backlight);    //write the current backlight status to the pin

one pin.png

I am curious, don't you control the backlight on/off already via an arduino pin? so why you need to use another pin? or is the button you refer to not connected to the arduino? It sounds like it is, since you say it is software controlled and uses 2 pins. backlight control needs only one pin. what is the second pin used for?

Thanks for all your suggestions! I've just been at my local electronics store and bought both a few 555's and a few BC547's, I'll experiment with both and see what I come up with!

@MarkT: Unfortunately they had no ICM7555. I was actually given ST SA555N. Are they any better than the original NE555's? I paid € 0,50 each. I also bought a few capacitors (0,60 each, not so cheap!), where would you recommend putting them with the SA555N? Oh, and the 10 uF I got are electrolytic, can I use these instead of the ceramic ones (which I thought were only in the pF range)?

@John_S: Very clever :): I'll try your trick, for curiosity's sake, but unfortunately I can't use it in the actual project, as I have no pins left at all.

@doughboy: I need two pins because the backlight is normally off and only gets switched on temporarily at the press of a button. So I need one input for the button and one output for the backlight.

SukkoPera:
@doughboy: I need two pins because the backlight is normally off and only gets switched on temporarily at the press of a button. So I need one input for the button and one output for the backlight.

If you can use software to turn the backlight on when switch is pressed, couldn't you just use software to turn the backlight off after a certain time delay?
I have a similar setup where the backlight is turned off after 60 seconds and comes on by pressing any key.

I've never had any issue with the NE555 (or SA555, both are the same).

If you connect it up in the circuit I posted, put your 10uF capacitor between +5v and GND (the - on the electrolytic goes to ground), then you shouldn't have a problem.

Ceramic capacitors tend to be available from 10pF all the way up to 470nF. I have seen some at 1uF and 4.7uF before. Generally for anything higher than that, you use Electrolytic anyway.

I've built both versions with success! A couple pics:


(Please don't mind about wire colors, I'd run out of jumpers!)

I tend to prefer the 555 version, it is much easier to choose the R/C values to achieve the desired timing.

PS: What's the difference between ceramic and electrolytic capacitors then? How should I choose?

Yes, you can use a 555 or similar and a few resistors and capacitors to do the delay; but what's wrong with doing the delay in software? That's the modern way to do it. The whole point of microcontrollers is that they replace a pile of electronic components with one microcontroller and some software.

If you are short of pins, and the push button is used only to turn the backlight on, you can use a single pin both to detect the button push and control the backlight.

Just to clarify: I'm perfectly fine doing the delay in software, it was my first thought and that's what I'm doing now. It was even a good excuse to use interrupts :).

The point is that I started testing this LCD stuff on a small side-project, where I have lots of spare pins, but the real goal is to use the LCD in another project, where unfortunately I've run out of pins. There the board is a KMtronic DINo, which drives 4 relays and an ENC26J80. It only exposes D0/D1 (Used for serial data exchange), D2 (which I use to read a digital thermometer) and A0/A1, which I'll be using to drive the LCD via a two-wire protocol through a shift register. It has no other pins. At the beginning I was planning to light the display through a button wired directly to Vcc, but it has the "inconvenience" that you have to keep the button pressed. Since I can add a delay with just € 0,50, I guess I'll go that way :).

The difference between electrolytic and ceramic is to do with the materials used.

A ceramic capacitor stores charge on two metal plates seperated by a piece of ceramic material (or in some cases an air gap) of a specific thickness. The size of the plates determines the capacitance, which is why capacitances larger than around 1uF become impractical - you would have to have a massive capacitor.

An electrolytic capacitor uses the same two plates, however it adds an electrolyte which is a material that contains a large number of free ions - essentially atoms which have had some of their outer electrons stripped away. The material is either a liquid (cheap, but eventually can leak out - which is bad), or a solid (expensive, but wont leak so used in harsh environments or high end electronics equipment). Because of the electrolyte, there is an electric feild inbuilt within the capacitor which essentially increases the amount of electrons which can be stored on the plates, leading to a much larger capacitance for a given size.
Depending on the electrolyte used, these can be polarised. Aluminum oxide is a commonly used material as it is what is called a 'dielectric' material (to do with the atomic structure). The problem with this material is that if the polarity of the electric field inside the capacitor is incorrect, the oxide will break down and thus cause the plates to short out (BOOM?!?).

SukkoPera:
Just to clarify: I'm perfectly fine doing the delay in software, it was my first thought and that's what I'm doing now. It was even a good excuse to use interrupts :).

The point is that I started testing this LCD stuff on a small side-project, where I have lots of spare pins, but the real goal is to use the LCD in another project, where unfortunately I've run out of pins. There the board is a KMtronic DINo, which drives 4 relays and an ENC26J80. It only exposes D0/D1 (Used for serial data exchange), D2 (which I use to read a digital thermometer) and A0/A1, which I'll be using to drive the LCD via a two-wire protocol through a shift register. It has no other pins. At the beginning I was planning to light the display through a button wired directly to Vcc, but it has the "inconvenience" that you have to keep the button pressed. Since I can add a delay with just € 0,50, I guess I'll go that way :).

I still don't get it, you are not using any extra pins by using software. I use I2C interface to LCD+keypad (using mcp23017) and all I use is the two i2c pins. you don't need to use any more pins that what you already need just to drive the lcd. not sure why the need to do things the hard way.

I'm not driving the LCD through i2c at the moment. I am using the New Liquid Crystal library by Francisco Malpartida and I don't think it allows me to control the backlight, so I am using an "external" wiring for it. I2C communication happend on A4/A5, if I'm not mistaken, which I can't access on my board.

@Tom: Thanks for the explanation, but I actually knew how the different types of capacitors are made :). I was rather willingly to know what the difference is on the practical side, but I seem to understand it's mainly a difference in the capacity range right?

SukkoPera:
I was rather willingly to know what the difference is on the practical side, but I seem to understand it's mainly a difference in the capacity range right?

The other significant differences are the leakage current and ESR (effective series resistance), which are both generally much higher for aluminium electrolytic capacitors than for ceramic or metallised film capacitors. The ESR is why it is common to put a 100nF ceramic capacitor in parallel with an aluminium electrolytic.

Thanks a lot. This thread has been very helpful for me! :slight_smile:

Hi Arduino Peeps:

To switch the LCD backlight off and on rather use the following:
![](http://C:\D&S Innovative Electronic Solutions\Contracts\Mr Kallis\Backlight_Control.jpeg)
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
transistor.
The following calculations:
Calculate R1:
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;

void setup()
{
//No need to setup analogue pin
}

void loop()
{
//Switch the analogue pin A0 high for a short time
digitalWrite(backLight, HIGH);
delay(1000);
//Switch the analogue pin A0 off
digitalWrite(backLight, LOW);
delay(1000);
}

Backlight_Control.jpg

You can use a phi-panel serial LCD back pack that I am selling. It will give you full control of the lcd and back light, and senses as many as 16 keys on a key pad, or one key that you currently have. You won't need anyone's library. All you need is to hook it up to arduino hardware serial port. The rest of the pins are free to do anything.