Driving LCD backlight and contrast ping by Arduino - Page 1
Forum section: electronics / beginners

author: VEGETA
author_rank: Super Contributor
timestamp: April 23, 2018, 09:10:22 pm
content: Dear Friends,I have a finished project with Arduino that contains LCD 16x2, I just need the Arduino to control the contrast and brightness to allow user to adjust brightness the way needed.I thought of outputting PWM then filtered by 330 ohm + 330uF capacitor but it didn't work as I expected. Although I am outputting (PWM = 255) the output of the RC filter is about 3~3.5v while at the Arduino pin itself is 5v. So I thought perhaps current is not enough or so because a drop voltage happened.I am powering my circuit by USBtinyISP programmer right now, so could it be the case? that it does not give enough power to circuit?best regards,

author: BrianHG
author_rank: Super Contributor
timestamp: April 23, 2018, 10:24:12 pm
content: As a test, disable the PWM on that IO pin and just set it to high. See if you get 5V. Measure the voltage across the resistor, maybe something is drawing too much current.

author: VEGETA
author_rank: Super Contributor
timestamp: April 23, 2018, 10:26:05 pm
content: Quote from: BrianHG on April 23, 2018, 10:24:12 pmI will test it tomorrow.I think the +5v pin gives enough but I wanted adjustable back light so PWM is a must. However, what values for RC filter?

author: BrianHG
author_rank: Super Contributor
timestamp: April 23, 2018, 10:32:15 pm
content: This is the reason for measuring the voltage across the 330Ohm resistor. I want to know if you are drawing ridiculous current for no reason. I would have chosen 1k or 10k with 100uf or 10uf. However, we first want to know why the output isn't reaching 5v. Those LCD contrast inputs are usually very-very low current.An example would be having the 330uf cap reverse in polarity, or, it being a 4v cap. Going with a higher voltage cap, like 10uf 16v, means at 5v, there will still be practically no current at all.Be careful of low ESR caps in this application, their current is much higher than cheap aluminum electrolytic, but, with 330 ohm in series, it should easily hit 4.9v or more.

author: VEGETA
author_rank: Super Contributor
timestamp: April 23, 2018, 10:39:35 pm
content: I have 330uF electrolytic cap which is a normal one. It is 25v rated and I am sure I put it the correct way. If you pick 10k resistor, won't this affect current?Plus, I don't want it for contrast only, but for back light which is more important. Contrast is just for convenience since I have a free arduino pin.

author: BrianHG
author_rank: Super Contributor
timestamp: April 23, 2018, 10:39:59 pm
content: Oooops, contrast and backlight are 2 different things.... Led current may be 20ma or more if there are more LEDs. Backlight contrast may be 0.02ma. There is a difference, not to mention that you MCU IO driving 20ma cannot reach the rail voltage. It is too weak.I would stick with 1k and 10uf for your filter.For the backlight, feed this output to the base of an NPN transistor like a 2N3904 or 2N2222, Collector at VCC and Emitter to the LED backlight. You will loose around 0.5v, but have a strong current to drive the LEDs. This is a linear drive method.If your PWM is fast enough, 200hz or above, you do not need a filter at all as your eyes will only see levels of intensity.If you are doing it this way, change the transistor linear emitter follower amplifier to a switch, or use a small mosfet as a switch. This means no power loss due to heat. Though just a LED, this still may be useful in battery powered applications. This gives you that last extra 0.5v on the LEDs.When I say switch, think of using the NPN transistor Emitter to GND, pwm output through 1k resistor to base (No cap), and collector to LED on the GND side, and the VCC side of the LED to 5V. Any low/logic level VGS mosfet will work in the place of the transistor, no 1k resistor needed.You now made a switching PWM switching driven LED dimmer.Make sure your LED can handle the full 5v it will now receive when it's on, otherwise it will need it's series resistor as well.

author: VEGETA
author_rank: Super Contributor
timestamp: April 24, 2018, 05:34:15 am
content: I attached a simulation in LTSPICE. One time as a linear regulator and one other as a switch.As linear, it drops around 0.5v as you said. But my duty cycle is 50% which should give 2.5v (~2v after drop) not 4.5v. While as a switch it gives the same PWM signal which I suspect will cause flickering. It may work for back light but probably won't work for contrast.

author: BrianHG
author_rank: Super Contributor
timestamp: April 24, 2018, 11:24:41 am
content: Oooops, you made a mistake on the linear, for the linear, place the series 1k between the IC PWM output and base of the transistor. Then place a 100uf cap on the base and to the GND. Keep your 100 ohm load for the simulation, you don't need the 330pf caps. Changing the PWM ratio in your simulation will now correctly give you an analog programmable voltage, minus 0.5v from what you would expect. Again, no caps needed on the emitter of the transistor. The 100uf at the base is being amplified at least 100x, meaning at the emitter, it looks like a 10000uf cap is there with any load the transistor can handle.As for the digital, you still need a series 1k resistor for the base, otherwise, you'll burn out the transistor or your PWM IO in real life.If the PWM is steady and fast enough, IE a hardware running PWM, your LED should be dim-able cleanly to the eye without any visual flutter.If your PWM is too slow, use the linear method.Yes, for the LCD contrast input, use no transistor, just a 1k resistor and 100uf cap like you originally had. That input on the LCD panel is less than 1/100 the current consumption of an LED.

author: VEGETA
author_rank: Super Contributor
timestamp: April 24, 2018, 11:59:57 am
content: I will try this soon.BTW, I play to power the device from 9v battery. How much will it last?If we say Arduino takes 20mA and LCD at full brightness will take around 20mA + 10mA here and there = 50mA total.

author: BrianHG
author_rank: Super Contributor
timestamp: April 24, 2018, 11:40:26 pm
content: 9v batteries don't have a lot of power. Take a look at the graph on the right of page 1 of a top end Duracell:http://www.celltech.fi/fileadmin/user_upload/Celltech/Prod.sheets/Duracell_Ultra-Power_9V.pdfAt 50ma, Green curve, you will get just over 10 hours. Cheaper brands can have less than half that operating time.Now, if you go to 6x AA cells (9v), take a look at this chart:http://www.jmargolin.com/furnace/Ultra-Power_AA_MX1500.pdfLooking at the right, the 100ma line, you get around 24 hours, so, at 50ma, you can get around 48 hours of use. Around 5x of a 9v battery.Best thing to do is only turn on the back light when you need to. And anything else, shut down when not in use and put the processor into sleep and see how much you can lower your operating current.Another trick if possible, it to run your project at 3.3v. Current will radically drop with some MCU ICs.

author: VEGETA
author_rank: Super Contributor
timestamp: April 25, 2018, 05:24:29 am
content: Quote from: BrianHG on April 24, 2018, 11:40:26 pmMy Arduino pro mini is 5v and I guess the LCD too. I don't currently have a 3.3v regulator to begin with, I only have mini dc-dc converters which can do the job.My other solution was to power it from 3.7v li-ion battery. I have small ones but again, I don't have protection and charge modules. I could power the thing from USB to charge it, then I won't worry about consumption.

author: BrianHG
author_rank: Super Contributor
timestamp: April 25, 2018, 06:47:40 am
content: Quote from: VEGETA on April 25, 2018, 05:24:29 amRemember, if at 5v your project draws 50ma and you use a LDO, when powering from a fresh battery at 9v, you will consume 50ma from your battery all the way to it's death at around 6v.(This only works if your DC-DC converter takes 9v in directly and operates between 6v&9v) If you use a mini DC-DC converted, or 'buck regulator' set to 5v, with you project consuming 50ma at 5v, when the battery is new feeding the regulator 9v, the current at the battery will be around (assuming 85% efficiency, check converter data sheet) 32ma giving which you might think gives you around 56% more battery life, but, at the battery voltage drops, the current will increase to 50ma, so, lets say you will get 25% more battery life.Now, powering your project with 3.3v, if possible, say your project now draws 32ma. If you had a 3.3v LDO, the draw at 9v will also be 32ma giving you a true 56% more battery life. However, if you were now to use the DC-DC buck regulator, at 9v, your project will draw only 14ma. This is now a huge savings, we are talking a 350% increase in battery life, however, due to current going up as battery voltage drops plus alkaline batteries last much longer the lest power you consume, using the battery charts for 10ma, lets say around 30 hours for the 9v batteries, 250 hours for 6 AA batteries, 100 hours for 4AA batteries.Remember, unlike linear regulators where current consumed is equal to current at the voltage input, regardless of the voltage, with a switching buck converter, current consumed at the voltage input keeps getting less as voltage increases * by loss in efficiency. This is why the 6x AA batteries at 9v perform so much better than 4x AA batteries at 6v.Your best bet is to always measure current with a DVM to be sure. If you have a bench supply, you can confirm the efficiency of your switching DC-DC converter with different power supply voltages (simulating battery voltage drop). You may need a hefty cap on the power going into your regulator to smooth out your DVM current reading.Since I don't know what your device needs to do, I cant recommend much more. I have made a 9v battery powered PIC project with a 2x16 character display in the past, and, I actually powered on and off the LCD character display and everything else from the PIC when not in use and got everything down to an average 2ma draw at the battery giving a respectable 300 hours life, or if I wen with 6x AA cells, I could have had 1400 hours life.

author: VEGETA
author_rank: Super Contributor
timestamp: April 25, 2018, 07:00:24 am
content: You said you powered the LCD from the pic, was it at 3.3v or 5v? My Arduino pro mini is the 5v 16 MHz version so I don't know if it is possible to work it down to 3.3v, if so, then I guess I need to modify the module itself or just solder the 3.3v power wire directly at the 5v pin.I want 9v battery simply because of space. I must put the project in an Altoid tin that I bought from Banggood so 4AA won't do the job.Anyway, how much current will the LCD back light consume at 3.3v? assuming fully powered not PWM controlled or something. If it has good brightness at 3.3v, then I might use a transistor to connect or disconnect the power to it without arduino pwm.

author: BrianHG
author_rank: Super Contributor
timestamp: April 25, 2018, 07:05:00 am
content: If you are interested, here is a truly old Dave video on battery capacity:

author: BrianHG
author_rank: Super Contributor
timestamp: April 25, 2018, 07:20:55 am
content: Quote from: VEGETA on April 25, 2018, 07:00:24 amWithout specs and looking at what LCD module you have, you are in a grey area. The LCD module I was using at the time did support 3.3v operation and I ran the PIC at 3.3v, 1Mhz.In your case, you will need to breadboard/do some experimentation with different back-light brightness's and voltages and narrow down which components are drawing how much current and what voltages the parts support.Using switching PWM method for the backlight, it doesn't matter whether you power the LED with 5v at a lower PWM set brightness, or at 3.3v at a higher set % PWM brightness, that circuit is near 100% efficient. IE, if you set the 5v PWM to 50%, the LEDs will draw 10ma, not 20ma at 100% brightness. It's just how bright you want the backlight.It's all the other circuits which don't shine, but still generate minute amounts of heat where you get your power savings, like the Arduino itself. Maybe 5v is fine, but, set the oscillator to run at 4MHz, or, keep the Aduino in sleep and only wake up 100 times a second to process whatever work you need done, then remain asleep most of the time. You can cut that 20ma down to 2-5ma.With battery power, every drop counts. Many of my battery projects run my PICs at 32Khz or 400Khz where they draw only 0.1ma to 0.5ma.Also remember, an LDO also draws a few ma just sitting there as well unless you use a special low quiescent current LDO.

author: VEGETA
author_rank: Super Contributor
timestamp: April 25, 2018, 07:46:44 am
content: I've seen this:http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/They claim that Arduino pro mini at 3.3v will consume 23uA only! This is due to no power LED and disconnecting the on-board regulator as well as sleep mode, although I don't know how to let it wake up when I need to update measurement and display. I guess now I can power the board with soldering 3.3v wire directly at the 5v pin? or RAW pin? I guess it is Vcc (5v pin).So assuming 0.1mA maximum for the board, it is perfect. Now the LCD is a different story but overall I have just doubled or even tripled the running hours by doing what is in that link. I would test stuff to see if it is possible without problems.

author: BrianHG
author_rank: Super Contributor
timestamp: April 25, 2018, 08:05:12 am
content: Quote from: VEGETA on April 25, 2018, 07:46:44 amNow you are heading in the right direction.I don't know about Aduino, but, with a PIC, when putting it to sleep, I can set a wakeup timer/timeout on interupt, or use the watchdog timer to force a wakeup.Basically removing that 5v regulator means that if you use the switching regulator, you send 3.3v direct to the Arduino removing that LDO's wasted quiescent current.The LCD should also draw around 1-2ma, especially if you are lucky enough that it will also take the 3.3v supply. It's just how often and how bright you power that backlight.I don't know about the rest of your connected hardware, but if you are driving thermocouples, they should only be powered on once every sample, like once a second for 1000th of a second. Same with battery monitoring.If you get your average power consumption down below 1ma, your 9v battery will last in the neighborhood of 3500hours(145 days).Note that without any LDO, using a really small DC-DC switcher powering direct from a 2x 3v 1000mAh lithium coin cell you will only get around 2500 hours.Get your average current down to 0.2ma average, that 9v battery will last 17000 hours, almost 2 years. IE, if you are sampling, just sample once a second, keep the Arduino in sleep for 99.9% of the time and only turn on both the LCD and the backlight when needed.

author: VEGETA
author_rank: Super Contributor
timestamp: April 25, 2018, 08:16:59 am
content: Parts needed for the project:- Arduino pro mini.- 9v battery.- DHT11 sensor.- Altoids project tin.- 16x2 LCD.As for requirements, DHT11 outputs once a second so if I make Arduino sleep for 3 seconds then wake up and take 1 measurement + update display... that would be perfect. temperature and humidity won't change in a matter of 1 second anyway.LCD must be always on, how much current will it take then? what if back light is on too? I would put one tactile push button to activate 2n2222 to connect 3.3v to back light. this button is connected to arduino so how will it do the job with all this power down thing?

author: BrianHG
author_rank: Super Contributor
timestamp: April 25, 2018, 08:49:10 am
content: Which 16x2 LCD module?(This is the lowest power one at digikey)Example:https://www.digikey.com/product-detail/en/newhaven-display-intl/NHD-C0216CU-FSW-GBW-3V3/NHD-C0216CU-FSW-GBW-3V3-ND/2165870Data sheet:http://www.newhavendisplay.com/specs/NHD-C0216CU-FSW-GBW-3V3.pdfThis is a 3.3v to 5v compatible unit.The character module takes around 0.3ma at 3.3v.The LED takes 20ma for full brightness.DHT11 datasheet:https://akizukidenshi.com/download/ds/aosong/DHT11.pdf(Requires 3.5v)So, leaving the character module on, powering and measuring with your sensor once every 3 seconds and updating the display, while keeping the backlight mostly off, you can attempt a life of 700-1200 hours. You will need to run everything at 3.5v to be compatible with the DHT11.Now, it will take a little quality programming and clock settings to get that 700-1400 hours. Tweak everything out really well and you might almost double that. It now comes down to the quality of your 9v to 3.5v regulator.Using 4 AAA batteries would give you around 1500-3000 hours. (Around the same size as an 9v if all 4 are grouped together in a square)Also remember that Alkaline weakens in cold temperatures. Energizer has a 9v lithium battery which will last longer and be more immune to sub-freezing temperatures.

author: VEGETA
author_rank: Super Contributor
timestamp: April 25, 2018, 09:10:25 am
content: Quotetypical one from aliexpress, bought them years ago.QuoteI have a breakout board version of it.Anyway, here it says 3-5 volts:https://www.adafruit.com/product/386so 3.3v is enough.Quote1.2v * 4 = 4.8v so you mean connecting dc-dc here to get 3.3v? will work fine. How is it that these give better life?Plus, how to wire them? will be messyQuoteHow? you mean the power down line I wrong above?QuoteHere it is:https://www.banggood.com/Small-Mini-360-Adjustable-DC-Power-Supply-Module-Mini-Step-Down-Module-p-917568.html?rmmds=myorder

author: BrianHG
author_rank: Super Contributor
timestamp: April 25, 2018, 09:47:28 am
content: Quote from: VEGETA on April 25, 2018, 09:10:25 amYou will need to test measure it. Most older character modules, not counting LED, typically draw 2-5ma. Yes, it's probably 5x to 10x the power consumption of the Digikey module I listed. But, you need to measure to see. They may be low power modules.QuoteRead duracell data sheets:9vhttps://d2ei442zrkqy2u.cloudfront.net/wp-content/uploads/2016/03/MN1604_US_CT1.pdfAt 1ma, expect 700 hours (cell drained down to 5v) (Remember, a 9v battery has 6 really tiny puny 1.5v alkaline batteries in it)AAA 1.5vhttps://d2ei442zrkqy2u.cloudfront.net/wp-content/uploads/2016/03/MN2400_US_CT1.pdfAt 1ma, expect 1350 hours (cell drained down at 0.9v x 4cell = 3.6v)https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20180425013022&SearchText=6v+aaa+battery+holderQuote?Typo in your question?Other than turning on and off the LED backlight, and if you want the character module always on, when programming the Arduino, it is within software that you decide when and how often the CPU is processing and sleeping. The link you made above to that site specifying the currents drawn by the Arduino at different voltages and either sleeping, or active is available for you to program. However, if you want the Adrduino to automatically wake up from sleep, the power consumption is a little higher. Also, the DHT11 also takes some time to sample a reading. Deciding when to take readings from the DHT11, how often, let the Arduino sleep until the reading is ready, updating the readings once every 5 or 10 seconds, refreshing the LCD display once every 10 seconds. Have you programmed all unused IO to an output or have pull-up or pull-downs on unused Arduino pins. How many MHz will you run the Arduino at. All these little things alter the power consumption when you are counting every 0.05ma or less. The link you provided to the low power Arduino site has links on how to sleep the processor and wake up options like a timer and/or push button event. I'm not specialized in Arduino, but with Microchip PIC and the power saving work required for battery powered devices I listed above are prety much universal with all microcontrollers and engineering out every last microamp is part of the game.Powering down the LCD character module brings you into the 10k hours range as long as the regulator module doesn't eat too much.Using 3x AAA cells, you dont need any regulator module at all. In this instance, you can get your current consumption super low.QuoteEither measure that module, or, get the IC datasheet and I suspect the PCB will have the default schematic listed in the datasheet.

author: VEGETA
author_rank: Super Contributor
timestamp: April 25, 2018, 12:40:21 pm
content: QuoteMine are white characters over blue background. So I guess we need some back light to display them nicely.Is there such low power LCDs on Aliexpress or so? I wish so but it should work with Arduino libraries.QuoteWell, I will try 9v battery first since I have one which is pretty much dead already. This project is not meant to be on all the time since it is portable so I guess 9v battery works fine for now.QuoteYes, something like 2-3 seconds would be nice. I guess the WDT is the one to do this right? I can shut down all other timers and hardware modules except for it.QuoteDHT11 is 1 Hz signal sensor, which means 1 signal per 1 second. So I am waiting 3 seconds to get the reading which is more than enough to gather 3 readings not just 1.My guess was sleep, then wake up after 3 seconds, get DHT11 reading, output it to LCD, back to sleep again. Is there any problem?QuoteIt is 16 MHz but if I could get it to be much lower then I would. No need for high speed. Do you know how?Quotebut it is not an option, LCD is the only visible thing in the project xD.QuoteIt has 1.5*3 = 4.5v so this will power the LCD and Arduino, but we agreed to 3.3v so...? plus wouldn't the drop voltage ruin everything eventually?If I wack in the DC-DC module, then it is gonna be the same as before.

author: BrianHG
author_rank: Super Contributor
timestamp: April 25, 2018, 09:39:50 pm
content: Quote from: VEGETA on April 25, 2018, 12:40:21 pmVerify the modules are 3.3v before buying and choose a light background with dark characters so you can read the module with the backlight off.https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20180425132259&SearchText=lcd+character+16x2+3.3vQuoteYou will then be using a regulator.QuoteWhen you get to this point, you will most likely be asking in the microcontroler's section of this forum where the Arduino guys are how to manage Arduino's sleep function and features & how to minimize current consumption. You will need a DVM and 2 big caps and resistor to power your project and measure how much current it is drawing in real time when programming.QuoteThe Arduino IC can run directly from 5v to 2.5v (you need to double check the part number with the data sheet, some low power versions work from 3.5v to 1.2v). The character module also runs from 5v to 3v (The 3.3v versions also run on 5v) and the DHT also runs from 3-5v. This means with 3x 1.5v batteries, 4.5v is fine for your system. As the batteries weaken down to 3v, ie 1v each, your system will still work. No regulator at all.Though, this means the backlight dims with battery age, which you can software brighten, but, you don't have a regulator eating an extra 0.5ma to 1ma. Also, if the Arduino has an internal voltage reference & ADC, your Arduino can now also tell you how much battery power you have left and it can automatically compensate the LED brightness as if you had a voltage regulator. This is getting a little advanced and you might just go for a 9v battery with switching regulator and live with a shorter battery life.