LDR Problem >fixed< w/ code

here is the code i am using to build a Lcd display that displays Temperature in Celsius and display the light level

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 6, 5, 4, 3, 2);
int tempC = 0;
int lightlevel = 0;
int tempPin = 1;
int ldrPin = 3;
void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Temperature:");
lcd.setCursor(14,0);
lcd.print(" c");
lcd.setCursor(0,1);
lcd.print("Light Level:");
}
void loop()
{
tempC = analogRead(tempPin);
tempC = (5.0 * tempC * 100.0)/1024.0;
lightlevel = analogRead(ldrPin);
lcd.setCursor(12,0);
lcd.print(tempC);
lcd.setCursor(12,1);
lcd.print(lightlevel);
delay(100);
}
the problem is that the light level jumps from about 100-200 to 800+ if there is a slight change in light

Schematic?
Code tags?

there is no schematic sorry
but is this picture good enough?
i have just tested the LDR on another arduino and it works fine
so why is it so different on my nano?

i didnt set the input as a analog ^.^ My bad lol
it is now fixed and i shall delete this post XD

i didnt set the input as a analog

?

i changed this int ldrPin = 3;
into this int ldrPin = A0;

But they're not the same pin.

yes i know that but i changed to code to A0
but now im having another problem when the light level goes about 500 the temperature reading goes nuts and displays random temperatures displaying 50+ degrees

Take two readings each time.
Chuck the first away.

not very helpful im not the best at programming alright

tempC = analogRead(tempPin);
  tempC = (5.0 * tempC * 100.0)/1024.0;

Becomes

(void) analogRead(tempPin);
tempC = analogRead(tempPin);
  tempC = (5.0 * tempC * 100.0)/1024.0;

OK?

Thank you that sorted it
sorry about the other comment
oh and i used the (Void) for the ldr as well which made it cleaner so less glitches thanks for that as well

The (void) isn't really necessary, it just makes the compiler think you know what you're doing. 8)

Right then now i have the temperature and the light level
i would like now to control the lcd backlight with the readings of the ldr
any ideas?

analogWrite?

ok the code is now written here is the finished code
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 6, 5, 4, 3, 2);
int tempC = 0;
int light = 0;
int tempPin = 1;
int ldrPin = A0;
int backlight = 10;
int val = 0;
void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Temperature:");
lcd.setCursor(13,0);
lcd.print(" c");
lcd.setCursor(0,1);
lcd.print("Light Level:");
}
void loop()
{
(void) analogRead(tempPin);
tempC = analogRead(tempPin);
tempC = (5.0 * tempC * 100.0)/1024.0;
lcd.setCursor(12,0);
lcd.print(tempC);
(void) analogRead(ldrPin);
light = analogRead(ldrPin);
lcd.setCursor(12,1);
val = analogRead(ldrPin);
analogWrite(backlight, val/3);
lcd.print(light);
delay(100);
}
This project is now up on youtube if you would like a look =)

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 6, 5, 4, 3, 2);
int tempC = 0;
int light = 0;
int tempPin = 1;                  
int ldrPin = A0;
int backlight = 10;
int val = 0;
void setup()                        
{
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Temperature:");
  lcd.setCursor(13,0);
  lcd.print(" c");
  lcd.setCursor(0,1);
  lcd.print("Light Level:");
}
void loop()                            
{
  (void) analogRead(tempPin);
  tempC = analogRead(tempPin);
  tempC = (5.0 * tempC * 100.0)/1024.0;
  lcd.setCursor(12,0);
  lcd.print(tempC);
  (void) analogRead(ldrPin);
  light = analogRead(ldrPin);
  lcd.setCursor(12,1);
  val = analogRead(ldrPin);
  analogWrite(backlight, val/3);
  lcd.print(light);
  delay(100);                      
}