Hi,I have a temperature control system projevt where the temperature should be displayed on the screen when the temp is below 2o the heater is on where I use red led and when the temperature is above 30 the cooler should turn on which is the blue led I did the connection the leds are working correctly acc yo the temp but the lcd is not giving any value snd sometimes it turns off
type or paste code here
#include <LiquidCrystal_I2C.h>
// Initialize the LCD library with the I2C address and the number of columns and rows
LiquidCrystal_I2C lcd(0x27, 16, 2); // 0x27 is the most common I2C address
// Pin definitions based on your wiring
const int tempSensorPin = A0; // TMP36 temperature sensor connected to analog pin A0
const int redLedPin = 11; // Red LED control pin for low temp (heater) indication
const int blueLedPin = 12; // Blue LED control pin for high temp (cooler) indication
// Temperature limits
const float lowerTempLimit = 20.0; // Lower temperature limit for heater activation
const float upperTempLimit = 30.0; // Upper temperature limit for cooler activation
void setup() {
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
pinMode(redLedPin, OUTPUT); // Set red LED pin as output (heater)
pinMode(blueLedPin, OUTPUT); // Set blue LED pin as output (cooler)
digitalWrite(redLedPin, LOW); // Initially turn off red LED
digitalWrite(blueLedPin, LOW); // Initially turn off blue LED
lcd.print("Initializing..."); // Display message during setup
delay(1000);
lcd.clear();
}
void loop() {
// Read the temperature from the TMP36 sensor
int sensorValue = analogRead(tempSensorPin);
float voltage = sensorValue * (5.0 / 1023.0);
float temperatureC = (voltage - 0.5) * 100.0; // Convert voltage to Celsius
// Display temperature on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperatureC);
lcd.print(" C");
// LED control logic based on temperature limits
if (temperatureC < lowerTempLimit) {
digitalWrite(redLedPin, HIGH); // Turn on red LED (heater)
digitalWrite(blueLedPin, LOW); // Turn off blue LED (cooler)
lcd.setCursor(0, 1);
lcd.print("Heater: ON ");
} else if (temperatureC > upperTempLimit) {
digitalWrite(blueLedPin, HIGH); // Turn on blue LED (cooler)
digitalWrite(redLedPin, LOW); // Turn off red LED (heater)
lcd.setCursor(0, 1);
lcd.print("Cooler: ON ");
} else {
digitalWrite(redLedPin, LOW); // Turn off red LED (heater)
digitalWrite(blueLedPin, LOW); // Turn off blue LED (cooler)
lcd.setCursor(0, 1);
lcd.print("System: Stable ");
}
delay(1000); // Delay for readability
}