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
|
// enable Vcc for water level sensor
|
||||||
digitalWrite(PINwaterlevel, HIGH);
|
digitalWrite(PINwaterlevel, HIGH);
|
||||||
// wait a bit to let the circuit stabilize
|
// wait a bit to let the circuit stabilize
|
||||||
delay(200);
|
delay(100);
|
||||||
// get the value
|
// get the value
|
||||||
waterlevelRAW = analogRead(PINanalog);
|
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);
|
digitalWrite(PINwaterlevel, LOW);
|
||||||
|
|
||||||
if( waterlevelRAW >= waterlevelOK) {
|
if( waterlevelRAW >= waterlevelOK) {
|
||||||
|
@ -166,8 +166,22 @@ float getHumidity() {
|
||||||
return humidity;
|
return humidity;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSoilmoisture() {
|
int getSoilmoisture(bool moistureSensor) {
|
||||||
int soilmoisture = readI2CRegister16bit(0x20, 0);
|
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;
|
return soilmoisture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,12 +197,14 @@ void setup() {
|
||||||
pinMode(PINfan, OUTPUT);
|
pinMode(PINfan, OUTPUT);
|
||||||
pinMode(PINdht, INPUT);
|
pinMode(PINdht, INPUT);
|
||||||
pinMode(PINwaterlevel, OUTPUT);
|
pinMode(PINwaterlevel, OUTPUT);
|
||||||
|
pinMode(PINsoilmoisture, OUTPUT);
|
||||||
pinMode(PINled, OUTPUT);
|
pinMode(PINled, OUTPUT);
|
||||||
pinMode(PINpump, OUTPUT);
|
pinMode(PINpump, OUTPUT);
|
||||||
|
|
||||||
// set all OUTPUT to low
|
// set all OUTPUT to low
|
||||||
digitalWrite(PINfan, LOW);
|
digitalWrite(PINfan, LOW);
|
||||||
digitalWrite(PINwaterlevel, LOW);
|
digitalWrite(PINwaterlevel, LOW);
|
||||||
|
digitalWrite(PINsoilmoisture, LOW);
|
||||||
digitalWrite(PINled, LOW);
|
digitalWrite(PINled, LOW);
|
||||||
digitalWrite(PINpump, LOW);
|
digitalWrite(PINpump, LOW);
|
||||||
|
|
||||||
|
@ -232,12 +248,12 @@ void loop() {
|
||||||
display.setCursor(0,0);
|
display.setCursor(0,0);
|
||||||
// display text
|
// display text
|
||||||
display.print("I2C: ");
|
display.print("I2C: ");
|
||||||
display.print(getSoilmoisture());
|
display.print(getSoilmoisture(1));
|
||||||
display.print(", ");
|
display.print(", ");
|
||||||
display.println(getTemperature(1));
|
display.println(getTemperature(1));
|
||||||
|
|
||||||
Serial.print("I2C: ");
|
Serial.print("I2C: ");
|
||||||
Serial.print(getSoilmoisture());
|
Serial.print(getSoilmoisture(1));
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
Serial.println(getTemperature(1));
|
Serial.println(getTemperature(1));
|
||||||
|
|
||||||
|
@ -258,12 +274,14 @@ void loop() {
|
||||||
|
|
||||||
Serial.print("Water Status: ");
|
Serial.print("Water Status: ");
|
||||||
Serial.println(getWaterlevel());
|
Serial.println(getWaterlevel());
|
||||||
/*
|
|
||||||
display.print("light: ");
|
display.print("ASM: ");
|
||||||
display.println(getLightchirp());
|
display.println(getSoilmoisture(0));
|
||||||
|
|
||||||
|
Serial.print("ASM: ");
|
||||||
|
Serial.println(getSoilmoisture(0));
|
||||||
|
|
||||||
// print everything on the display
|
// print everything on the display
|
||||||
*/
|
|
||||||
display.display();
|
display.display();
|
||||||
|
|
||||||
Serial.println("Test");
|
Serial.println("Test");
|
||||||
|
|
Loading…
Reference in a new issue