LCD values coming out too high

So I have an LDR connected to my arduino which just measures the light intensity. I made it write this intensity to the serial monitor AND my LCD. Whenever I turn my desk light on and point it at the LDR the value goes up to about 1000 and then jumps way up to 9000! I thought the analog can only go up to about 1023 or something like that. The serial monitor shows the correct value but not the LCD. I am using a 2k resistor for the ldr voltage divider circuit.

ive just notice that when the value goes down from 1003 to 200 the 3 " sticks". So basically what it reads now is 2003.
The 3 stays the same while the other values change. Heres my code BTW:

#include <LiquidCrystal.h>



LiquidCrystal lcd(7,8,9,10,11,12);

int sensorPin = 5;
int val = 0;


void setup() {

  Serial.begin(9600);
  // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  lcd.begin(16, 4);              // rows, columns.  use 16,2 for a 16x2 LCD, etc.
  lcd.clear();                   // start with a blank screen
  lcd.setCursor(0,0);            // set cursor to column 0, row 0
  lcd.print("Light level is:");
}



void loop() {  


  val = analogRead(sensorPin);
  Serial.println(val);
  lcd.setCursor(2,2);
  lcd.print (val);
  delay(100);






}

post your code. it may be that when you write 1000, the measurement may go down later to something like 90. then the two extra 0s stay in place.

polishdude20: ive just notice that when the value goes down from 1003 to 200 the 3 " sticks". So basically what it reads now is 2003.

Why would it not stick? Did you clear it?

probably just insert an lcd.clear(); right before you update the number.

probably just insert an lcd.clear(); right before you update the number.

You have the correct idea but not the best solution. The LCD clear command takes up a lot of time and it also requires you to resend any titles such as "Light level is:". What you want to do for your new data is (1)reposition the cursor, (2)write some spaces, (3)reposition the cursor again, (4)write the new data.

Don

floresta:

probably just insert an lcd.clear(); right before you update the number.

You have the correct idea but not the best solution. The LCD clear command takes up a lot of time and it also requires you to resend any titles such as "Light level is:". What you want to do for your new data is (1)reposition the cursor, (2)write some spaces, (3)reposition the cursor again, (4)write the new data.

Don

now that's a good idea, thanks!

floresta:

probably just insert an lcd.clear(); right before you update the number.

You have the correct idea but not the best solution. The LCD clear command takes up a lot of time and it also requires you to resend any titles such as “Light level is:”. What you want to do for your new data is (1)reposition the cursor, (2)write some spaces, (3)reposition the cursor again, (4)write the new data.

Don

worked like a charm, thanks