#include <LiquidCrystal.h>//imports the libraries
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//sets the LCD pins
const int sensorPin = A0;
float fntemp;
float sum;
float voltage;
int sensorVal;
int count;
void setup() {
Serial.begin(250000);//begins serial interface
lcd.begin(16, 2);
lcd.setCursor(0, 0);
sum = 0.0;
voltage = 0.0;
fntemp = 0.0;
sensorVal = 0;
count = 0;
}
void loop() {
if (count < 30) {//value represents the number of values averaged. Can
sensorVal = analogRead(sensorPin);//be changed
voltage = (sensorVal/1024.0)*5.0;//conversion of sensor value to °C
sum += ((voltage-0.5) * 100);
count ++;
delay(1);//needed to recieve different vslues each time
}
else {
fntemp = sum / count;//averaging
count = 0;
sum = 0.0;
}
Serial.println(fntemp);
lcd.print(fntemp);
lcd.print(" C");
lcd.setCursor(0, 1);
delay(50);//delay to prevent over flashing of the LCD
lcd.clear();
delay(0);
}
Comments
Please log in or sign up to comment.