esp32-garden-basics/01-resistance/sketch/sketch.ino

67 lines
1.0 KiB
Arduino
Raw Permalink Normal View History

2024-05-02 20:51:50 +00:00
/*
C1 : humidité du sol
I1 : Circuit alimenté si On
I2 : Substrat sec si On
*/
2024-06-01 10:46:15 +00:00
#define AOUT_PIN A7
2024-05-02 20:51:50 +00:00
2024-06-01 10:46:15 +00:00
#define LED_POWER 12
#define LED_POW_G 11
#define LED_ALERT 10
#define LED_ALE_G 9
2024-05-02 20:51:50 +00:00
#define THRESHOLD 530 // CHANGE YOUR THRESHOLD HERE
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
2024-06-01 10:46:15 +00:00
// 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);
2024-05-02 20:51:50 +00:00
}
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(")");
2024-06-01 10:46:15 +00:00
// Stay up a bit longer for display
delay(100);
2024-05-02 20:51:50 +00:00
2024-06-01 10:46:15 +00:00
digitalWrite(LED_POWER, LOW);
digitalWrite(LED_ALERT, LOW);
2024-05-02 20:51:50 +00:00
2024-06-01 10:46:15 +00:00
delay(10000);
}
2024-05-02 20:51:50 +00:00