TEMP SENSOR LCD Program
#include <LiquidCrystal.h> // include the LCD driver library
//declare variables
float tempC = 0; // variable for holding Celcius temp (floating for decimal points precision)
float tempf = 0; // variable for holding Fareghneit temp
int tempPin = 0; // Declaring the Analog input to be 0 (A0) of Arduino board.
float samples[8]; // array to hold 8 samples for Average temp calculation
float maxi = -100,mini = 100; // max/min temperature variables with initial values. LM35 in simple setup only measures Temp above 0.
int i;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(28, 29, 30, 31, 32, 33);
void setup()
{
Serial.begin(9600); // start serial communication
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.setCursor(0, 0); // set LCD cursor position (column, row)
lcd.print("Hello "); // print text to LCD
lcd.setCursor(0, 1);
lcd.print("Elderly project");
delay(5000); // wait 500ms
lcd.clear(); // clear LCD display
lcd.setCursor(0, 0);
lcd.print("LCD Temp");
lcd.setCursor(0, 1);
lcd.print(" Digital Monitor ");
delay(4000);
lcd.clear();
}
void loop()
{
Serial.println(analogRead(tempPin));
for(i = 0;i<=7;i++){ // gets 8 samples of temperature
samples[i] = ( 4.4 * analogRead(tempPin) * 100.0) / 1024.0;
Serial.print(".");
lcd.setCursor(0, 0); // set LCD cursor position
lcd.print("Current T: "); // print to LCD
lcd.setCursor(12, 0);
lcd.print(samples[i]);
tempC = tempC + samples[i];
delay(800);
}
Serial.println(""); // Like and CR at serial monitor
Serial.println("");
tempC = tempC/8.0; // better precision
tempf = (tempC* 9)/ 5 + 32; // converts to fahrenheit
if(tempC > maxi) {maxi = tempC;} // set max temperature
if(tempC < mini) {mini = tempC;} // set min temperature
// Send Results to Serial Monitor
Serial.println("New measurement");
Serial.print(" Average Temperature in Celcius is " ); //send the data to the computer
Serial.println(tempC);//send the data to the computer
Serial.print(" Average Temperature in Farenait is " ); //send the data to the computer
Serial.println(tempf);//send the data to the computer
Serial.print(" MAX Temperature in Celcius is " ); //send the data to the computer
Serial.println(maxi);//send the data to the computer
Serial.print(" MIN Temperature in Celcius is " ); //send the data to the computer
Serial.println(mini);//send the data to the computer
// Send results to LCD.
lcd.setCursor(0, 0);
lcd.print("Av.T Max Min");
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the measured temp average
lcd.print(tempC);
lcd.setCursor(6, 1);
// print the maximum temp
lcd.print(maxi);
lcd.setCursor(12, 1);
// print the minimum temp
lcd.print(mini);
digitalWrite(13, HIGH); // set the LED off
delay(2000); // Wait about 3 seconds to display the results to LCD screen befor starting the loop again
tempC = 0; // Set tempC to 0 so calculations can be done again
}