Arduino nano Water Level Sensor

The Arduino Nano Water Level Sensor measures liquid depth using a conductive‑trace water level sensor connected to the Arduino Nano board. It is used in water‑tank monitors, leak‑detection alarms, and level‑control systems for aquariums, tanks, or industrial fluid containers.

Arduino Nano Water Level Sensor

The Water Level Sensor project demonstrates how to measure liquid depth using a conductive‑trace water level sensor with an Arduino Nano. The sensor outputs an analog voltage that changes with the water level, and the Arduino converts this into a readable level (e.g. low, medium, high or in millimeters) and can trigger LEDs, buzzers, or messages when the level crosses a set threshold.

About the Water Level Sensor

A typical water level sensor module exposes a PCB with parallel or interdigitated copper traces that act as a variable resistor. When the sensor is immersed in water, the liquid bridges the exposed traces, reducing the resistance. The deeper the water, the better the conductivity and the lower the resistance, which increases the output voltage read by the Arduino’s analog pin.

Most modules operate at 3.3–5 V, have a small detection area (about 40×16 mm), and provide an analog output signal plus a power LED. The sensor does not directly output a calibrated distance; instead, you must calibrate the relationship between raw analog values and water level for your own tank or container.

Components Needed

  • Arduino Nano
  • Water level sensor module
  • LEDs (e.g. green, yellow, red for low/medium/high warning)
  • 220 Ω resistors (for each LED)
  • Buzzer (optional, for alarm)
  • Jumper Wires
  • Breadboard
  • Water‑resistant container or tank for testing

Circuit Setup

1. Connect Water Level Sensor to Arduino Nano:

Most water level sensor modules expose three pins:

  • VCC → 5V or 3.3V on the Arduino Nano (check module datasheet; many are 3.3–5 V).
  • GND → GND on the Arduino Nano.
  • S (Signal) → analog pin A0 on the Arduino Nano.

2. Connect Indicator Devices:

  • Connect green / low LED anode to e.g. D3, via a 220 Ω resistor; cathode to GND.
  • Connect yellow / medium LED to D4 (with 220 Ω) and red / high LED to D5 (with 220 Ω).
  • Optionally connect a buzzer to D6 for audible alarm at high level or empty‑tank states.

How the Water Level Sensor Works

The Arduino reads the analog output of the water level sensor using `analogRead(A0)`, which returns a value from 0 to 1023. When the sensor is dry, the resistance is high so the output voltage is low; as water rises and bridges more traces, the resistance drops and the voltage rises, giving a higher analog value. By calibrating a few levels (e.g. 0 mm, 10 mm, 20 mm, 40 mm), you can map the raw value to a meaningful level or distance.

A simple example uses three thresholds: below 300 for “low”, 300–700 for “medium”, and above 700 for “high”, lighting the appropriate LED(s) and optionally sounding a buzzer when the level is too high or too low.

Program: Arduino Nano Water Level Sensor (With LED Indicators)
/*
Water Level Sensor with Arduino Nano
*/

// Water level sensor analog pin
const int waterPin = A0;

// LED pins for low/medium/high
const int ledLow = 3;
const int ledMedium = 4;
const int ledHigh = 5;
const int buzzerPin = 6;

// Example threshold values (calibrate for your setup)
const int lowThresh = 300;
const int mediumThresh = 700;

void setup() {
  pinMode(ledLow, OUTPUT);
  pinMode(ledMedium, OUTPUT);
  pinMode(ledHigh, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  
  digitalWrite(ledLow, LOW);
  digitalWrite(ledMedium, LOW);
  digitalWrite(ledHigh, LOW);
  digitalWrite(buzzerPin, LOW);
  
  Serial.begin(9600);
  Serial.println("=== WATER LEVEL SENSOR READY ===");
  Serial.println("Raw	Level");
}

void loop() {
  // Read the sensor
  int raw = analogRead(waterPin);
  
  // Reset all LEDs
  digitalWrite(ledLow, LOW);
  digitalWrite(ledMedium, LOW);
  digitalWrite(ledHigh, LOW);
  digitalWrite(buzzerPin, LOW);
  
  if (raw < lowThresh) {
    // Low level
    digitalWrite(ledLow, HIGH);
    digitalWrite(buzzerPin, HIGH);
    Serial.println(F("LOW"));
  } else if (raw < mediumThresh) {
    // Medium level
    digitalWrite(ledMedium, HIGH);
    Serial.println(F("MEDIUM"));
  } else {
    // High level
    digitalWrite(ledHigh, HIGH);
    digitalWrite(buzzerPin, HIGH);
    Serial.println(F("HIGH"));
  }
  
  // Optional: print raw value for calibration
  Serial.print(raw);
  Serial.print("\t");
  
  delay(200);
}

Instructions

1. Circuit Setup:

Wire the water level sensor according to the pinout described above, taking care not to short the exposed traces with tools or metal and to avoid powering the board from sources that might exceed its 3.3–5 V range.

2. Calibration:

Place the sensor in your tank and slowly fill it with water. Open the Serial Monitor (9600 baud) and note the raw values at 0 mm, 10 mm, 20 mm, 30 mm, and 40 mm of immersion. Adjust `lowThresh` and `mediumThresh` in the code so that the LEDs switch at the desired levels (for example, warning at 35–40 mm to avoid overflow).

3. Code Upload:

Connect the Arduino Nano to your computer via USB, open the Arduino IDE, paste the water‑level‑sensor code, and upload it to the board.

4. Testing:

Submerge the sensor partially in water and observe the LEDs changing color as the level changes. The buzzer should sound when the level is too low or too high, according to your chosen thresholds.

Applications

Water‑Tank Monitors: Use the sensor inside a domestic or industrial water tank to warn when the level is low or dangerously high, preventing overflow or dry‑pump conditions.

Aquarium and Fish‑Tank Systems: Monitor water depth and trigger alarms or automatic pumps when the level falls below a safe height.

Leak and Flood Detection: Place the sensor near the floor or in a sump area to detect unwanted water presence and trigger alerts or water‑shut‑off valves.

Troubleshooting

  • Sensor reads near 0 or 1023 all the time? Check VCC, GND, and S‑pin wiring; also inspect the exposed traces for corrosion or damage.
  • Inconsistent readings at the same level? Ensure the sensor is mounted vertically, the tank walls are smooth, and the water is reasonably clean; avoid air bubbles or foam on the sensor surface.
  • LEDs or buzzer never respond? Verify that the LED and buzzer pins match your circuit and that the thresholds in the code are wide enough to cover the sensor’s range.

Best Practices and Notes

  • Keep the sensor’s exposed traces clean and avoid harsh chemicals or abrasive cleaning that can damage the copper.
  • Power the sensor using a stable 3.3–5 V supply; avoid long or noisy power lines that can introduce fluctuations in the readings.
  • For continuous submersion, choose a module that is rated for long‑term water exposure or add a protective coating such as clear lacquer (only on the non‑sensing areas), ensuring the sensing traces remain uncovered.

Extensions and Ideas

You can extend this project by adding an LCD or OLED display to show the level in millimeters or percentage, or by using the Arduino Nano to control a pump or valve that fills or drains the tank when the level crosses a set threshold, or by logging the sensor values over time to an SD card for analysis of daily water‑usage patterns.