A water sensor module detects the presence of water or moisture and provides an analog output on the S pin. Connect GND to ground, VCC to the module’s power supply, and read S with an Arduino/ESP32 analog input to get a varying signal that reflects moisture or wetness level.
| Pin | Signal | Description |
|---|---|---|
GND |
ground | Ground return for the water sensor module. |
VCC |
power | Positive supply input for the water sensor, typically 3.3V or 5V. |
S |
analog | Analog sensor output proportional to detected water level or conductivity. |
| From | To | Wire |
|---|---|---|
board:GND |
x1:GND |
black |
board:5V |
x1:VCC |
red |
board:A0 |
x1:S |
green |
This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.
// Water Sensor canonical example for Arduino Uno
// Reads the analog output from the water sensor and prints it to Serial.
const int waterSensorPin = A0;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Water Sensor example starting...");
}
void loop() {
int sensorValue = analogRead(waterSensorPin);
Serial.print("Water sensor analog value: ");
Serial.println(sensorValue);
delay(500);
}
Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.
Start for free