I'm trying to come up with a good circuit from common parts that will allow me to set predefined contrast levels to the LCD from the microcontroller. I've seen an example on the internet but its for the PIC micro and it uses pulse width modulation.

I cannot afford to use pulse width modulation since I need to use my CPU cycles in the micro elsewhere.

So I thought of using a simple switch setup where depending on the value of the port pins, the contrast will be low, medium or high.

The maximum voltage that will enter the LCD as well as the micro is 5VDC. Eventually I will be running this circuit on batteries.

It is important that the display can produce clear text (not faint grey) when the battery level is very low (about 2-3V)

Question is, if this circuit setup is perfect, I would assume I could use 2N3905 for PNP transistors, but what about the resistors? Do I use some inverted voltage divider equation of some sorts?

I remembered in the past when I was playing with LCD's that when I hooked a resistor from the contrast to ground without initializing the LCD I see a bar of black squares (normal), but when I instead connected the resistor from contrast to VCC, I saw nothing. So that's why I asked if I needed some sort of inverted voltage divider equation to calculate the optimal resistor values.

Say the voltage level each battery produces is the following:

4V, 3.5V, 3V.

and in each of those cases, I want the display to be of maximum darkness without melting anything inside the display.

How do I choose the optimal resistor values?

And if my transistor setup is incorrect, how would I be able to improve that?

LCD contrast switch

  • \$\begingroup\$ Could a digital potentiometer work? They have up/down interfaces if you can't spare pins for bit-banged SPI. It does depend on how much current flows out of Vo however as digipots can't handle much current. \$\endgroup\$
    – user185972
    Commented Sep 19, 2018 at 17:09
  • \$\begingroup\$ Are you sure your micro and display are going to run on 2 to 3V? The contrast is probably the least of your problems. \$\endgroup\$
    – Finbarr
    Commented Sep 19, 2018 at 17:18
  • \$\begingroup\$ The contrast voltage is temperature and viewing-angle sensitive. For most micros PWM uses ZERO CPU cycles once it is set up. It's a hardware peripheral that, once initialized, just runs autonomously. \$\endgroup\$ Commented Sep 19, 2018 at 17:44

1 Answer 1


The transistors are unnecessary. The port pins can handle the current of VO directly. Just set them low or hi-z as needed.

If you need more resolution, consider building an R-2R DAC. N outputs will give you 2N different settings.

And LCD modules are very low-power devices overall. Nothing is going to "melt", no matter what you do (within the "Absolute Maximum" ratings, of course).

  • \$\begingroup\$ Could PWM work for contrast (with a smoothing capacitor for example)? \$\endgroup\$
    – filo
    Commented Sep 19, 2018 at 18:12
  • \$\begingroup\$ I should try the simple resistor idea now that I think about it because the other end of the resistor is connected to hi-z or ground on the 8051 and the hi-z resistor value in the 8051 is probably way too high anyway to affect the LCD \$\endgroup\$ Commented Sep 19, 2018 at 18:18
  • \$\begingroup\$ PWM would work fine. And it shouldn't require a lot of CPU cycles, either. For example, if you have a timer interrupt that happens every millisecond, you just need to add one line to its ISR: output = ((++counter & 0x0F) < setting); where output is your output pin and counter and setting are 8-bit variables. This gives you 16 distinct settings with a refresh rate of 62.5 Hz. \$\endgroup\$
    – Dave Tweed
    Commented Sep 19, 2018 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.