esp32-garden-basics/01-resistance/sketch/sketch.ino
2024-06-01 12:46:15 +02:00

67 lines
1.0 KiB
C++

/*
C1 : humidité du sol
I1 : Circuit alimenté si On
I2 : Substrat sec si On
*/
#define AOUT_PIN A7
#define LED_POWER 12
#define LED_POW_G 11
#define LED_ALERT 10
#define LED_ALE_G 9
#define THRESHOLD 530 // CHANGE YOUR THRESHOLD HERE
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// Set to LOW to use as ground
pinMode( LED_POWER, OUTPUT);
pinMode( LED_POW_G, OUTPUT);
pinMode( LED_ALERT, OUTPUT);
pinMode( LED_ALE_G, OUTPUT);
digitalWrite(LED_POW_G , LOW);
digitalWrite(LED_ALE_G , LOW);
}
void loop() {
int value = analogRead(AOUT_PIN); // read the analog value from sensor
digitalWrite(LED_POWER, HIGH);
if (value > THRESHOLD){
Serial.print("The soil is DRY (");
digitalWrite(LED_ALERT, HIGH);
}else{
Serial.print("The soil is WET (");
digitalWrite(LED_ALERT, LOW);
}
Serial.print(value);
Serial.println(")");
// Stay up a bit longer for display
delay(100);
digitalWrite(LED_POWER, LOW);
digitalWrite(LED_ALERT, LOW);
delay(10000);
}