add analog soil moisture
This commit is contained in:
parent
903a1058e7
commit
b80ae8c138
1 changed files with 28 additions and 10 deletions
|
@ -123,10 +123,10 @@ int getWaterlevel() {
|
|||
// enable Vcc for water level sensor
|
||||
digitalWrite(PINwaterlevel, HIGH);
|
||||
// wait a bit to let the circuit stabilize
|
||||
delay(200);
|
||||
delay(100);
|
||||
// get the value
|
||||
waterlevelRAW = analogRead(PINanalog);
|
||||
// disable Vcc for the sensor to prevent electrolysis effect
|
||||
// disable Vcc for the sensor to prevent electrolysis effect and release analog pin
|
||||
digitalWrite(PINwaterlevel, LOW);
|
||||
|
||||
if( waterlevelRAW >= waterlevelOK) {
|
||||
|
@ -166,8 +166,22 @@ float getHumidity() {
|
|||
return humidity;
|
||||
}
|
||||
|
||||
int getSoilmoisture() {
|
||||
int soilmoisture = readI2CRegister16bit(0x20, 0);
|
||||
int getSoilmoisture(bool moistureSensor) {
|
||||
int soilmoisture;
|
||||
|
||||
if(moistureSensor == false ) {
|
||||
// read analog value from analog moisture sensor
|
||||
digitalWrite(PINsoilmoisture, HIGH);
|
||||
// wait a bit to let the circuit stabilize
|
||||
delay(300);
|
||||
soilmoisture = analogRead(PINanalog);
|
||||
// disable Vcc for the sensor to release analog pin
|
||||
digitalWrite(PINsoilmoisture, LOW);
|
||||
} else {
|
||||
// read soil moisture from chrip I2C
|
||||
soilmoisture = readI2CRegister16bit(0x20, 0);
|
||||
}
|
||||
|
||||
return soilmoisture;
|
||||
}
|
||||
|
||||
|
@ -183,12 +197,14 @@ void setup() {
|
|||
pinMode(PINfan, OUTPUT);
|
||||
pinMode(PINdht, INPUT);
|
||||
pinMode(PINwaterlevel, OUTPUT);
|
||||
pinMode(PINsoilmoisture, OUTPUT);
|
||||
pinMode(PINled, OUTPUT);
|
||||
pinMode(PINpump, OUTPUT);
|
||||
|
||||
// set all OUTPUT to low
|
||||
digitalWrite(PINfan, LOW);
|
||||
digitalWrite(PINwaterlevel, LOW);
|
||||
digitalWrite(PINsoilmoisture, LOW);
|
||||
digitalWrite(PINled, LOW);
|
||||
digitalWrite(PINpump, LOW);
|
||||
|
||||
|
@ -232,12 +248,12 @@ void loop() {
|
|||
display.setCursor(0,0);
|
||||
// display text
|
||||
display.print("I2C: ");
|
||||
display.print(getSoilmoisture());
|
||||
display.print(getSoilmoisture(1));
|
||||
display.print(", ");
|
||||
display.println(getTemperature(1));
|
||||
|
||||
Serial.print("I2C: ");
|
||||
Serial.print(getSoilmoisture());
|
||||
Serial.print(getSoilmoisture(1));
|
||||
Serial.print(", ");
|
||||
Serial.println(getTemperature(1));
|
||||
|
||||
|
@ -258,12 +274,14 @@ void loop() {
|
|||
|
||||
Serial.print("Water Status: ");
|
||||
Serial.println(getWaterlevel());
|
||||
/*
|
||||
display.print("light: ");
|
||||
display.println(getLightchirp());
|
||||
|
||||
display.print("ASM: ");
|
||||
display.println(getSoilmoisture(0));
|
||||
|
||||
Serial.print("ASM: ");
|
||||
Serial.println(getSoilmoisture(0));
|
||||
|
||||
// print everything on the display
|
||||
*/
|
||||
display.display();
|
||||
|
||||
Serial.println("Test");
|
||||
|
|
Loading…
Reference in a new issue