Help with TMP36 (Temperature sensor)
when temperature is higher than 40 degrees, red led n buzzer should work, and the lcd should say ThermoCheck: Hot
otherwise, lower than 40 degrees, green led is on and the lcd should say ThermoCheck: Normal
problem: the lcd is not working
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD setup (address 0x27, 16 columns, 2 rows)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Pin definitions
const int sensorPin = A0;
const int greenLED = 2;
const int redLED = 3;
const int buzzer = 6;
// Temperature variables
float celsius = 0.0;
const float baselineTemp = 40.0; // Threshold
void setup() {
// Initialize LCD
lcd.init();
lcd.backlight();
// Initialize pins
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(buzzer, OUTPUT);
// Initialize Serial Monitor
Serial.begin(9600);
// Initial display
lcd.setCursor(0, 0);
lcd.print("ThermoCheck");
delay(1500);
lcd.clear();
}
void loop() {
// Read TMP36 sensor
int sensorValue = analogRead(sensorPin);
float voltage = sensorValue * (5.0 / 1023.0);
celsius = (voltage - 0.5) * 100.0;
// Debugging output
Serial.print("Temp: ");
Serial.print(celsius, 1);
Serial.println(" C");
// Display temperature
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(celsius, 1);
lcd.print((char)223); // Degree symbol
lcd.print("C ");
// Status check
lcd.setCursor(0, 1);
if (celsius < baselineTemp) {
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
digitalWrite(buzzer, LOW);
lcd.print("ThermoCheck: Normal");
} else {
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
digitalWrite(buzzer, HIGH);
lcd.print("ThermoCheck: HOT ");
}
delay(1000); // Update every second
}

3 Replies
except for using pin 1 it looks like it should work
ill move the buzzer's pin?
the lcd doesnt seem to be working though, is my code wrong?
the LCD wiring looks fine, as does the code
it's possible you are using a different LCD library which wants
.begin
instead of .init