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
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?
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
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
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 =)