PinoutSearch

Water Leak / Level Alert (Arduino)

Light an LED when water reaches the sensor — a leak detector or tank-level warning. Learn to power a sensor from a pin.

Beginner15 min

What you need

Wiring

Hover a pin or a wire to trace the connection.

Code

water_alert.ino
// Light an LED when water reaches the sensor.
const int sensorPower = 7;   // power the sensor from a pin
const int sensorPin   = A0;
const int ledPin      = 13;
const int threshold   = 300; // calibrate dry vs. wet

void setup() {
  pinMode(sensorPower, OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(sensorPower, HIGH);   // power on
  delay(10);
  int level = analogRead(sensorPin);
  digitalWrite(sensorPower, LOW);    // power off (less corrosion)

  Serial.println(level);
  digitalWrite(ledPin, level > threshold ? HIGH : LOW);
  delay(500);
}

Steps

  1. Wire: + to D7, − to GND, S to A0. LED on D13 through a 220Ω resistor to GND.
  2. Open the Serial Monitor; note readings dry vs. with water, set `threshold` between them.
  3. When water bridges the traces, the LED turns on.
  4. Powering + from D7 (not 5V) keeps the traces from corroding between reads.