Projects / Boat bilge leak alarm

Boat bilge leak alarm

Beginner1.7 hGuided buildReviewed

Build it step by step

0 of 9 done
  1. NANO

    Wire the sensor

    Plus to D7, minus to GND and S to A0.

  2. NANO18.6 mA

    Wire the buzzer and light

    Buzzer plus to D8, minus to GND, red LED through 220 ohms to D4.

  3. NANOWATER

    Upload the sketch

    The monitor says Bilge alarm armed and shows a level every 2 seconds.

  4. NANO

    Note the dry reading

    It should be close to 0.

  5. NANOWATER

    Dip the sensor tips in a glass of water

    The level climbs well above 200.

  6. NANO

    Keep it wet for 6 seconds

    The monitor prints ALARM and the light and buzzer begin.

  7. NANO

    Take it out and dry it

    The alarm keeps going because it is latched.

  8. NANO

    Press the reset button on the Nano

    The alarm is rearmed.

  9. NANO

    Mount it

    Fix the sensor low in the hull, with the electronics in a dry box.

In short

How do you build a boat bilge leak alarm?

A water sensor low in a model boat's hull gives a beeping, flashing alarm when water collects. The sensor is powered only for a moment each time it is read, so its copper traces do not corrode, and the alarm stays on until you reset it so a splash is never missed. You need Arduino Nano, Water level sensor module, Passive buzzer, LED 5 mm red, Resistor 220 Ω, USB A to micro-USB cable (data), Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 9 steps and about 100 minutes.

Level
Beginner
Time
About 100 min
Parts
8

Parts list

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

Wiring

FromToWhy
Water sensor +Nano D7Power only while reading, so it does not corrode
Water sensor -Nano GNDGround
Water sensor SNano A0Analog level, higher when wetter
Passive buzzer +Nano D8Alarm sound
Passive buzzer -Nano GNDReturn
Red LEDNano D4 through 220 ohms to GNDAlarm light, long leg towards the resistor

Code

The cheap water sensor board is a set of bare copper traces. When water bridges them, current flows and the signal pin rises, so a higher number on A0 means more water. Left powered all the time, a small direct current slowly eats away the copper through electrolysis, and the sensor stops working within weeks. So the sensor's positive pin is connected to a digital pin, D7, which is only switched on for ten milliseconds while the sketch takes a reading and then off again. It is a simple trick and it makes the sensor last. The sketch checks every two seconds, and to avoid false alarms from one splash or a drop clinging to the board, it needs three wet readings in a row, about six seconds, before it sounds. The alarm is latched, which means that once it starts it stays on, even if the water drains away, until you reset the board, so a leak that came and went is never missed. The red light and the buzzer flash and beep four times a second. A passive buzzer is driven with tone() at 2000 Hz, which is loud to the ear. The threshold of 200 is a starting value: print the readings, measure the sensor dry, in a damp cloth, and in water, then set WET_ABOVE between dry and damp. Mount the sensor low in the hull but keep the Nano, the buzzer and the power bank high and dry in a sealed box. This is a model or a hobby aid and not a safety device for a real boat.

Runs on a virtual Arduino Nano 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).

const uint8_t SENSOR_POWER = 7;
const uint8_t SENSOR_PIN = A0;
const uint8_t BUZZER = 8;
const uint8_t LED = 4;

const int WET_ABOVE = 200;               // counts above this mean water is touching the traces
const uint8_t NEED_IN_A_ROW = 3;         // this many wet readings in a row before we sound
const unsigned long CHECK_EVERY = 2000;  // read the sensor every 2 seconds

bool alarm = false;
uint8_t wetCount = 0;
unsigned long lastCheck = 0;

int readWater() {
  digitalWrite(SENSOR_POWER, HIGH);      // power the traces only for the reading
  delay(10);
  int v = analogRead(SENSOR_PIN);
  digitalWrite(SENSOR_POWER, LOW);
  return v;
}

void setup() {
  pinMode(SENSOR_POWER, OUTPUT);
  digitalWrite(SENSOR_POWER, LOW);
  pinMode(LED, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  Serial.begin(9600);
  Serial.println(F("Bilge alarm armed"));
}

void loop() {
  if (!alarm && millis() - lastCheck >= CHECK_EVERY) {
    lastCheck = millis();
    int v = readWater();
    Serial.print(F("Water level "));
    Serial.println(v);
    if (v > WET_ABOVE) wetCount++; else wetCount = 0;
    if (wetCount >= NEED_IN_A_ROW) {
      alarm = true;
      Serial.println(F("ALARM: water in the hull. Reset the board to rearm."));
    }
  }

  if (alarm) {                           // latched: stays on until the board is reset
    bool on = (millis() / 250) % 2;
    digitalWrite(LED, on);
    if (on) tone(BUZZER, 2000); else noTone(BUZZER);
  }
}

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 Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Bilge alarm armed
Water level 512
Water level 513
Water level 512
ALARM: water in the hull. Reset the board to rearm.

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Dry sensorLevel near 0, no alarm
Touch the tips with a damp fingerA small rise, still no alarm
Tips in water for 2 seconds onlyNo alarm, because three readings in a row are needed
Tips in water for 7 secondsALARM printed, light flashes and buzzer beeps
Remove the waterThe alarm continues until reset
Reset the NanoArmed again, alarm off

If it does not work

No alarm in water

Print the level and lower WET_ABOVE below the wet reading.

Alarm with a dry sensor

The sensor board may be damp, so dry it and raise WET_ABOVE.

Always reads 0

Check S goes to A0 and the plus pin goes to D7.

Silent alarm

A passive buzzer needs tone(), so check it goes to D8 and the right way round.

The traces are turning green

The sensor was powered all the time, so use the D7 pulse as in the sketch.

Upload fails

Choose the Old Bootloader option for the Nano.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the boat bilge leak alarm?

Arduino Nano, Water level sensor module, Passive buzzer, LED 5 mm red, Resistor 220 Ω, USB A to micro-USB cable (data), Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the boat bilge leak alarm take to build?

About 100 minutes for a beginner maker, in 9 steps.

How do I know the boat bilge leak alarm works?

Dry sensor: Level near 0, no alarm. Touch the tips with a damp finger: A small rise, still no alarm. Tips in water for 2 seconds only: No alarm, because three readings in a row are needed.

No alarm in water: what should I check?

Print the level and lower WET_ABOVE below the wet reading.

Alarm with a dry sensor: what should I check?

The sensor board may be damp, so dry it and raise WET_ABOVE.

Always reads 0: what should I check?

Check S goes to A0 and the plus pin goes to D7.

Silent alarm: what should I check?

A passive buzzer needs tone(), so check it goes to D8 and the right way round.