Back light not working on lcd

Hey guys, I’ve got a regular lcd screen that worked just fine before I attached a servo to the program. I need the back light to be working, and when the servo program is on it just doesn’t want to turn on. Anything wrong with the code?

p.s. It’s not a power supply issue; I removed the servo but kept the code and it still didn’t work.

Here’s the code

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

#include “DHT.h”

#define DHTPIN 7 // what pin we’re connected to

// Uncomment whatever type you’re using!
#define DHTTYPE DHT22

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

#include <LiquidCrystal.h>
char ch;
int Contrast=100;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
{
myservo.attach(10); // attaches the servo on pin 10 to the servo object
}
{
Serial.begin(9600);
Serial.println(“DHTxx test!”);

dht.begin();
}
{
Serial.begin(9600);
Serial.println(“LCD test with PWM contrast adjustment”);
pinMode(13,OUTPUT);
analogWrite(6,Contrast);
analogWrite(9,28836);
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.

}
}

void loop()
{

{
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}

// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);

Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t”);
Serial.print(“Temperature: “);
Serial.print(t);
Serial.print(” *C “);
Serial.print(f);
Serial.print(” *F\t”);
Serial.print(“Heat index: “);
Serial.print(hi);
Serial.println(” *F”);
{
lcd.setCursor(0,0);
lcd.print(“Temp. “);
lcd.print(f);
lcd.print(”*F”);
}
if(h > 40)
{
myservo.write(180);
}
else
{
myservo.write(0);
}
{
lcd.setCursor(0, 1);
lcd.print(“Hum. “);
lcd.print(h);
lcd.print(”%”);
}

}
digitalWrite(13,LOW);
delay(1000);
digitalWrite(13,HIGH);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:

}

void serialEvent()
{
if (Serial.available())
{
ch= Serial.read();
if(ch==‘A’ && Contrast<255)
{
Contrast=Contrast+1;
}
if(ch==‘B’ && Contrast>0)
{
Contrast=Contrast-1;
}
if(ch==‘N’)
{
analogWrite(9,28836);
}
if(ch==‘F’)
{
analogWrite(9,0);
}
analogWrite(6,Contrast);
Serial.println(“Current contrast”);
Serial.println(Contrast);
}
}

The backlight have an external connection physically..

have you given the lcd backlight power ? i had this issue, i didnt connect the backlight to 5v.

Does that mean it needs external power from a transformer? if so, why did it work without an external power source before the servo was plugged in? Why does it not work even when the servo is not attached but the code for it is still there?

The backlight worked before, and when i comment the servo code it works, just not when the servo code is in place.

Are you trying to power the servo directly from the arduino ? Maybe not enough power for the servo and the backlight.

The backlight doesn't usually interface with any programming at all. You connect it to 5V and a manual potentiometer, to adjust the brightness manually.

analogWrite(9,28836); } if(ch=='F') { analogWrite(9,0); } analogWrite(6,Contrast);

pin 6 or 9 ? Or both right ?

analogWrite( ) probably requires an argument between 0 and 255. 28836 doesn't look convincing.

Please put code between code tags. (Go edit ;) )

But you have a default LCD 16x2 with the back light wires directly connected to power (no I2C etc). So code cannot change the back light. So if the back light is off when you plugged in the servo then

1) You blew the voltage regulator but then nothing will work 2) You messed up the wires to the back light when you plugged in the servo 3) You have bad luck and the back light just died...

So check and double check the wiring to the back light (pin 15 and 16). What's the voltage across it?

I found out not all LCD's have a resistor on board for the LED so some need an external resistor to connect it to 5V. Did you use a external resistor?

[edit] michinyon has a point. But I have no idea how you connected everything. Please use a variable name for all pins with a useful name so you (and we) know how it's connected. See Gammons Tip 3

The servo library disables PWM (analogWrite) on pins 9 and 10.

Here is the wiring diagram for the lcd. Does the backlight need a pin with the ability for pwm? Nothing is wrong with the hardware on the board. When I set the servo code to comment mode the program works fine; so the servo code and/or the library is messing with the rest.

Arduino LCD_bb.jpg

Thanks guys! I figured it out thanks to the info given by groundfungus. Since the servo library disabled pwm on pin 9 (where the backlight was connected to) the backlight wouldn't work. I just changed from pin 9 to pin 8 and it worked. Thanks again guys!

Then, for the next time post schematic, use code tags and use proper variable names!