Gardening is a common hobby for nature lovers. Plants need continuous care and close monitoring. Sometimes this turns into a liability. Just as when the caretaker of a garden needs to be away for some time, the garden can remain unattended for some time or even a long time. The Internet of Things can offer a viable solution to this. The garden can be modernized with electronic technology that continuously monitors plant and soil conditions so that plants can receive watering and shade as needed. All of this can be controlled and monitored online with the IoT application.
In this project, a simple garden monitoring system based on the Internet of Things is designed. An IoT device built on Arduino UNO and equipped with sensors such as DHT-11 temperature and humidity sensor, humidity sensor and LDR sensor is designed to send environmental data to the ThingSpeak IoT platform by connecting to a Wi-Fi access point. The ESP8266 Wi-Fi modem interfaces with Arduino to connect to a Wi-Fi access point. The device also interfaces with a water pump controlled by the L293D motor driver IC. The water pump is automatically controlled based on the values of various environmental factors. Various environmental factors such as temperature, humidity, soil moisture and light intensity can be monitored on the Freeboard.io dashboard.
In fact, many of these devices can be installed to watch over a large garden. The Arduino Sketch running on the device implements the various functionalities of the project, such as reading data from the sensor, converting it into strings, passing it to the IoT platform, receiving commands from the IoT platform to control the water pump and controlling the water pump. 'water to water the plants in a timely manner. . Sketch is written, compiled and uploaded using ArduinoIDE. The IoT platform used is ThingSpeak and Freeboard.io is used to build the IoT Dashboard.
Figure 1: Arduino-based IoT Garden monitoring system prototype
Required components –
Fig. 2: List of components required for Arduino based IoT Garden monitoring system
Block diagram –
Fig. 3: Block diagram of Arduino-based IoT Garden monitoring system
Circuit Connections –
The garden monitoring device is built on Arduino UNO. Therefore, the reader must have knowledge of How to get started with Arduino. The Arduino UNO is one of the most popular prototyping boards, commonly used even in IoT projects. Various sensors like DHT-11, humidity sensor and LDR, ESP8266 Wi-Fi modem and L293D motor driver IC interface with Arduino.
Fig. 4: Image showing circuit connections of Arduino-based IoT Garden monitoring system
The Arduino based IoT device has the following circuit connections –
Arduino UNO – The Arduino UNO is a microcontroller board based on ATmega328. It is one of the most popular prototyping boards. The board comes with an integrated Arduino bootloader. It has 14 GPIO pins, 6 PWM pins, 6 analog inputs and integrated UART, SPI and TWI interfaces, an integrated resonator, a reset button and holes for mounting pin headers. While programming the board, it can be connected to PC using USB port and the board can run on USB power. The Arduino UNO has 32 Kb Flash memory, 1 Kb EEPROM and 2 Kb SRAM. The board can be connected to different Arduino Shields for Ethernet, Bluetooth, Wi-Fi, Zigbee or cellular network connectivity and can be connected to most IoT platforms. The ATmega328 controller has the following pin configuration –
Fig. 5: Arduino Uno pin configuration listing table
In this project, the board's two analog input pins are used to interface the LDR and humidity sensor, one GPIO is used to interface the DHT-11 sensor, two GPIO are used to interface the ESP8266 module interface where the pins are configured. using serial software and 2 GPIO pins are used to interface with L293D motor driver IC.
DHT-11 Sensor – DHT-11 is a temperature and humidity sensor. The DHT11 sensor consists of two main components – one is the humidity detection component and the other is the NTC temperature sensor (or thermistor). The thermistor is actually a variable resistor that changes its resistance with changing temperature. Both sense the temperature and humidity of the area and provide output to the IC (which is placed on the back of the sensor). The sensor has four pins – VCC, Ground, data output and NC. The VCC and Ground pins are connected to the common VCC and Ground respectively. The Data Out pin of the sensor is connected to pin 3 of the Arduino board.
LDR sensor – The LDR is used to detect light intensity. The sensor is connected to pin A1 on the Arduino board. The sensor is connected to a potential divider circuit. The LDR provides an analog voltage that is converted to a digital readout by the integrated ADC.
Moisture sensor – An Arduino compatible soil moisture sensor is used in the project. The sensor measures the volumetric water content of the soil with the help of a sensor probe that must be placed in the soil. The sensor module operates between a voltage of 3.3V to 5V. It has an integrated LM393 comparator. The module has four terminals – VCC, Ground, Data Out and Analog Out. The VCC and Ground pins are connected to the common VCC and Ground respectively. The sensor's analog output pin is connected to the A0 pin of the Arduino board.
ESP8266 Module – The ESP8266 Wi-Fi Module is a standalone SOC with integrated TCP/IP protocol stack that can access a Wi-Fi network. The ESP8266 is capable of hosting one application or offloading all Wi-Fi network functions from another application processor. Each ESP8266 module comes pre-programmed with AT command set firmware. The module is available in two models – ESP-01 and ESP-12. The ESP-12 has 16 pins available for interfacing, while the ESP-01 only has 8 pins available for use. The ESP-12 has the following pin configuration –
Fig. 6: ESP8266 ESP-12 modem listing pin configuration table
The ESP-01 model is used in the project. The ESP-01 model has the following pin configuration –
Fig. 7: ESP8266 ESP-01 modem listing pin configuration table
The RESET and VCC pins of the module are connected to 3.3V DC while the Ground pin is connected to common ground. The Tx and Rx pins of the module are connected to pins 10 and 11 of the Arduino UNO.
L293D DC Motor Driver IC – The L293D is the motor control driver IC. It has 16 pins with the following pin configuration:
Fig. 8: Table listing the pin configuration of the L293D motor driver IC
A water pump is controlled in the circuit using L293D which is connected between pins 3 and 6 of the IC.
The IC L293D controls any DC Motors according to the following truth tables:
Fig. 9: Truth table of L293D motor driver IC
Pins 2 and 7 of the L293D are connected to pins 6 and 7 of the Arduino board and allow controlling the pump rotation. Pins 1 and 16 (VSS) are connected to 5 VDC and pin 8 (VS) is connected to 12 VDC power. Pins 4 and 5 are grounded. Pins 12 and 13 of the motor driver IC are also grounded.
Power supply – The circuit requires 5V DC for its operation, while the motor driver IC also needs 12V DC. The AC electrical grid is used as the primary source of energy. The mains supply is stepped down by a transformer and rectified by a full bridge rectifier. The rectified output is regulated to 5V and 12V using 7805 and 7812 ICs. Pin 1 of both voltage regulator ICs is connected to the battery anode and pin 2 of both ICs is connected to ground. The respective voltage outputs are taken from pin 3 of the respective voltage regulator ICs. An LED along with a 10K Ω pull-up resistor is also connected between the common ground and the output pin to get a visual cue of power continuity.
How the circuit works –
This Arduino-based IoT device can be installed anywhere in the garden. Once properly installed and turned on, it connects to the internet via Wi-Fi modem and starts reading data from the interfaced sensors – DHT-11 temperature and humidity sensor, humidity sensor and LDR sensor.
The DHT11 Temperature and Humidity Sensor is a digital sensor with a built-in capacitive humidity sensor and thermistor. It transmits a real-time temperature and humidity reading every 2 seconds. The sensor operates with a power supply of 3.5 to 5.5 V and can read temperatures between 0° C and 50° C and relative humidity between 20% and 95%.
The sensor cannot be connected directly to a digital pin on the board, as it operates on the 1-wire protocol that must only be implemented in the firmware. First, the data pin is configured for input and a start signal is sent to it. The start signal comprises a LOW for 18 milliseconds followed by a HIGH for 20 to 40 microseconds followed by a LOW again for 80 microseconds and a HIGH for 80 microseconds. After sending the start signal, the pin is configured for digital output and the 40-bit data consisting of temperature and humidity reading is locked. Of the 5-byte data, the first two bytes are the integer and decimal part of the relative humidity reading respectively, the third and fourth bytes are the integer and decimal part of the temperature reading, and the last is the checksum byte .
For Arduino, the standard library for DHT-11 sensor is now available. Sensor data can be easily prepared by calling the read11 method of the DHT class.
The LDR sensor is connected to a potential divider circuit and inputs a voltage to the controller's analog input pin. Voltage is read and digitized using the integrated ADC channel.
The humidity sensor also has an analog output which is detected on the A0 pin of the Arduino UNO and is converted to a calibrated value using onboard ADC. The humidity sensor emits an analog voltage in the range of 0 to 4.2 V. The Arduino has a 10-bit ADC channel, so the detected voltage is converted to a value in the range of 0 to 1024. The drier the soil, the higher is the sensor output voltage. Moisture can be expressed as a percentage by calibrating the sensor voltage output on dry and moist soil.
Arduino collects data from all sensors and converts the values into strings. The ESP8266 Wi-Fi module connected to the Arduino uploads the data to the ThingSpeak Server. To display and monitor data uploaded to the ThingSpeak server, a digital dashboard or data broker is required. In this project, a digital dashboard called Freeboard.io is used to visually monitor sensor data online. Freeboard.io uses the JASON file to visualize ThingSpeak data. It offers three elements to build a dashboard –
1) Data Sources – Data sources obtain data from external sources. These external sources can be data brokerage services, JavaScript applications, or JSON files that receive content from an HTTP server. In this project, the data source is a JSON file that receives data from the ThingSpeak server.
2) Widgets – Widgets help to display data in textual or graphical form. There are many widgets available on Freeboard.io such as text, graph, meter, etc.
3) Panels – They are used to organize widgets.
Freeboard.io requires sign-up and post-signal widgets can be created.
Fig. 10: Screenshot of the Freeboard registration page
Sign up for Freeboard.io
There are four meter-type widgets designed to monitor temperature, humidity, light intensity, and soil moisture.
The dashboard on Freeboard.io can be created as follows –
1. Access the freeboard.io website and register with a new account.
2. Enter the name and click on the create button, after entering the new window, click on create data source and select type as JASON.
Fig. 11: Screenshot of meter type widgets in the Freeboard API
Freeboard.io data source selection
3. Then fill in the fields to indicate the IoT platform. In the URL tab, change the number 392797 with the respective channel id.
4. After creating the data source, click on add panel and select as Meter.
Fig. 12: Screenshot of data source creation in the Freeboard API
Freeboard.io widget creation
5. In the dashboard, after selecting the Meter, select the following as shown below and create the widgets.
Figure 13: Screenshot of how to select the data source in the Freeboard API
Freeboard.io meter widget creation
This way, sensor data can be uploaded to the ThingSpeak server and viewed online in the Freeboard.io dashboard. The dashboard can be accessed from any device like smartphone, laptop or PC with internet connectivity.
The water pump is automatically controlled depending on the values of environmental factors detected by Arduino. If the humidity level is below 80%, the pump turns on and continues running until the humidity level is retained.
The Arduino board needs to connect to a Wi-Fi hotspot to connect to the Internet. The Wi-Fi hotspot name and password are encoded in the Arduino sketch. Initializing the Wi-Fi connection is done within the Arduino Sketch setup function, which is executed as soon as the board is turned on.
Wi-Fi connection configuration is performed by passing AT commands to the ESP8266 Wi-Fi modem. The modem is connected to the GPIO pins of the Arduino which are configured as UART transmitter and receiver pins using the software serial library. Wi-Fi is initialized by passing the following AT commands to the ESP module –
NO : This command is passed to check if the modem is working properly.
AT+GMR: This command is passed to print the firmware version.
AT+CWMODE=3 : This command is passed to set the Wi-Fi mode for both AP mode and Station mode.
AT+RST: This command is passed to restart the modem.
After rebooting, the modem checks the IP addresses of available access points. The ESP modem can connect to the access point whose SSID and password are encoded in the Arduino Sketch. The following AT command is passed to connect to the access point –
AT+CWJAP
Once the modem is connected to an access point, it obtains the IP address by running the following command –
AT+CIFSR: This command is used to obtain the IP address of the ESP module as a client.
The IP address is stored in a string and confirmed on the Arduino board. Once the sensor data is collected, the following AT commands are passed to the ESP module to send it to the cloud:
AT+CIPSTART=4,”TCP”,”184.106.153.149″,80 : This command is passed to initiate a TCP connection to the given IP address on the specified port (80).
AT+CIPSEND=4, String(getStr.length) : This command is passed to send data on the previously mentioned IP address with the number of transmission connections set to 4 and the data length (which can be a maximum of 2048 bytes) specified .
Thus, the Arduino connects to the server via ESP modem and the data sent can be observed graphically on Freeboard.io.
Programming guide –
The Arduino sketch can collect data from DHT-11, humidity sensor and LDR sensor, convert sensor values into string, control the water pump via L293D IC and pass data to ThingSpeak server. First, the Arduino open source standard library for interfacing with the DHT11 is imported, and the software serial library for serial communication with the Wi-Fi module is imported. Variables representing pin connections to read sensor data are initialized.
Fig. 14: Screenshot of Arduino code initialization for IoT Garden monitoring system
Getting Started with Arduino Sketch for IoT Garden Monitoring System
The setup function is called in which the serial communication baud rate for communication with the Wi-Fi modem is set to 9600. Wi-Fi mode and network connectivity are established using AT commands with some delays. The delay must be given according to the time it takes to connect to the network.
Fig. 15: Screenshot of configuration function in Arduino code for IoT Garden monitoring system
Configuration Function in Arduino Sketch for IoT Garden Monitoring
The loop function is called in which the sensor data is fetched and stored in the initialized variables. The water pump is controlled by passing the appropriate digital logic to the input pins of the L293D motor driver IC. The esp8266 function is called to transmit data to the cloud.
Fig. 16: Screenshot of Loop function in Arduino code for IoT Garden monitoring system
Loop Function in Arduino Sketch for IoT Garden Monitoring System
In the esp8266 function, AT commands are passed to establish the TCP connection, and then the ThingSpeak API key is provided to transmit the data to the registered channel. Every 16 seconds, data is updated for the ThingSpeak channel.
Fig. 17: Screenshot of IoT communication management function in Arduino Sketch for IoT Garden Monitoring System
Function Managing IoT Communication in Arduino Sketch for IoT Garden Monitoring System
This completes the Arduino sketch for IOT based garden monitoring system. Check out the Arduino Sketch in the code section to try it out.
This project is easy to build and can be installed anywhere in the garden. It allows automatic garden maintenance and remote monitoring with the help of IoT.
Project source code
###
//Program to /*================================================= =========================*/ /*Standard Library */ /*================================================= =========================*/ #include#include /*================================================= =========================*/ /*Variable Initialization for Senor pins */ /*================================================= =========================*/ dht DHT; #define DHT11_PIN 3 #define RM_1 6 #define RM_2 7 float t=0; float h=0; int sen_val = 0; int lig_val = 0; char data = 0; #define MOS_SEN A0 #define LDR_SEN A1 /*================================================= =========================*/ /*API key for things speak and change with your API */ /*================================================= =========================*/ String apiKey = "CAM10KIK7YH2HAO0"; /*================================================= =========================*/ /*Serial pins for connecting WiFi module */ /*================================================= =========================*/ SoftwareSerial be(10,11); // RX, TX /*================================================= =========================*/ /*Setup function that runs first */ /*================================================= =========================*/ void setup { Serial.begin(9600); pinMode(MOS_SEN, INPUT); pinMode(LDR_SEN, INPUT); pinMode(RM_1, OUTPUT); pinMode(RM_2, OUTPUT); ser.begin(9600); // reset ESP8266 WiFi connection AT+CIPMUX=1 AT+CWJAP /*================================================= ========================*/ /*AT commands for establishing WiFi connection */ /*================================================= ========================*/ ser.println("AT"); delay(1000); ser.println("AT+GMR"); delay(1000); ser.println("AT+CWMODE=3"); delay(1000); ser.println("AT+RST"); delay(5000); ser.println("AT+CIPMUX=1"); delay(1000); String cmd="AT+CWJAP="EngineersGarage","egP@$$w0rd?""; ser.println(cmd); delay(1000); ser.println("AT+CIFSR"); delay(1000); } /*================================================= ========================*/ /*Loop functions that runs infinitely that collects sensor data */ /*================================================= ========================*/ void loop { delay(1000); int chk = DHT.read11(DHT11_PIN); Serial.print("Temperature = "); t = DHT.temperature; Serial.println Serial.print("Humidity = "); h = DHT.humidity; Serial.println(h); lig_val = analogRead(LDR_SEN); int mos_val = read_mos; if(mos_val > 80) { Serial.println("Start"); digitalWrite(RM_1, HIGH); digitalWrite(RM_2, LOW); } else if(read_mos < 80) { Serial.println("Stop"); digitalWrite(RM_1, LOW); digitalWrite(RM_2, LOW); } Serial.println(sen_val); delay(500); Serial.print("Light Intensity = "); Serial.println(lig_val); delay(500); esp_8266; } /*================================================= ========================*/ /*esp8266 function that uploads data to web */ /*================================================= ========================*/ void esp_8266 { // TCP connection AT+CIPSTART=4,"TCP","184.106.153.149",80 String cmd = "AT+CIPSTART=4,"TCP",""; cmd += "184.106.153.149"; // api.thingspeak.com cmd += "",80"; ser.println(cmd); Serial.println(cmd); if(ser.find("Error")) { Serial.println("AT+CIPSTART error"); return; } // prepare GET string GET String getStr = "GET /update?api_key="; getStr += apiKey; getStr +="&field1="; getStr +=String(h); getStr +="&field2="; getStr +=String getStr +="&field3="; getStr +=String(sen_val); getStr +="&field4="; getStr +=String(lig_val); getStr += "rnrn"; // send data length cmd = "AT+CIPSEND=4,"; cmd += String(getStr.length ); ser.println(cmd); Serial.println(cmd); delay(1000); ser.print(getStr); Serial.println(getStr); //thingspeak needs 15 sec delay between updates delay(15000); } int read_mos { sen_val = analogRead(MOS_SEN); Serial.print("Moisture = "); sen_val = map(sen_val,0,1023,0,255); return sen_val; }
###
Circuit diagrams
Circuit Diagram Based on Arduino-IoT-Garden-Monitoring-System- |