I am using the LM35 sensor and the LCD 1602F ( I think) and unfortunately it is giving me very high readings.
my display says the temperature is 62 degrees centigrade, which is incorrect as it is actually about 20 degrees centigrade.
I have wired the board and coded it exactly as it is on the exemplar project as per the web link I attached to this thread so I'm not sure why I am getting such inaccurate readings?
I would be appreciative of any assistance that can be offered.
Difficult to say what the source of error might be. I would start by verifying LM35 working properly and that it responds temperature differences correctly.
Is there consistently 42 degrees too much in reading? Codes offset value might need fixing...
LM35 is supposed to raise its output voltage by 10mV/degree, so if room is about 20, then heating LM35 with your fingers should rise its output voltage about 150mV (20 -> 35).
There have been quite a few hobbyist having problems with cheap breadboards.
The parts and wires sometimes don't make contact. Try wiggling the LM35 when it's running
Look at the source code of libraries you are using. ~20C is so close to 62F it's pointless to speculate or try to interpret your code until you do some due diligence.
#include <LiquidCrystal_I2C.h> // LCD I2C library
#define ADC_VREF_mV 5000.0 // in millivolt
#define ADC_RESOLUTION 1024.0
#define PIN_LM35 A0 // pin connected to LM35 temperature sensor
LiquidCrystal_I2C lcd(0x3F, 16, 2); // LCD I2C address 0x27, 16 column and 2 rows
void setup() {
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.backlight(); // open the backlight
}
void loop() {
int adcVal = analogRead(PIN_LM35);
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in Celsius
float tempC = milliVolt / 10;
float tempF = (tempC * 9/5) + 32; // convert Celsius to Fahrenheit
lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print(tempC); // print the temperature in Celsius
lcd.print("°C");
lcd.setCursor(0, 1); // start to print at the second row
lcd.print(tempF); // print the temperature in Fahrenheit
lcd.print("°F");
// print the temperature to Serial Monitor
Serial.print(tempC);
Serial.print("°C ~ ");
Serial.print(tempF);
Serial.println("°F");
delay(60000);
}