/* Laurien Hofkens 7/05/2024
* Grondvochtigheidssensor
*/
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int waarde = 0;
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x3F for a 16 chars and 2 line display
Servo myservo; // create servo object to control a servo
int potpin = A0; // analog pin used to connect the potentiometer
int analogValue; // variable to read the value from the analog pin
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
lcd.init(); // initialize the lcd
lcd.backlight(); // zet achtergrondverlichting aan
lcd.setCursor(3,0); // zet cursor op 4e plaats op 1e rij
lcd.print("Laurien"); // zet tekst op LCD
pinMode(A0, INPUT); // zet A0 als input
}
void loop()
{
analogValue = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
map(analogValue, 0, 1023, 0, 180); // scale it for use with the servo (value between 0 and 180)
myservo.write(90); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
if (analogValue < 200)
{
//waarde = analogRead(A0);
lcd.setCursor(5,1);
lcd.print(analogValue);
lcd.setCursor(5,2);
lcd.print("Grote dorst");
analogValue = analogRead(potpin);
map(analogValue, 0, 1023, 0, 180);
myservo.write(180);
delay(500);
}
else
{
if (200 < analogValue < 500)
{
lcd.setCursor(5,1);
lcd.print(analogValue);
lcd.setCursor(5,2);
lcd.print("Dorst");
delay(200);
}
if (500 < analogValue < 800)
{
lcd.setCursor(5,1);
lcd.print(analogValue);
lcd.setCursor(5,2);
lcd.print("OK ");
delay(200);
}
if (800 < analogValue)
{
lcd.setCursor(5,1);
lcd.print(analogValue);
lcd.setCursor(5,2);
lcd.print("Verdrinkt");
delay(200);
}
}
}