#include <Wire.h>
#include <LiquidCrystal_PCF8574.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Define the GPIO pin for DS18B20
#define ONE_WIRE_BUS 22
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
// Set the LCD address to 0x27 or 0x3F for a 20 chars and 4 line display
LiquidCrystal_PCF8574 lcd(0x27);
void setup(void) {
// Start the serial communication
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library");
// Initialize the DS18B20 sensor
sensors.begin();
// Initialize the LCD
lcd.begin(20, 4);
lcd.setBacklight(255); // Turn on the backlight
// Print initial message to the LCD
lcd.setCursor(0, 0);
lcd.print("Temperature Monitor");
}
void loop(void) {
// Request temperature from sensor
Serial.println("Requesting temperatures...");
sensors.requestTemperatures();
// Get temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);
// Print the temperature to the serial monitor
Serial.print("Temperature is: ");
Serial.print(temperatureC);
Serial.println(" *C");
// Display temperature on the LCD
lcd.setCursor(0, 2);
lcd.print("Temp: ");
lcd.print(temperatureC);
lcd.print(" C");
// Wait 1 second before repeating the loop
delay(1000);
}
type or paste code here
5 posts - 3 participants