add analog soil moisture

This commit is contained in:
Marcus 2024-04-07 01:56:33 +02:00
parent 0a34f9f3fe
commit 33d313c68e

View file

@ -167,22 +167,34 @@ float getHumidity() {
}
int getSoilmoisture(bool moistureSensor) {
// value to return
int soilmoisture;
// value for wet
int wet;
// value for dry
int dry;
if(moistureSensor == false ) {
// read analog value from analog moisture sensor
wet = 185;
dry= 590;
digitalWrite(PINsoilmoisture, HIGH);
// wait a bit to let the circuit stabilize
delay(100);
// get analog input value
soilmoisture = analogRead(PINanalog);
// disable Vcc for the sensor to release analog pin
digitalWrite(PINsoilmoisture, LOW);
} else {
// read soil moisture from chrip I2C
wet = 580;
dry= 250;
// get raw value from I2C chirp sensor
soilmoisture = readI2CRegister16bit(0x20, 0);
}
return soilmoisture;
return map(soilmoisture, wet, dry, 100, 0);
}
int getLightchirp() {
@ -285,7 +297,7 @@ void loop() {
display.display();
Serial.println("Test");
delay(1000);
//delay(1000);
}