The red water level sensor is the strip with ten exposed traces that comes in many Indian starter kits for about ₹40. Water bridging the traces switches a transistor on a little more as the level rises, so the S output rises with depth.
On the Uno it is three wires: S to A0, − to GND, and + to D7. Using a pin instead of 5V for the supply is deliberate. The traces corrode quickly when they carry current all the time, so the sketch switches the strip on only for the 10 ms it takes to read.
Be realistic about what it measures. It covers only a few centimetres and is non-linear, so the sketch reports bands — no water, low, half, full — that you calibrate with your own water.
Wiring
| Arduino Uno R3 | Water level sensor (exposed-trace board) | Wire | Notes |
|---|---|---|---|
| A0 | S | yellow | |
| D7 | + | red | Switched supply: HIGH for 10 ms per reading. The strip draws under 20 mA. |
| GND | - | black |
3.3–5 V part, 5 V board. S can reach the supply voltage. Power the + pin from 3.3 V (or from a GPIO) on ESP32 and Pico, from 5 V on Uno, and S is always safe for your ADC.
Board quirks
- The strip senses only its bottom 4 cm or so. It suits a cup, a flower pot tray or a leak alarm on the floor — not a 1000-litre overhead tank. For tanks use a ultrasonic sensor or float switches.
- The output isn’t linear, and it depends on the water: borewell water reads higher than RO water at the same depth. Calibrate
EMPTY,HALFandFULLwith your own water. - With constant power the traces corrode within days. Feeding + from D7 only while reading slows that a lot.
- Keep the top of the board (with the transistor and pins) out of the water — only the traces go in.
Code
// Water level sensor (red strip with exposed traces) on an Arduino Uno R3.
// + → D7 (switched on only while reading), - → GND, S → A0.
// Calibrate EMPTY/HALF/FULL with your own water - the output depends on how mineral-rich it is.
const uint8_t POWER_PIN = 7, SENSOR_PIN = A0;
const int EMPTY = 50, HALF = 450, FULL = 600;
void setup() {
pinMode(POWER_PIN, OUTPUT);
digitalWrite(POWER_PIN, LOW);
Serial.begin(9600);
Serial.println(F("Water level sensor on A0 (powered from D7)"));
}
int readLevel() {
digitalWrite(POWER_PIN, HIGH);
delay(10);
int v = analogRead(SENSOR_PIN);
digitalWrite(POWER_PIN, LOW); // off between readings = far less corrosion
return v;
}
void loop() {
int v = readLevel();
Serial.print(F("S = "));
Serial.print(v);
Serial.print(F(" "));
if (v < EMPTY) Serial.println(F("No water"));
else if (v < HALF) Serial.println(F("Low"));
else if (v < FULL) Serial.println(F("Half"));
else Serial.println(F("Full"));
delay(2000);
}// Water level sensor (red strip with exposed traces) on an Arduino Uno R3.
// + → D7 (switched on only while reading), - → GND, S → A0.
// Calibrate EMPTY/HALF/FULL with your own water - the output depends on how mineral-rich it is.
const uint8_t POWER_PIN = 7, SENSOR_PIN = A0;
const int EMPTY = 50, HALF = 450, FULL = 600;
void setup() {
pinMode(POWER_PIN, OUTPUT);
digitalWrite(POWER_PIN, LOW);
Serial.begin(9600);
Serial.println(F("Water level sensor on A0 (powered from D7)"));
}
int readLevel() {
digitalWrite(POWER_PIN, HIGH);
delay(10);
int v = analogRead(SENSOR_PIN);
digitalWrite(POWER_PIN, LOW); // off between readings = far less corrosion
return v;
}
void loop() {
int v = readLevel();
Serial.print(F("S = "));
Serial.print(v);
Serial.print(F(" "));
if (v < EMPTY) Serial.println(F("No water"));
else if (v < HALF) Serial.println(F("Low"));
else if (v < FULL) Serial.println(F("Half"));
else Serial.println(F("Full"));
delay(2000);
}Expected serial output
Water level sensor on A0 (powered from D7)
S = 0 No water
S = 512 Half
S = 634 FullWater level sensor on A0 (powered from D7) S = 0 No water S = 512 Half S = 634 Full
Common errors
Reads 0 even in water
+ isn’t powered: check it goes to D7 and that the sketch sets D7 HIGH before reading. Very pure (distilled or RO) water barely conducts and also reads low.
Readings creep up over weeks
Corrosion and mineral build-up on the traces. Clean them gently, and power the sensor only when reading, as in the sketch.
Reading fluctuates while the water is still
Ripples and a wet board surface. Average a few readings and use the bands (low/half/full), not exact numbers.