LCD + Contrast Pin


I am trying to control the the contrast pin on my LCD using an analog pin on my seeeduino MEGA. If I ground the pin, I see some output on the LCD as expected.

I am using the following:


LCDInit(); pinMode(LCD_CONTRAST_PIN, OUTPUT); analogWrite(LCD_CONTRAST_PIN, 10);

whatever value i put in the analogWrite, the LCd always stay blank. Is it something doable or I have to absolutely use a POT to control constrast?





I use this for controlling the contrast in my lcd display:

  // Sets the Contrast on the LCD, Value 5-20 is OK, on pin 9
  pinMode(9, OUTPUT);
  analogWrite(9, 5);

You can see all of my coding here:

Best Regards

It depends on the sort of LCD module you have. Some modules require a pot with on end open circuit. This is because a negative voltage is being generated that is being connected to ground through a variable resistor.

Other types of LCD need a small positive voltage not a PWM signal. In that case you would have to use a filter between the output pin and your LCD.

Pin mode is automatically set to OUTPUT by "analogWrite" - there's no need to initialise it.

the LCD is

The data sheet says:-

Although a potentiometer is shown as a typical connection, VO can be driven by your microcontroller, either by using a DAC or a filtered PWM.

analogwrite is a PWM signal like I have read in that spec a while ago.. so I guess it should work right?

I guess the keyword here is FILTERED but yeah. test it with a pot first, if it works, build a PWM-filter

I'm agree with ArduinoM

so I guess it should work right?

Only if you use a filter. Are you using one?

No I am not :(

An easy solution to this is to use a capacitor. Just hook your contrast pin to your arduinos pwm pin and filter the oscillation by connecting a capacitor between the lcds contrast pin and ground or power depending on your lcd.

In a nutshell, to encourage you to go read Grumpy Mike's excellent tutorial....

The PWM signal from the Arduino is, alternately, fully on or fully off... rapidly changing between the two, but not rapidly enough for the needs of the LCD "contrast" input.

The filter... which is a simple thing in principle, but may need a little "cleverness" in your selection of component values... goes between the Arduino and the LCD. It takes the "on/off" of the Arduino output and "mushes" it into a (fairly) steady voltage somewhere between the full on and full off. Where it is between those limits varies according to the ratio of the on time and the off time.