Interfacing float sensor with Arduino

Float sensor is used in projects where you need to detect the level of water in a tank or any reservoir. In this tutorial we will see what is a Float sensor, How it works and how to interface this sensor with Arduino with wiring connections and the code.

FLOAT SENSOR SWITCH:

magnetic-float-sensor-switch

The float sensor consists of an electromagnetic switch. It operates just like any other switch. Here a Magnetic reed switch is placed in the stem of the sensor. A magnet will be in the bulb structure of float sensor. When water fills up in a reservoir the bulb structure which has the magnet starts moving up once water reaches a certain level. It moves up close to stem near the reed switch. Due to the force of attraction from this magnet reed switch closes indicating water level is high.

When the water level goes down the bulb moves down and reed switch contact breaks and by this way the system detects that water level has gone down and acts accordingly.

  • The maximum switch current of the float is 0.5A and the switch voltage of 100V DC.
  • The temperature rating is about 10-85 degrees centigrade.
  • The power rating of this sensor is about 10W.
  • The entire body of this sensor is made up of plastic.

INTERFACING THE MAGNETIC FLOAT SENSOR SWITCH WITH ARDUINO:

magnetic-float-sensor-switch

The float sensor consists of two terminals, VCC and GND. The VCC terminal of float sensor goes to digital pin 2 on the Arduino board and GND terminal to ground of Arduino board. It acts as a switch here and pin 2 of Arduino reads this switch state for either being high or low. Here we have used inbuilt LED of Arduino board as an indication for float and message of the switch state will be displayed in Serial monitor.

CODE:

int FloatSensor=2;   
int led=13;           
int buttonState = 1; //reads pushbutton status 

void setup() 
{ 
Serial.begin(9600); 
pinMode(FloatSensor, INPUT_PULLUP); //Arduino Internal Resistor 10K
pinMode (led, OUTPUT); 
} 
void loop() 
{ 
buttonState = digitalRead(FloatSensor); 
  if (buttonState == HIGH) 
  { 
    digitalWrite(led, HIGH);
    Serial.println( "WATER LEVEL - HIGH"); 
  } 
  else 
  { 
    digitalWrite(led, LOW);
    Serial.println( "WATER LEVEL - LOW" ); 
  } 
delay(1000); 
}

CODE EXPLANATION:

In this code, two components are available to indicate the Water level. They are LED and Serial monitor. We use three variables in this program. The following steps explain the program completely.

  • Initially, the sensor is connected to Pin 2 and LED in pin 13 that is the built-in LED on the Arduino board.
  • Initialize serial communication.
  • Now the digital values are read from the sensor and stored in the variable.
  • When variable “buttonState” is HIGH the sensor detects the water level as HIGH and it is prints the message “WATER LEVEL – HIGH” message in serial monitor and simultaneously LED glows.
  • When water level goes down “buttonState” goes low and Arduino prints “WATER LEVEL – LOW” message and LED turns off.
  • The program repeats reading the button state with a delay of 1 second.

APPLICATIONS OF FLOAT SENSOR:

  • Pump/Valve control
  • Fuel and Water Tanks.

I hope this tutorial explained you enough about Float sensor and how it interfaces with Arduino. Do check out our other tutorials related to Arduino. Do leave your comments/ feedback and queries related to this tutorial below, we will be happy to answer your questions.


Ask your query

avatar
  Subscribe  
Notify of