Projects / Paddy field water depth sensor

Paddy field water depth sensor

Intermediate4 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. ESP32

    Build the float

    Glue the magnet in a small sealed float that slides inside a perforated vertical pipe.

  2. ESP32A1302

    Fix the sensor

    Mount the A1302 on the outside of the pipe, close to the float's travel.

  3. ESP32A1302

    Read the sensor

    Print readHall() and note it with the float at 0, 5 and 10 cm of water.

  4. ESP32

    Put in the calibration

    Replace CM_AT_0 and CM_AT_10 with your readings.

  5. ESP32RFM95W868

    Send over LoRa

    Upload and check a second LoRa node receives the depth message.

  6. ESP32

    Waterproof

    Put the electronics in a sealed box above flood level and let the pipe stand in the field.

In short

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

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
A1302 pin 1 (VCC)ESP32 3V3Power (runs at 3.3 V, centre is about 1.65 V)
A1302 pin 2 (GND)ESP32 GNDGround
A1302 pin 3 (OUT)ESP32 GPIO34Analog reading
RFM95W 3.3V, GNDESP32 3V3, GNDPower
RFM95W SCKESP32 GPIO18SPI clock
RFM95W MISOESP32 GPIO19SPI data in
RFM95W MOSIESP32 GPIO23SPI data out
RFM95W NSSESP32 GPIO5Chip select
RFM95W RESETESP32 GPIO14Reset
RFM95W DIO0ESP32 GPIO26Interrupt
RFM95W ANT868 MHz antennaNever 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.

CheckExpected
Float at 0 cmReports about 0.0
Float at 5 cmAbout 5.0
Float at 10 cmAbout 10.0
Receiver in rangeShows 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 →

Ask Lark AI

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.