/*
#include <LiquidCrystal.h>
// Define the pins for the temperature sensor and LCD
const int tempSensorPin = A0; // Analog pin for temperature sensor
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // LCD pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// Initialize LCD
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
// Read analog input from temperature sensor
int sensorValue = analogRead(tempSensorPin);
Serial.println("\nAnalog Instantaneous Value:");
Serial.println(sensorValue);
// Convert analog reading to temperature in Celsius
int temperature = map(sensorValue, 0, 1023, -41, 98); // Assuming sensor range is 0-100°C
// Display temperature on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print((char(223)));
lcd.print("C");
// Determine temperature status
lcd.setCursor(0, 1);
if (temperature < 8) {
lcd.print("Extreme Cold");
} else if (temperature >= 8 && temperature <= 18) {
lcd.print("Too Cold");
} else if (temperature >= 18 && temperature <= 40) {
lcd.print("Normal");
} else {
lcd.print("Extreme Hot");
}
// Delay before next reading
delay(1000);
}
*/
#include <LiquidCrystal.h>
// Define the pins for the temperature sensor and LCD
const int tempSensorPin = A0; // Analog pin for temperature sensor
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // LCD pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Function to print a message centered on the LCD
void printCenteredMessage(String message) {
int spaces = (16 - message.length()) / 2; // Calculate number of spaces needed for center alignment
for (int i = 0; i < spaces; i++) {
lcd.print(" ");
}
lcd.print(message);
}
void setup() {
// Initialize LCD
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
// Read analog input from temperature sensor
int sensorValue = analogRead(tempSensorPin);
Serial.println("\nAnalog Instantaneous Value:");
Serial.println(sensorValue);
// Convert analog reading to temperature in Celsius
int temperature = map(sensorValue, 0, 1023, -41, 98); // Assuming sensor range is 0-100°C
// Display temperature on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print((char(223)));
lcd.print("C");
// Determine temperature status and display centered on the LCD
lcd.setCursor(0, 1);
if (temperature <=0) {
printCenteredMessage("Extreme Cold");
} else if (temperature >= 1 && temperature <= 18) {
printCenteredMessage("Too Cold");
} else if (temperature >= 19 && temperature <= 28) {
printCenteredMessage("Normal");
} else if (temperature >= 29 && temperature <= 38) {
printCenteredMessage("Warm");
} else {
printCenteredMessage("Extreme Hot");
}
// Delay before next reading
delay(1000);
}