IoT Based Irrigation System using Arduino | Futuristic Smart Home

| |

A few days back we published an article “Home Automation using Arduino Nano” in our blog which was well-received among hobbyists. We also did a Home Automation System using NodeMCU. In this post, we are going to make our home SMARTER. We will be using the IoT features of Arduino Nano 33 IoT to water the plants using our mobile phone. Yup! Arduino Plant Watering System Sounds cool, right? So, without further ado, let’s get started.

How to make an IoT Based Irrigation System Video Tutorial

For those who are too lazy to read, (including me) we are linking this video to this page. Hook up your headphone and watch this video, in this video, we explain everything about this project with a demo.

Guys if you like this video and want to see more videos like this, make sure you check out Arduino Project Tutorial Videos. Hit the like button and subscribe to our channel by clicking the subscribe button here. Share your thoughts in the comment box and guys see you in the next video.

Time needed: 1 hour and 30 minutes.

How to setup an Arduino Plant Watering System?

  1. Gather the components

  2. Setup the Circuit

  3. Download and Install Arduino IDE

  4. Setup the Library and Board

  5. Modify the below code

  6. Upload the code

  7. Test

Now lets take a look at everything in detail

IoT Based Irrigation System – Components Required

Home automation is a popular topic these days and with good reason. Devices that we use in the home can be connected to the Internet and controlled remotely via an app or voice assistant. This means you don’t have to control them manually each time you want to turn up the thermostat, close your curtains, or water your plants! Today I will show you how to make an IoT-enabled plant watering system for indoor and outdoor plants using Arduino’s IoT features.

Let’s get familiarised with components

Arduino Nano 33 IoT

The Arduino Nano 33 IoT is the most straightforward and least expensive way to turn old projects into part of the IoT and build pico-network apps and even create new ones. There is an inbuilt wifi adapter that will work flawlessly with all the projects. That means you won’t have to use an external wifi module!

Water Pump

The water pump I use is a 12VDC pump, which can be purchased from your local hardware store. The water valve can be bought from your local hardware store for around 20 Rs.

Solid State Relays

Solid-state relays (SSRs) are simple and reliable electronic switches that allow you to control high voltage devices with low voltage signals from your Arduino or other microcontroller boards.

IoT Based Irrigation System Step by Step Instructions

Step 1 – Drawing Schematics and PCB Design

So I used Altium Designer to draw the circuit and design the PCB. It is a powerful tool that can be used to design and create your own PCBs for your project as well as complex and multiplayer PCBs for industrial use. Here is the link to the Altium trial version. So make sure you check it out.

Guys, for our plant watering system, I have designed a PCB layout where you can easily mount your Arduino Nano 33 IOT and your SSR, set this up without using messy wires and cables hanging around.  The board is lightweight and can be powered using a 9V battery or a 9-12 V power adapter.

Arduino plant watering system | smart home circuit
Arduino Plant Watering System Circuit

Here, there are 2 voltage inputs – One to power the Arduino and other components on the board and another which will drive the electronic devices connected to the relay, which can depend on the devices.

Arduino IoT Based Irrigation System | smart home PCB layout
Arduino Plant Watering System PCB Layout

Here I will be connecting LED strips that work on 12 V So, I will be connecting a 12 V DC adapter. The input power is connected to a 7805 regulator. 7805 is a 5V regulator which will convert an input voltage of 7- 32V to a steady 5V DC supply. There are indicator LEDs across various points for easy troubleshooting.

Getting PCB Done

I ordered PCB from PCBWay. PCBWay is a PCB manufacturer specializing in PCB prototyping, low-volume production, and neat and tidy PCB assembly.

To order your PCB from PCBWay, go to the PCBWay website and fill in the basic board details in the instant order form. From there you will be directed to a form where you can provide more elaborate board details. Update your board information in the PCB specification screen. On the next screen, you should be able to upload your Gerber file and submit it for review. Once the review is completed, all that is left is to add to the cart, make payment, and wait for your PCBs to arrive.

Easy way to control Adobe Photoshop using Arduino HID Functionality - Make it easier for you to edit images in photoshop!

Once you get all the components and the PCB, it’s time for you to solder them together. Solder all the components onto the board and make sure to check the polarity of the components. After soldering the PCB looks like this.

I personally find soldering on this kind of PCBs a fun task, because of these pads soldering becomes very easy. The solder takes up the conical shape and gets soldered from all the sides evenly. After soldering the PCB looks like this.

Step 2 – Download, Install and Setup Arduino IDE

This little board can be easily programmed using the world’s most user-friendly Open Source Platform – Arduino. This will be explained in detail below. So, to get started with our Home Automation system using Arduino, the first thing to do is download and install Arduino IDE from Here.

Step 3 – Code for IoT Based Irrigation System

Now we will start coding!


#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFiUdp.h>

int status = WL_IDLE_STATUS;
#include "arduino_secrets.h" 
char ssid[] = SECRET_SSID;     
char pass[] = SECRET_PASS; 
int keyIndex = 0;    
unsigned int localPort = 5005; 

char packetBuffer[256]; 
char  ReplyBuffer[] = "acknowledged"; 

WiFiUDP Udp;

void setup() {
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("nStarting connection to server...");
  Udp.begin(localPort);
}

void loop() {

  int packetSize = Udp.parsePacket();
  if (packetSize) {
    //Serial.print("Received packet of size ");
    //Serial.println(packetSize);
    //Serial.print("From ");
    IPAddress remoteIp = Udp.remoteIP();
   // Serial.print(remoteIp);
   // Serial.print(", port ");
   // Serial.println(Udp.remotePort());

    int len = Udp.read(packetBuffer, 255);
    if (len > 0) {
      packetBuffer[len] = 0;
    }
    Serial.print("Command Received: ");
    Serial.println(packetBuffer);


 if(strcmp(packetBuffer, "device1on") == 0)
    {
       digitalWrite(3, HIGH); 
       Serial.println("Turning Device 1 ON");

    }
 else if(strcmp(packetBuffer, "device1off") == 0)
    {
       digitalWrite(3, LOW); 
       Serial.println("Turning Device 1 OFF");
    }
 else if(strcmp(packetBuffer, "device12on") == 0)
    {
       digitalWrite(4, HIGH); 
       Serial.println("Turning Device 2 ON");
    }
 else if(strcmp(packetBuffer, "device2off") == 0)
    {
       digitalWrite(4, LOW); 
       Serial.println("Turning Device 2 OFF");
    }
else if(strcmp(packetBuffer, "device3on") == 0)    {
       digitalWrite(5, HIGH); 
       Serial.println("Turning Device 3 ON");
    }
else if(strcmp(packetBuffer, "device3off") == 0)    {
       digitalWrite(5, LOW); 
       Serial.println("Turning Device 3 OFF");
    }
else if(strcmp(packetBuffer, "device4on") == 0)    {
       digitalWrite(6, HIGH); 
       Serial.println("Turning Device 4 ON");
    }
else if(strcmp(packetBuffer, "device4off") == 0)    {
       digitalWrite(7, LOW); 
       Serial.println("Turning Device 4 OFF");
    }

Serial.println("");
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

IoT Based Irrigation System Code Explained

char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;

This is where you enter the ESSID and Passphrase of your network. Before uploading, make sure that you change values to SSID and Passphrase of your WiFi network.

unsigned int localPort = 5005;

This is the port, Arduino will be listening for incoming UDP packets

pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);

The 4 pins we will connect to the relay input

Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);

Connect to the WiFi network using predefined ESSID and Passphrase and set up a UDP listener in the predefined port

int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remoteIp = Udp.remoteIP();
 Serial.print(remoteIp);
 Serial.print(", port "); Serial.println(Udp.remotePort());

int len = Udp.read(packetBuffer, 255);
if (len > 0) {
packetBuffer[len] = 0;
}
Serial.print("Command Received: ");
Serial.println(packetBuffer);

Save the UDP packet contents to the variable ‘packetBuffer’ and print its value

if(strcmp(packetBuffer, "device1on") == 0)
{
digitalWrite(3, HIGH);
Serial.println("Turning Device 1 ON");
}
else if(strcmp(packetBuffer, "device1off") == 0)
{
digitalWrite(3, LOW);
Serial.println("Turning Device 1 OFF");
}
else if(strcmp(packetBuffer, "device12on") == 0)
{
digitalWrite(4, HIGH);
Serial.println("Turning Device 2 ON");
}
else if(strcmp(packetBuffer, "device2off") == 0)
{
digitalWrite(4, LOW);
Serial.println("Turning Device 2 OFF");
}
else if(strcmp(packetBuffer, "device3on") == 0) {
digitalWrite(5, HIGH);
Serial.println("Turning Device 3 ON");
}
else if(strcmp(packetBuffer, "device3off") == 0) {
digitalWrite(5, LOW);
Serial.println("Turning Device 3 OFF");
}
else if(strcmp(packetBuffer, "device4on") == 0) {
digitalWrite(6, HIGH);
Serial.println("Turning Device 4 ON");
}
else if(strcmp(packetBuffer, "device4off") == 0) {
digitalWrite(7, LOW);
Serial.println("Turning Device 4 OFF");
}

Turns the output of the pins to HIGH or LOW depending upon the packets received.

Step 4 – Install RootSaid WiFi Command Center from Google PlayStore

RootSaid WiFi Command Center is a simple lightweight android application that can be used to control robots and Raspberry Pi and Arduino Home Automation over WiFi. All you have to do is connect your mobile phone to the network, enter the IP address and port of the server (the Arduino of our Home Automation system using Arduino) and control it using the On-Off buttons. Click here to know more about this App.

Arduino Plant Watering System

Click Here to Download this app from Playstore.

Step 5 – Tesing Arduino Plant Watering System

Now all you have to do is start the App, enter the IP address of the Pi and port it is listening to (5005).

Arduino Android App

Load the IP and Port using the link button and navigate to the Home Automation Tab.

Arduino Smart Home

That’s it, your Home Automation system using Arduino is now ready. You can now control devices connected to your Arduino using this simple app and turn it on and off.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *