Float Switch

By Emir

In this tutorial you will learn how to use float switch. In our case, it is used to notify if the tank is full of water or when it is empty, but you can use it in any other way you see fit.

Step 1

Bill of materials

  • Arduino board with USB cable (we use Arduino Uno)
  • Float switch sensor
  • Glass of water
Step 2

Connect float switch to Arduino board

Float switch has two wires attached.

Connect one wire to GND and another to any digital pin on Arduino. We chose pin 7 in this tutorial.

Step 3

Open Arduino IDE and write code

Write following code in Arduino IDE:

int floatswitch = 7;

void setup() {
pinMode(floatswitch,INPUT_PULLUP);
Serial.begin(9600);
}

void loop() {
 int x = digitalRead(floatswitch);
 Serial.println(x);
}
show more
Step 4

Upload code to Arduino

Connect Arduino with computer using USB cable.

Select "Tools"->"Board"->[Arduino board]. In our case it is Arduino Uno.

Then select "Tools"->"Serial port"->[Your serial port used for communication with Arduino]. In our case it is /dev/tty.usbmodem1411.

Click on "File"->"Upload" to upload code to Arduino.

Step 5

Test results

Open Serial Monitor and see results.

Put float switch in glass of water and check results again.

When float switch is up, serial monitor will print "1" and when float is down it will print "0".

show more

Tutorial Forum

There are no posts here yet. Add the first post