/*
 * ESP32 automatic irrigation system wokwi simulation
 * Copyright 2022 ITlernpfad
 *
 * SPDX-License-Identifier: Apache-2.0 OR CC-BY-4.0
 *
 * Based on:
 * https://esp32io.com/tutorials/esp32-automatic-irrigation-system
 *
 * This ESP32 code is created by esp32io.com
 *
 * This ESP32 code is released in the public domain
 *
 * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-automatic-irrigation-system
 * 
 * Notes
 * - moisture sensor is replaced by temperature sensor for this simulation
 * - dc motor is replaced by LED and resistors for this simulation
 */

/* 
 * Arduino core library. Aautomatically included by the Arduino IDE. 
 */
//#include "Arduino.h"

#define RELAY_PIN    14 // ESP32 pin GIOP14 that connects to relay
#define MOISTURE_PIN 2 // ESP32 pin GIOP2 (ADC0) that connects to AOUT pin of moisture sensor

#define THRESHOLD 2000 // CHANGE YOUR THRESHOLD HERE

void setup() {
  Serial.begin(9600);
  pinMode(RELAY_PIN, OUTPUT);
}

void loop() {
  int value = analogRead(MOISTURE_PIN); // read the analog value from sensor
  if (value < THRESHOLD) {
    Serial.print("The soil is DRY => turn pump ON");
    digitalWrite(RELAY_PIN, LOW);
  } else {
    Serial.print("The soil is WET => turn pump OFF");
    digitalWrite(RELAY_PIN, HIGH);
  }

  Serial.print(" (");
  Serial.print(value);
  Serial.println(")");

  delay(200);
}
NOCOMNCVCCGNDINLED1PWRRelay Module