Build Your Own Smart Agriculture Sensor with Arduino project is a low-cost IoT agricultural system that measures soil moisture, ambient temperature, air humidity, and light levels, providing irrigation alerts when necessary and optionally sending data to a web panel. In this guide, you will find everything needed to set up an Arduino-based sensor in about 1-2 hours, including the required parts, connection diagrams, sample code, calibration steps, durability tips for field use, and methods to monitor data online.
Smart agriculture sensors are used in a variety of areas, from small hobby gardens to greenhouses, to reduce unnecessary watering, detect plant stress early, and digitally track production conditions. While ready-made industrial systems are powerful, a modular system built with Arduino is more economical and educational for beginner producers, students, makers, or small businesses. Moreover, with the right sensor selection and regular calibration, reliable results can be obtained for daily decision-making.
The goal of this article is not only to create a functioning circuit but also to address measurement logic, data accuracy, energy consumption, internet connectivity, and secure publishing together. If you wish to display sensor data later on a website or a custom control panel, reliable infrastructure is required on the hosting side. At this point, you might consider Hostragons Web Hosting Solutions for project documentation, API endpoints, or control panels, and Hostragons Domain Lookup for domain publishing.
Project Purpose and Working Logic
This smart agriculture sensor collects four fundamental data points from the environment where the plant is located: soil moisture, temperature, air humidity, and light intensity. The Arduino reads these data at specified intervals, compares them to predetermined thresholds, and can send the results to a serial monitor, LCD screen, SD card, or a web server via Wi-Fi. In its simplest use, the system provides an alert with an LED or buzzer when soil moisture drops below a set level. In more advanced uses, it can activate a mini water pump using a relay module.
For example, if the soil moisture in a small balcony where tomatoes are grown falls below 35% for an extended period, the plant may experience stress. Your sensor measures every 10 minutes, checks the average of the last 6 readings, and notifies when watering is necessary if moisture is low. This approach is safer than making decisions based on a single erroneous measurement, as soil sensors can sometimes display instantaneous deviations due to salinity, contact quality, or sudden temperature changes.
On the IoT side, the logic is simple: the device measures, the microcontroller interprets, the connection module transmits the data, and the web panel or database stores the history. If you plan to publish the web panel publicly, it is recommended to use HTTPS. While sensor data may not seem like personal data, it can provide clues about location, production patterns, and business habits. Therefore, it is a good security practice to consider What is SSL Certificate and Why is it Necessary when publishing your panel.
Required Materials and Approximate Costs
The following list consists of components that are stable, easy to find, and suitable for beginners. Prices vary based on brand, quality, and supplier; therefore, it is more practical to focus on selection criteria rather than exact pricing. If you plan to use the sensor outdoors, the most important components to focus on are the capacitive soil moisture sensor and the waterproof enclosure.
- Arduino Uno or Arduino Nano: Uno is suitable for beginners, while Nano is ideal for compact setups.
- Capacitive soil moisture sensor: More resistant to corrosion compared to resistive sensors.
- DHT22 or DHT11 temperature-humidity sensor: DHT22 is more accurate and has a wider range.
- LDR light sensor and 10K resistor: Sufficient for approximately measuring light levels.
- ESP8266 Wi-Fi module or directly using an ESP32 board: Used for internet connectivity.
- Relay module and mini water pump: Optional for those who want to add automatic watering.
- External 5V power adapter or power bank: Provides stable power in the field.
- Breadboard, jumper wires, soldering equipment: Necessary for prototyping and permanent connections.
- IP65 enclosure, cable gland, silicone seal: Recommended for outdoor durability.
The initial cost is generally lower compared to ready-made industrial systems in most scenarios. For a basic measurement system, an Arduino, soil moisture sensor, DHT sensor, and wires are sufficient. As you add Wi-Fi, a web panel, automatic pump, and outdoor protection, costs will increase; however, the benefits of the system will also rise. Particularly in small greenhouses, recording irrigation decisions can clearly show which days water stress occurs within a few weeks.
Comparison of Arduino, ESP32, and Ready Sensor Kits
Before starting the project, it is important to determine which board to choose. Arduino Uno provides ease of learning, while ESP32 offers advantages in IoT with built-in Wi-Fi and higher processing capacity. Ready kits offer quick setup but may have limited customization options.
| Option | Advantage | Disadvantage | Best Use Case |
|---|---|---|---|
| Arduino Uno | Abundant resources, easy connection, ideal for education | No built-in Wi-Fi, takes more space in the box | Initial prototypes and learning projects |
| Arduino Nano | Small size, low cost, suitable for permanent installation | USB and pin structure may challenge beginners | Pot, balcony, and compact greenhouse setups |
| ESP32 | Built-in Wi-Fi/Bluetooth, powerful processor, low power modes | 3.3V logic level requires caution | IoT systems sending data to a web panel |
| Ready Agriculture Kit | Quick start, bundled components are compatible | Customization and learning value may be limited | Users with limited time |
If you are setting up for the first time, prototyping with Arduino Uno and reading values on the serial monitor is the safest route. When you want to send data to the internet, you can add the ESP8266 module or switch directly to ESP32. If you are preparing a professional mini panel, ESP32 offers fewer components and cleaner architecture.
Connection Diagram: Basic Circuit Setup
In the basic setup, the capacitive soil moisture sensor connects to an analog pin, the DHT sensor to a digital pin, and the LDR connects to an analog pin using a voltage divider logic. Before assembling the circuit, make all connections without power. Especially if you are using a water pump or relay, do not carry the power line through the Arduino; feed the pump with a separate power source and only send the control signal from the Arduino.
Recommended Pin Connections
- Soil moisture sensor VCC: 5V, GND: GND, AO: A0
- DHT22 VCC: 5V, GND: GND, DATA: D2
- LDR: One end to 5V, the other end to A1 and GND through a 10K resistor
- Alert LED: Connect to pin D8 with a 220-ohm resistor
- Relay signal: Connect to pin D7, the pump is powered externally
The probe part of the soil moisture sensor should be placed vertically in the soil; the cable connection point should not touch the soil. Instead of leaving the sensor in a constantly wet area, it is more accurate to place it close to the root zone but away from points where water directly accumulates. If there are multiple pots or beds, using a separate sensor for each section is healthier. Trying to represent the entire area with a single sensor can be misleading, especially in drip irrigation systems.
Setting Up the Arduino IDE and Libraries
After downloading the Arduino IDE from the official source and connecting your board to the computer, first verify that the board is working with a simple blink example. Then, install the necessary library for the DHT sensor. You can do this by opening the Library Manager in the Arduino IDE and loading the DHT sensor library and the Adafruit Unified Sensor package. This step makes reading temperature and humidity measurements in the code easier.
If you plan to connect the project to a web panel, you also need to add the ESP8266 or ESP32 board manager to the IDE. However, this guide provides basic code based on Arduino Uno logic, making the measurement and decision algorithm clearly understandable. Later, the same logic can be expanded on the ESP32 using HTTP POST or MQTT protocol. When you create an API endpoint, API and Integrations Guides can help you with architectural planning on the server side.
Sample Arduino Code
The following code reads soil moisture, temperature, air humidity, and light levels. If soil moisture is below the threshold you set, it provides an LED alert. Do not expect direct percentage values without calibration; each sensor and soil type can produce different analog ranges. Therefore, you should adjust the dry and wet values in the code according to your own measurements.
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define SOIL_PIN A0
#define LDR_PIN A1
#define LED_PIN 8
DHT dht(DHTPIN, DHTTYPE);
int dryValue = 820;
int wetValue = 360;
int minMoisture = 40;
void setup() {
Serial.begin(9600);
dht.begin();
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int soilRaw = analogRead(SOIL_PIN);
int lightRaw = analogRead(LDR_PIN);
float temp = dht.readTemperature();
float hum = dht.readHumidity();
int soilPercent = map(soilRaw, dryValue, wetValue, 0, 100);
soilPercent = constrain(soilPercent, 0, 100);
if (soilPercent < minMoisture) { digitalWrite(LED_PIN, HIGH); }
else { digitalWrite(LED_PIN, LOW); }
Serial.print("Soil Moisture: "); Serial.print(soilPercent); Serial.println("%");
Serial.print("Temperature: "); Serial.print(temp); Serial.println(" C");
Serial.print("Air Humidity: "); Serial.print(hum); Serial.println("%");
Serial.print("Raw Light Value: "); Serial.println(lightRaw);
Serial.println("---");
delay(10000);
}
The code uses a 10-second measurement interval. In actual agricultural applications, a 10-second interval is often unnecessarily frequent. For pots or greenhouses, intervals of 5-15 minutes may be sufficient. If you are using a battery, extending the measurement interval, powering the sensor only during measurement, and using low power modes can significantly increase battery life.
Calibration: The Most Critical Step for Accurate Measurement
In many Arduino agricultural projects, errors arise not from the circuit but from calibration. The soil moisture sensor produces raw analog values; these values do not directly equate to percentage moisture. First, you must determine the raw values of your sensor in both dry and wet conditions. For example, you might read 820 when holding the sensor in dry air and 360 when completely submerged in thoroughly wet soil. These two extreme values are defined in the code as dryValue and wetValue.
Calibration Steps
- Run the sensor in a dry environment and take 10 measurements; record the average as the dry value.
- Place the sensor in very wet but not submerged soil; take 10 measurements.
- Repeat the same procedure with the actual soil mixture you will use; peat, clay, and sandy soil behave differently.
- Monitor the measurement values on the serial monitor and update the limits in the code.
- Determine the minimum moisture threshold through experimentation based on the plant type.
In practice, values of 0% and 100% do not represent absolute agricultural moisture; they represent the dry-wet range of your sensor. Nevertheless, they are quite useful for irrigation decisions. To make more reliable decisions, you can use the average of the last 3 or 5 measurements instead of a single reading. This method reduces sudden spikes caused by sensor contact or electrical noise.
Sending and Publishing Data to a Web Panel
The step that truly makes the smart agriculture sensor useful is the ability to track measurements over time. Instead of just seeing the instantaneous moisture value, it is more accurate to view the watering needs, temperature changes, and light trends over the past 7 days. For this, you can send your sensor data to a web server, save it to a database using a simple PHP or Node.js API, and display it on a graphical panel.
A simple architecture may look like this: ESP32 reads the sensors, sends an HTTP POST request to the server in JSON format, the server validates the incoming data, and saves it to a MySQL database. On the panel side, the latest measurements can be shown in a table or graph. To publish this panel on your own domain, you can refer to How to Register a Domain and for stable publishing, Choosing a Suitable Web Hosting Package.
For security, add a simple token check to the API. For instance, the device sends a secret key with each request; the server does not save the data without validating this key. Protect the panel access with a password, keep the software updated, and always use HTTPS. If you plan to share data publicly, avoid disclosing precise location information, as the location of a greenhouse, field, or storage can be commercially significant.
Considerations for Those Wanting to Add Automatic Watering

Adding a relay and mini pump makes the project more impressive; however, care must be taken since water and electricity coexist in the same system. The Arduino should only act as a decision maker and should not power the pump directly from its pin. A separate adapter, relay, or MOSFET driver should be used for the pump. Low-voltage 5V or 12V DC pumps are safer for hobby projects.
The biggest risk in automatic watering is that the pump may run too long due to sensor errors. Therefore, set a maximum watering duration in the software. For example, even if the soil moisture is low, the pump should not run for more than 20 seconds and should wait until the next measurement. You can also set a limit for the maximum number of watering cycles per day. Such safety limits prevent a small sensor failure from drowning the plant or emptying the water reservoir.
Recommended Watering Logic
- If soil moisture is below the threshold, first validate with two consecutive measurements.
- Run the pump briefly; for example, for 10-20 seconds.
- After watering, wait at least 5 minutes for the soil to absorb the water.
- If moisture remains low, initiate a second short watering cycle.
- Limit the daily maximum number of operations in the software.
Outdoor Durability and Maintenance
A circuit that works on a laboratory bench may not operate the same way outdoors for extended periods. Humidity, rain, sun, insects, dust, and temperature differences strain electronic components. Therefore, place the circuit board in an IP65-rated enclosure, use glands at cable entries, and keep small moisture-absorbing packets inside the box to reduce condensation. When inserting the sensor tip into the soil, protect cable joints with silicone or heat shrink tubing.
A maintenance schedule is also important. Check weekly to ensure the sensor hasn't shifted, cables are not loose, and measurements are within reasonable ranges. Review calibration values monthly. If the sensor provides very different values under the same moisture conditions as before, the probe surface may be dirty, the connections may be oxidized, or the sensor may be worn out. Capacitive sensors tend to last longer than resistive ones, but they still do not last indefinitely in continuously moist environments.
Common Mistakes and Solutions
The most common mistake in initial setups is assuming the sensor values are the actual percentage moisture. Another mistake is submerging the soil moisture sensor entirely in water, which can damage its electronic components. Additionally, leaving the DHT sensor directly in sunlight can cause it to display higher temperature readings than actual. The temperature-humidity sensor should be positioned in the shade where it can receive airflow.
- Values consistently showing 0 or 100: Dry and wet calibration values may have been reversed or entered incorrectly.
- DHT sensor showing NaN: Check the library, pin selection, or cable connections.
- Arduino resets when the pump operates: The pump may be stressing the same power line; use a separate power source.
- Wi-Fi connection dropping: Check antenna position, power source, and signal strength.
- Measurements are very fluctuating: Try averaging, shortening cables, and ensuring a more stable power supply.
Interpreting Data: Turning Numbers into Decisions
The real value of the smart agriculture sensor is its ability to convert raw data into meaningful decisions. For instance, if soil moisture is low, temperature is high, and light levels are high, the plant may be losing water rapidly. Conversely, if soil moisture appears low but the air is cool and light is low, it may be possible to delay watering for a few hours. Therefore, looking at combinations instead of relying solely on single sensor data provides more accurate results.
When you record data for a week, you can see how quickly moisture drops after watering. If moisture drops rapidly at the same time each day, you can adjust your watering schedule accordingly. If moisture remains consistently high in some areas, there may be a drainage issue. Such observations can improve production quality, even on a small scale. If you wish to share the project as a blog or technical documentation, a project page published under your own domain can serve both as a portfolio and an educational resource. For this, you can explore Website Creation Guide and for secure publishing, SSL Certificate Installation content.
Ideas for Project Development
After running the basic system, you can develop the project in many directions. For example, by adding a rain sensor, you can postpone outdoor watering based on weather conditions. You can track nutrient solution with a pH sensor and EC sensor. By adding an OLED display, you can show measurements locally, and with an SD card module, you can keep records even without internet access. At a more advanced level, you can transfer data to platforms like Home Assistant using MQTT.
- Extending battery life by using deep sleep mode with ESP32
- Setting up an independent energy system with a solar panel and charging module
- Graphical reporting with Grafana or a custom panel
- Sending watering alerts via Telegram or email notifications
- Monitoring multiple sensors from a single hub
- Integrating a mobile application through an API
If you are setting up multiple devices, assign a unique device ID to each sensor. On the server side, regularly storing device ID, measurement time, sensor type, and value fields simplifies future analysis. As the database grows, a backup plan becomes essential. If your control panel will be used for business decisions, it is helpful to look into topics like Hosting Backup Solutions at an early stage.
Transforming the Project into a Blog in Terms of SEO and Content Publishing
This project does not have to remain just a technical experiment. You can contribute to the community by turning your measurement results, installation photos, problems encountered, and solution steps into a blog post while also creating a valuable technical resource for search engines. Technical DIY content should include clear photos, original measurement data, error-solving steps, and real user experiences that Google loves.
When publishing your article, clearly state the target topic in the title, inform the reader about what they will learn in the first paragraph, provide the materials list in a table, and support the code with explanations. Including your own test results strengthens E-E-A-T. For example, 'the capacitive sensor gave a value of 812 in dry soil and 428 after watering' differentiates the content from ordinary copy guides. For a fast and secure site to publish your project, you can explore Hostragons Hosting Packages.
Conclusion
Build Your Own Smart Agriculture Sensor with Arduino project is a viable starter project that combines electronics, software, and agricultural observation. With the right sensor selection, careful calibration, secure power design, and regular data recording, you can establish a useful decision support system for a small garden or greenhouse. If you want to monitor data on a web panel, reliable hosting, a domain name, and SSL infrastructure make the project more professional. When you're ready, you can securely launch your project by planning your domain and hosting environment through Hostragons.
Frequently Asked Questions
Is software knowledge required to build a smart agriculture sensor with Arduino?
Basic knowledge of using the Arduino IDE and editing ready-made code is sufficient. If you can change pin numbers, threshold values, and calibration ranges, you can complete the starter project. However, adding a web panel and API requires basic knowledge of HTTP, databases, and servers.
Which is better, capacitive soil moisture sensor or resistive sensor?
For long-term use, a capacitive soil moisture sensor is more suitable. Resistive sensors are more prone to corrosion in moist soil, which can lead to a loss of measurement accuracy over time. Capacitive models should be preferred for outdoor or greenhouse projects.
Can this system be used in real farming?
It is suitable for small-scale greenhouses, hobby gardens, educational projects, and preview purposes. It can provide benefits as a decision support system in commercial production; however, industrial sensors, redundant measurements, and professional automation safety are recommended for critical irrigation decisions.
Is it safe to display sensor data on the internet?
It can be secured. Using an API token, password-protecting the panel, enabling HTTPS, and keeping the software updated are necessary. Utilizing SSL on the domain and hosting to encrypt data transmission is a good starting point.
Can I run the Arduino sensor with a battery or solar panel?
Yes, but you need to reduce energy consumption. Extending the measurement interval, using deep sleep mode on the ESP32, powering sensors only during measurements, and adding a solar panel with an appropriate charging control module can enhance battery life.