Arduino Uno float switch wiring to D2 and ground

In this easy CircuitMagic tutorial you will build detect water level with arduino and float switch using Arduino Uno and one simple sensor. The project needs only a few connections and a short Arduino IDE sketch.

What does the sensor do?

A float switch changes contact state when the water reaches the float’s position. It is a simple on/off level detector, not a continuous depth sensor.

Required components

Arduino Uno, two-wire float switch, jumper wires, USB cable and container of water.

Connection diagram

The diagram below is a pin-to-pin connection map: each colored line shows one separate wire between labeled terminals, not a photograph of a particular board’s header layout.

float switch wiring diagram for Arduino Uno

Pin connections

Unplug USB power before wiring. The pin table is authoritative; always verify your board’s printed pin labels and your module’s pinout.

Arduino Uno pin / connectiontwo-wire water-level float switch connection
D2Float switch lead A
GNDFloat switch lead B

Arduino IDE setup

No additional library needed. Select the matching board and serial port, then upload this sketch.

Complete Arduino code

const int floatPin = 2;
void setup() {
  Serial.begin(9600);
  pinMode(floatPin, INPUT_PULLUP);
}
void loop() {
  bool contactsClosed = digitalRead(floatPin) == LOW;
  Serial.println(contactsClosed ? "Float switch CLOSED" : "Float switch OPEN");
  delay(300);
}

Expected output

Raise or lower the float: Serial Monitor changes between OPEN and CLOSED. Open Serial Monitor at the baud rate specified by Serial.begin().

Troubleshooting

Whether a CLOSED switch means high water depends on installation and float orientation. Keep the Arduino and USB connection away from water.

If there is no output, double-check the board and port, USB data cable, common ground, sensor pin labels and Serial Monitor speed.

Try next

Once the basic example works, experiment with the sampling delay, add an LED indicator, or log the sensor output to a computer. See more CircuitMagic electronics projects for related beginner tutorials.

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

or

Log in with your credentials

Forgot your details?