Introduction: IOT IRRIGATION PROJECT

In this tutorial, we leverage the Arduino IoT Cloud in conjunction with an ESP32 module to control a 12V DC solenoid valve. This foundational project illustrates remote device control and serves as a starting point for more intricate system management. By connecting the solenoid valve to the ESP32 and the IoT Cloud, users can toggle the valve's state through the Cloud interface, demonstrating the potential for remote operation of diverse devices. This basic project lays the groundwork for more complex IoT applications and device management scenarios.

Supplies

  1. Hardware:
  • ESP32 controller board
  • 12V DC solenoid valve
  • 5V DC power supply
  • External 12V DC power supply
  • Breadboard
  • Jumper wires (male-to-male and male-to-female)
  • 5v Relay
  1. Software:
  • Arduino IDE (Integrated Development Environment)
  • Required libraries for ESP32 and Arduino IoT Cloud (to be installed in Arduino IDE)



Step 1: Circuit Connection

  • Connect the 5V DC power source to ESP32 GND and Vin pin
  • Also power the relay pins using the same 5V power source
  • Connect the 12V DC power supply to the relay and to the 12V DC solenoid valve as shown in the diagram.
  • Connect the relay signal wire (control wire) to a digital pin on the ESP32 Pin GPIO16
  • Ensure proper connections and no loose wires


Step 2: Create Arduino IOT Cloud Account

Open the page and Sign up

Step 3: Now We Create a Thing

Step 4: Add a Cloud Variable

  • After that, you just need to name the variable, so as we want to make a project for controlling solinoid.
  • We will require only one variable. So let’s just add it. I will name the first variable as Irrigation and select Schedule.
  • Select the read and write permission
  • Add variable


Step 5: Click Select Device

Step 6: Set Up a New Device

  • Select 3rd party device
  • Select ESP32 as we are using ESP32 module
  • Select ESP32 Dev module
  • Give name as Smartgarden
  • In next step we need to save both device id and the secret key,
  • we can save inside our computer because we will be requiring these parameters at the time of coding
  • you just need to click on download the pdf and it will automatically download the credentials pdf on your computer


Step 7: WIFI

  • configure the WIFI under network
  • Fill your Wi-Fi- name and password
  • Copy paste the secret-key saved earlier


Step 8: Dashboard

  • now to create a dashboard we have to select the dashboard from top left section
  • Now int the new dashboard click add and select scheduler

Step 9: Scheduler

  • Now Select linked variables and connect the variable irrigation that we saved before
  • Make the Starting Date/Time Visibility as time only
  • make the Time Formats in hh : mm
  • Select done

Step 10: Coding

  • Now we select the top menu as before
  • and select things
  • Here we select sketch


Step 11: Coding

  • Replace the codes in sketch with the one below or copy paste from the download link below
  • You can see that i have just defined R7 and a function onIrrigationChange()


#include "thingProperties.h"

#define R7 16 // Pins of Relay (Control)


void setup() {

 // Initialize serial and wait for port to open:

 Serial.begin(9600);

 pinMode(R7, OUTPUT);

 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found

 delay(1500); 


 // Defined in thingProperties.h

 initProperties();


 // Connect to Arduino IoT Cloud

 ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  

 /*

   The following function allows you to obtain more information

   related to the state of network and IoT Cloud connection and errors

   the higher number the more granular information you’ll get.

   The default is 0 (only errors).

   Maximum is 4

 */

 setDebugMessageLevel(2);

 ArduinoCloud.printDebugInfo();

 digitalWrite(R7, HIGH);

}


void loop() {

 ArduinoCloud.update();

 // Your code here 

 void onIrrigationChange();

  

}



/*

 Since Irrigation is READ_WRITE variable, onIrrigationChange() is

 executed every time a new value is received from IoT Cloud.

*/

void onIrrigationChange() {

 // Add your code here to act upon Irrigation change

 {if (irrigation.isActive()) {

  // can be configured to be ON between 8am - 5pm 

  digitalWrite(R7, LOW);

} else {

  //can be set to OFF between 5pm - 8am the next morning

  digitalWrite(R7, HIGH);  

}

}

Step 12: Coding

  • One very great thing about this Arduino IoT cloud platform is you don’t even need to have any software any library to be installed onto your computer.
  • You just need to have a basic computer with internet connectivity and all the things will be done inside this IoT. 
  • Arduino IoT cloud platform provides the online Arduino IDE or we can say code editor software with all the libraries already included on it,
  • You will need to download and install the ArduinoCreatAgent
  • Then compile the code for errors and upload it to your ESP32 controller

Step 13: Finished

  • Now go to the Dashboard, adjust the irrigation schedule time to where the valve must work
  • Connect one end of valve to tap inlet and other end to tap outlet checking the arrow on valve showing the water flow
  • make all the circuit in a box so u can place the box anywhere
  • you can also use a 12v DC charger and connect a 12v to 5 v converter to power ESP32
  • thank you