Kisan · Tutorial
Build a soil-moisture sensor for about ₹500
A capacitive probe and an ESP32 that reads your field's moisture every half hour and sends it to your PunjabiUni dashboard. Three wires, no soldering.
Why bother
Irrigation is one of the largest costs a farmer controls, and most of the waste comes from watering soil that is already wet. You cannot tell by looking: the top two inches dry out first, so a field can look parched at the surface and be perfectly damp at root depth.
This sensor measures moisture where the roots are and reports it every half hour to your Kisan dashboard, so the decision to irrigate is made from a number instead of a guess.
It is a genuinely small build: two components, three wires, no soldering, and no programming knowledge. You copy one file, change five lines in it, and press a button. Everything below assumes you have never used an Arduino before.
What you need
Roughly ₹500–₹800 all in. Prices and links below were checked on 2026-08-29; where no product page could be confirmed, the exact search terms are given instead of a guessed link.
| Part | What to look for | Approx. | Where |
|---|---|---|---|
| Capacitive soil-moisture sensor | Capacitive (NOT resistive), v1.2 or v2.0, 3.3–5.5 V, analog output. Capacitive is the important word — resistive probes corrode away in a few weeks in wet soil. | ₹55 | Robocraze |
| ESP32 development board | Any ESP32-WROOM-32 DevKit, 30-pin or 38-pin, with a micro-USB socket. This is the part that has WiFi and does the sending. | ₹399 | Robocraze |
| Jumper wires, female-to-female | 2.54 mm Dupont connectors, 20 cm, female on both ends — they push straight onto both boards' pins, so nothing needs soldering. A 40-piece set costs far less than buying three. | price not confirmed | Robocraze (category page) search: female to female jumper wires 40 pin 20cm |
| Micro-USB cable | A normal phone charging cable — but it must be a DATA cable, not charge-only. Many cheap cables carry power only, and the board will light up but never appear on your computer. | price not confirmed | any electronics shop search: micro USB data cable |
| Power supply | A 5 V USB phone charger and an outdoor socket, or a USB power bank. Deep sleep between readings is what makes a power bank last; a bank that switches itself off when current drops may need one with an 'always on' mode. | price not confirmed | any electronics shop search: USB power bank always on mode |
| Waterproofing for the sensor's top end · optional | Heat-shrink tubing or hot glue over the exposed electronics at the TOP of the probe. The probe's lower blade is designed to sit in soil; the header pins and board at the top are not. | price not confirmed | any electronics shop search: heat shrink tubing assorted |
| A weatherproof box for the ESP32 · optional | Any sealed plastic enclosure with a small hole for the wires. An electrical junction box works. The ESP32 must stay dry. | price not confirmed | any electronics shop search: IP65 plastic junction box |
How it goes together
Step by step
1. Install the Arduino IDE on a computer
Download the Arduino IDE from arduino.cc/en/software and install it. It is free, and it runs on Windows, Mac and Linux.
You only need the computer for this setup. Once the sensor is running it works on its own.
2. Teach the Arduino IDE about ESP32 boards
The IDE does not know about ESP32 boards until you tell it. Open File → Preferences, find the box labelled 'Additional boards manager URLs', and paste this line in:
https://espressif.github.io/arduino-esp32/package_esp32_index.json
Click OK. Then open Tools → Board → Boards Manager, type 'esp32' in the search box, and install the entry published by Espressif Systems. It is a large download — give it a few minutes.
When it finishes, go to Tools → Board and choose 'ESP32 Dev Module'.
3. Wire the sensor to the board
Three wires, with the ESP32 unplugged:
Sensor VCC → ESP32 pin marked 3V3. Sensor GND → ESP32 pin marked GND. Sensor AOUT (sometimes marked A0 or SIG) → ESP32 pin marked GPIO34 or just 34.
GPIO34 is not an arbitrary choice. The ESP32 has two analog converters, and the second one stops working the moment WiFi switches on. GPIO34 is on the first one. If you use a different pin, the sensor may read perfectly on the bench and return nonsense as soon as it connects to WiFi.
Do not connect the sensor to 5 V. The board is 3.3 V.
4. Download the code and make your own config file
Download both files at the bottom of this page and put them in a folder named exactly 'soil-sensor' — the Arduino IDE requires the folder name to match the .ino file name.
Rename config.example.h to config.h. (Keep the example file if you like; only config.h is read.)
Open config.h and fill in five things: your WiFi name, your WiFi password, your device key from the Kisan dashboard, the address readings are sent to, and a short name for this sensor.
The ESP32 only joins 2.4 GHz WiFi, never 5 GHz. If your router broadcasts both under one name, it usually still works — but this is the first thing to check if it never connects.
Never share your filled-in config.h. It holds your WiFi password and your device key.
5. Calibrate the probe — the two-cup method
Every probe is slightly different, so it has to be told what 'dry' and 'wet' mean. This takes two minutes and only has to be done once.
Plug the board into the computer with the USB data cable. In the Arduino IDE press the → (Upload) button, wait for 'Done uploading', then open Tools → Serial Monitor and set the speed to 115200.
Hold the probe in the open air, completely dry. Write down the 'Raw ADC' number it prints. That is your AIR_VALUE.
Stand the probe in a cup of water, up to but NOT past the line marked on the board. Write down that number. That is your WATER_VALUE.
Put both numbers into config.h and upload again. On a capacitive probe the air number is the HIGHER one — that is expected, wetter soil reads lower.
Using someone else's calibration numbers is the single most common reason these sensors report nonsense.
6. Install it in the field
Push the probe into the soil at root depth — for most field crops that is 15–20 cm — with the marked line staying above the surface. Do not bury the top of the board.
Waterproof the top of the probe and put the ESP32 in a sealed box with the wires coming out of a small hole facing downward, so rain cannot run in along them.
The sensor must be within reach of your WiFi. A field boundary is often further from the house than it looks.
Power it, and within a couple of minutes the first reading appears on your Kisan dashboard. After that it wakes every 30 minutes, sends one reading, and sleeps again.
The code
Both files below are the real files this site serves — what you see is byte-for-byte what the download gives you. Put them in one folder named soil-sensor, and rename config.example.h to config.h before uploading.
Loading…Loading…When it does not work
Every one of these has a specific cause. Work down the list — the first two account for most first-time failures.
The Arduino IDE cannot see the board at all — no port to select.
Why: Almost always a charge-only USB cable, or a missing USB driver.
Fix: Try a different micro-USB cable — one you know transfers files from a phone. If the port still does not appear, install the CP2102 or CH340 driver (the chip name is printed on the board next to the USB socket).
Upload fails with 'Failed to connect to ESP32'.
Why: Some boards need the BOOT button held while the upload starts.
Fix: Press Upload, and when the IDE prints 'Connecting......', hold the BOOT button until it starts writing. Release it then.
It never connects to WiFi — the Serial Monitor prints dots then 'timed out'.
Why: 5 GHz network, wrong password, or the sensor is out of range.
Fix: Confirm the network is 2.4 GHz. Re-check WIFI_SSID and WIFI_PASSWORD in config.h for stray spaces. Test the board indoors beside the router first; if it works there, the field position is out of range.
The reading is stuck at 0% or 100% and never moves.
Why: Almost always calibration, occasionally the wrong pin.
Fix: Redo the two-cup calibration and put YOUR numbers in config.h. If the raw value itself never changes between air and water, check that AOUT is on GPIO34 and not another pin.
Readings look plausible on the bench and turn to nonsense once it is outdoors on WiFi.
Why: The sensor is wired to an ADC2 pin, which the WiFi radio takes over.
Fix: Move the sensor's AOUT wire to GPIO34 (or another of GPIO32–39).
The server replies 401.
Why: The device key is wrong, or has been replaced.
Fix: Copy KISAN_API_KEY again from where you saved it when the account was set up. Keys are shown once and are not recoverable — if it is lost, a new one has to be issued.
The server replies 400.
Why: The reading itself was rejected.
Fix: The server's reply, printed in the Serial Monitor, names the field it did not like. A moisture value outside 0–100 usually means calibration is inverted — check that AIR_VALUE is larger than WATER_VALUE.
It works for a few days, then stops.
Why: Usually power or water.
Fix: Check the power bank has not switched itself off (many do when current drops during deep sleep — use one with an 'always on' mode), and check no water has reached the ESP32 or the top of the probe.
ਕਿਸਾਨ