IoT Based Smart Gardening and Smart Agriculture Using ESP32




Introduction: IoT Based Smart Gardening and Smart Agriculture Using ESP32

World is changing as time and so agriculture.
Nowadays, People are integrating electronics in every field and agriculture is not exception for this. This merging of electronics in agriculture is helping farmers and people who manages gardens.

In this article we will see how to monitor and how to manage gardening and agriculture. We will use (ESP32) controlling module for IoT and we will update the data on cloud and based on readings we will take the appropriate action.

In this project we have used sensors like LDR(Light depedent Resistor), Temperature sensor, Soil Moisture level sensor and we will use water pump to react on the sensors data. Apart from this we can use lots of sensors to monitor.

Step 1: Required Components

Below are the required components,

  1. Soil Moisture Sensor
  2. NTC Temperature Sensor
  3. LDR Sensor
  4. DC Water Pump +5v
  5. Breadboard -
  6. ​Jumper Wires -​
  7. Nodemcu -
  8. ESP32 -



Few Wires

Step 2: Working Principle

ESP32 controlling module is used for gathering the data from sensors like LDR(Light depedent Resistor), Temparature sensor, Soil Moisture level sensor. If the soil moisture level is very low then we will turn ON the water Pump. We are monitoring the motor status as well for the feedback to confirm the motor status.

We are using temparature sensor to regulate the water on crop's root which will keep the crop fresh. ESP32 is gathering the data from all sensors and sending/publishing all the data to MQTT server and subscribing for the motor control topic.

Step 3: Projects Pics

Step 4: Code Explaination:

And from the mqtt server or other node (from where we are observing or controlling motor). In our case we are using mobile as node and we have subscribe for the following topic.

Topics to subscribe from controlling node (mobile) and ESP32 will publish for the topic





Publish the topic from controlling node and ESP32 will subscribe for the topic


In the setup_wifi function we are connecting to wifi and control will be stop there till wifi connection.

In the reconnect function ESP32 will try to connect to MQTT server and wait till connection.

callback is the function which will get invoke or will get execute once subscribed topic is available.

In the setup function we are initilizing Serial communication, Wifi connection and MQTT connection.

getTemperature,getMoisturePercentage and getLightPercentage function is reading the data from sensor and returning the value which has to publish over MQTT.

And in the loop function which gets executed continously, ESP32 will send the collected data over mqtt.

Step 5: Schematic

Step 6: Code

Step 7: Tutorial

1 Person Made This Project!


  • Anything Goes Contest

    Anything Goes Contest



Question 1 year ago

Why 4096 in the moisture percentage