/* Hofkens Laurien - 16/04/2024
* Toon temperatuur op LCD
*/
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/*
* The setup function. We only start the sensors here
*/
float minTemp = 100.0;
float maxTemp = -100.0;
void setup()
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
lcd.init(); // initialiseer LCD
lcd.backlight(); // zet achtergrondlicht aan
lcd.setCursor(7, 0); // zet cursor op 4e plaats van 1e rij
lcd.print("Laurien");
}
/*
* Main function, get and show the temperature
*/
void loop()
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
float tempC = sensors.getTempCByIndex(0);
// Check if reading was successful
if(tempC != DEVICE_DISCONNECTED_C)
{
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(tempC);
lcd.setCursor(0,1);
lcd.print("temp:");
lcd.print(tempC);
lcd.print("Celsius");
lcd.setCursor(0,2);
lcd.print("min temp:");
lcd.print(minTemp);
lcd.print("Celsius");
if(tempC < minTemp) {
minTemp = tempC;
}
lcd.setCursor(0,3);
lcd.print("max temp:");
lcd.print(maxTemp);
lcd.print("Celsius");
if(tempC > maxTemp) {
maxTemp = tempC;
}
}
else
{
Serial.println("Error: Could not read temperature data");
lcd.setCursor(0,1);
lcd.print("Geen temp.sensor");
}
delay(1000);
}