add analog soil moisture
This commit is contained in:
parent
0a34f9f3fe
commit
33d313c68e
1 changed files with 14 additions and 2 deletions
|
@ -167,22 +167,34 @@ float getHumidity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSoilmoisture(bool moistureSensor) {
|
int getSoilmoisture(bool moistureSensor) {
|
||||||
|
// value to return
|
||||||
int soilmoisture;
|
int soilmoisture;
|
||||||
|
// value for wet
|
||||||
|
int wet;
|
||||||
|
// value for dry
|
||||||
|
int dry;
|
||||||
|
|
||||||
if(moistureSensor == false ) {
|
if(moistureSensor == false ) {
|
||||||
// read analog value from analog moisture sensor
|
// read analog value from analog moisture sensor
|
||||||
|
wet = 185;
|
||||||
|
dry= 590;
|
||||||
|
|
||||||
digitalWrite(PINsoilmoisture, HIGH);
|
digitalWrite(PINsoilmoisture, HIGH);
|
||||||
// wait a bit to let the circuit stabilize
|
// wait a bit to let the circuit stabilize
|
||||||
delay(100);
|
delay(100);
|
||||||
|
// get analog input value
|
||||||
soilmoisture = analogRead(PINanalog);
|
soilmoisture = analogRead(PINanalog);
|
||||||
// disable Vcc for the sensor to release analog pin
|
// disable Vcc for the sensor to release analog pin
|
||||||
digitalWrite(PINsoilmoisture, LOW);
|
digitalWrite(PINsoilmoisture, LOW);
|
||||||
} else {
|
} else {
|
||||||
// read soil moisture from chrip I2C
|
// read soil moisture from chrip I2C
|
||||||
|
wet = 580;
|
||||||
|
dry= 250;
|
||||||
|
// get raw value from I2C chirp sensor
|
||||||
soilmoisture = readI2CRegister16bit(0x20, 0);
|
soilmoisture = readI2CRegister16bit(0x20, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return soilmoisture;
|
return map(soilmoisture, wet, dry, 100, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getLightchirp() {
|
int getLightchirp() {
|
||||||
|
@ -285,7 +297,7 @@ void loop() {
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
Serial.println("Test");
|
Serial.println("Test");
|
||||||
delay(1000);
|
//delay(1000);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue