controling contrast with adruino

With project 11 from the starterkit i want to control the contrast by using a PWM output. For the LED this works great but for contrast i don’t get it working.

The only thing thats happens is that no text can be read, no matter witch value is set. When the LCD pin 4 is connected to GND the screen show the text that where programmed with full contrast. When using the potentiometer for the contrast, the contrast can be set to different settings.

Is there an solution i can use to control the contrast from the LCD screen with a PWM signal or have i bad luck?

hi jrheuwing! i have build the project11 today myself, because i find it very interesting to play around with a lcd. mine works well, because i did the same as they describe in the project-book - with the potentiometer to adjust the contrast! i thougt about your plans, to control the contrast by using PWM...

as you allready mentioned, the lcd needs connected to ground on pin 3 (not pin 4 as you wrote?) to set the contrast high, so you can read the text. maybe that is you problem? i messured the voltage on pin 3 and its true, if you apply about 0.8V on pin 3 you cant hardly read anything!

and then i tried PWM by myself, and? it worked quit fine! i tested it with:

analogWrite(contrastPin, 0);

so no voltage is applied on the pin3 of the lcd and the text is readable with full contrast. within the range from 0 to 80 it disapeared slowly and by the value of 100 there is nothing to read and the lcd. so: adjusting the contrast via PWM works quit fine! you should try it - it works!

@jn-wp: You're right about the used pin. I typed it wrong in this topic. The contrast is connected to pin 3.

I tried your solution and this works perfect. I only don't understand why this didn't work in the first place. The wires are connected as with the first attempt and i only rechecked the program and uplodaded it again. Now everything works perfect.

When the contrastvalue is 50 or higher, i see horizontal lines going through the text. I think that the PWM output creates a interference signal causes this problem.