/* Laurien Hofkens 21/05/2024
* Schakeling miniserre :
* - data van temperatuursensor DS18B20
* - data van grondvochtigheidsensor
* - data leesbaar op I2C LCD
* - servomotor voor bewatering
*/
// Include the libraries we need
#include <OneWire.h> // library Temp.sensor
#include <DallasTemperature.h> // Library Temp.sensor
#include <Wire.h> // Library voor I2C
#include <LiquidCrystal_I2C.h> // Library voor LCD
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);
int grondVocht; // variabele voor grondvochtigheid
/*
* The setup function. We only start the sensors here
*/
void setup()
{
lcd.init(); // initialiseer LCD
lcd.backlight(); // zet achtergrond licht LCD aan
lcd.setCursor(3,0); // zet cursor 4e plaats van 1e lijn
lcd.print("Laurien"); // print tekst
Serial.begin(9600); // start serial port 9600 bps
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
/*
* 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); // zet cursor op 1e plaats 2e rij
lcd.print(tempC);
lcd.print(char(223));
lcd.print("Celsius");
}
else
{
Serial.println("Error: Could not read temperature data");
lcd.setCursor(0,1); // zet cursor op 1e plaats 2e rij
lcd.print("Error.temp.sensor");
}
grondVocht = analogRead(A0);
lcd.setCursor(0,2);
lcd.print(grondVocht);
}