Paddy field water depth sensor
Build it step by step
0 of 6 doneBuild the float
Glue the magnet in a small sealed float that slides inside a perforated vertical pipe.
Fix the sensor
Mount the A1302 on the outside of the pipe, close to the float's travel.
Read the sensor
Print readHall() and note it with the float at 0, 5 and 10 cm of water.
Put in the calibration
Replace CM_AT_0 and CM_AT_10 with your readings.
Send over LoRa
Upload and check a second LoRa node receives the depth message.
Waterproof
Put the electronics in a sealed box above flood level and let the pipe stand in the field.
How do you build a paddy field water depth sensor?
A float with a magnet in a pipe moves a hall sensor's reading to measure field water depth, helping farmers save water with alternate wetting and drying. You need ESP32 DevKit V1, A1302 linear hall sensor, Neodymium magnets (10 × 3 mm), RFM95W LoRa module (868 MHz), 868 MHz LoRa antenna, 18650 cell 2600 mAh (branded) and Battery holder 18650 single. It takes 6 steps and about 240 minutes.
- Level
- Intermediate
- Time
- About 240 min
- Parts
- 7
Wiring
| From | To | Why |
|---|---|---|
| A1302 pin 1 (VCC) | ESP32 3V3 | Power (runs at 3.3 V, centre is about 1.65 V) |
| A1302 pin 2 (GND) | ESP32 GND | Ground |
| A1302 pin 3 (OUT) | ESP32 GPIO34 | Analog reading |
| RFM95W 3.3V, GND | ESP32 3V3, GND | Power |
| RFM95W SCK | ESP32 GPIO18 | SPI clock |
| RFM95W MISO | ESP32 GPIO19 | SPI data in |
| RFM95W MOSI | ESP32 GPIO23 | SPI data out |
| RFM95W NSS | ESP32 GPIO5 | Chip select |
| RFM95W RESET | ESP32 GPIO14 | Reset |
| RFM95W DIO0 | ESP32 GPIO26 | Interrupt |
| RFM95W ANT | 868 MHz antenna | Never power without the antenna |
Code
Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module". Install "LoRa" by Sandeep Mistry. Use only the 865 to 867 MHz band that is licence-free in India and follow your local rules for power and duty cycle. Calibrate the two end readings with water at 0 and 10 cm, and check your own agronomy guidance for the alternate wetting and drying limit. Power: the 18650 cell is 3.0 to 4.2 V, so use an ESP32 board with a battery input and charger, or keep it on a solar-charged supply; a plain dev board's 5 V pin needs 5 V.
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <SPI.h>
#include <LoRa.h>
const byte HALL = 34;
const float CM_AT_0 = 2300, CM_AT_10 = 1500; // readings at 0 and 10 cm; replace with your calibration
const unsigned long SLEEP_US = 12ULL * 3600ULL * 1000000ULL; // twice a day
const long FREQUENCY = 865200000; // licence-free 865 to 867 MHz band in India; check your local rules
int readHall() {
long s = 0;
for (byte i = 0; i < 32; i++) { s += analogRead(HALL); delay(5); }
return s / 32;
}
void setup() {
Serial.begin(115200);
float depthCm = 10.0 * (readHall() - CM_AT_0) / (CM_AT_10 - CM_AT_0);
LoRa.setPins(5, 14, 26);
if (LoRa.begin(FREQUENCY)) {
LoRa.setTxPower(14);
LoRa.beginPacket();
LoRa.print("PADDY1,");
LoRa.print(depthCm, 1);
LoRa.endPacket();
}
Serial.print("Depth cm: "); Serial.println(depthCm, 1);
LoRa.sleep();
esp_sleep_enable_timer_wakeup(SLEEP_US);
esp_deep_sleep_start();
}
void loop() {}
/* ---- Receiver (another ESP32 with an RFM95W on the same pins) ----
void setup() { Serial.begin(115200); LoRa.setPins(5, 14, 26); LoRa.begin(865200000); }
void loop() {
if (LoRa.parsePacket()) {
String s = LoRa.readString();
Serial.println(s);
float cm = s.substring(s.indexOf(',') + 1).toFloat();
if (cm < -15.0) Serial.println("Field is dry enough: irrigate again"); // alternate wetting and drying rule
}
}
*/What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Depth cm: 3.2 [deep sleep for 720 min 0 s]
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Float at 0 cm | Reports about 0.0 |
| Float at 5 cm | About 5.0 |
| Float at 10 cm | About 10.0 |
| Receiver in range | Shows PADDY1 with the depth twice a day |
If it does not work
Reading does not change
The magnet is too far or the wrong pole faces the sensor.
LoRa begin fails
Check the SPI wires, NSS and that the antenna is attached.
No message received
Both ends must use the same frequency and settings.
Battery drains quickly
Make sure the ESP32 goes to deep sleep after sending.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the paddy field water depth sensor?
ESP32 DevKit V1, A1302 linear hall sensor, Neodymium magnets (10 × 3 mm), RFM95W LoRa module (868 MHz), 868 MHz LoRa antenna, 18650 cell 2600 mAh (branded) and Battery holder 18650 single.
How long does the paddy field water depth sensor take to build?
About 240 minutes for a intermediate maker, in 6 steps.
How do I know the paddy field water depth sensor works?
Float at 0 cm: Reports about 0.0. Float at 5 cm: About 5.0. Float at 10 cm: About 10.0.
Reading does not change: what should I check?
The magnet is too far or the wrong pole faces the sensor.
LoRa begin fails: what should I check?
Check the SPI wires, NSS and that the antenna is attached.
No message received: what should I check?
Both ends must use the same frequency and settings.
Battery drains quickly: what should I check?
Make sure the ESP32 goes to deep sleep after sending.
