DIY ELECTRONICSTR

← All projects

Level Measurement with a Water Level Sensor

Beginner15 min

A starter project that reads the water level sensor's analog output and writes the level as Empty, Low, Medium or High to the Serial Monitor once a second. As the sensor's parallel tracks go under water, the resistance drops and the reading rises. The thresholds (100, 400, 450) depend on the water's conductivity and the sensor; watching the raw values first and setting your own thresholds gives better results. Only dip the lower part with the tracks in water; keep the electronics and pins at the top dry. To reduce corrosion, do not leave the sensor powered all the time. No extra library needed.

Build it step by step in the app

What you need

Wiring steps

  1. 1

    Power the sensor

    Power the sensor

    Plug a red jumper wire into the 5V pin on the Arduino's POWER header. Connect its other end to the sensor's pin marked +.

  2. 2

    Ground (GND) connection

    Ground (GND) connection

    Plug a black jumper wire into the GND pin on the Arduino's POWER header. Connect its other end to the sensor's pin marked −.

  3. 3

    Connect the signal (S) line

    Connect the signal (S) line

    Plug a blue jumper wire into pin A0 on the Arduino's ANALOG IN header. Connect its other end to the sensor's S (signal) pin. The code reads the water level on this pin as a value from 0 to 1023 (sensorPin = A0).

Arduino sketch

const int sensorPin = A0; 
int value = 0; 

void setup() {  
    // analogRead için pinMode tanımlamaya gerek yoktur, donanımsal olarak ayarlanır.
    Serial.begin(9600); 
}  

void loop() {  
    value = analogRead(sensorPin);  
    
    if (value <= 100) {  
        Serial.println("Water Level: Empty");  
    }  
    else if (value <= 400) {  
        Serial.println("Water Level: Low");  
    }  
    else if (value <= 450) {  
        Serial.println("Water Level: Medium");  
    }  
    else {  
        // Değer 450'den büyükse otomatik olarak buraya düşer
        Serial.println("Water Level: High");  
    } 
    
    delay(1000);  
}

What the Serial Monitor shows

SERIAL MONITOR · 9600 BAUD
Water Level: Empty
Water Level: Empty
Water Level: Low
Water Level: Low
Water Level: Medium
Water Level: High
Water Level: High

In the app, tick off every wire, match the parts to your inventory and pick up where you left off.

Build it step by step in the app