• Usha Saha

Interfacing Water/Rain Sensor with Arduino

Updated: Dec 15, 2020

Let's talk about what a water sensor is! A water #sensor is typically a device that senses or detects the water levels. A water sensor is essentially used for the measurement of water level, detection of any leakage, monitor tanks, and water pump any many such similar activities. Through this article one can learn how to interface a water sensor with an #Arduino board in a very manageable way.


Apparatus Required:


These are the list of components used for the #interfacing purpose.


Components required

Water sensor:- A water sensor has three pins particularly VCC, ground, and analog output pins. The #hardware of a water sensor has 10 copper traces, 5 of them are for power traces, and the rest 5 of them are sense traces. The power and sense traces are placed alternately.


Water Sensor

Arduino Board:- Arduino Board can read inputs such as light on a sensor, a finger on a button, or a Twitter message and convert it to an output such as activating a motor, turning on an LED, publishing something online. All of this can be done by sending a set of instructions to the microcontroller on the board by the use of the Arduino programming language.


Arduino Board

Jumper wires:- Jumper wires are used for the connection purpose.

Jumper wires

Circuit Diagram:- The circuit connections are as follows. VCC(positive terminal) is connected to the 8th pin of the Arduino board using a jumper wire. The ground pin of Arduino is connected to the ground of the water sensor, and lastly, the analog pin(output pin) of the sensor is connected to A(0) of the Arduino board.


Note:- The positive terminal of the sensor can also be connected to pin 5 of the Arduino board, but here it is connected to pin 8 so that whenever output values are desired only then then-current should be supplied to the sensor hardware. For the rest of the time, the current movement is stopped because as soon as the current flows through the sensor it gets electrified and starts to corrode. Basically to make the sensor more durable and prevention form corrosion.

Circuit Arrangement

Code:


The codes for interfacing a water sensor with Arduino are as follows.


#define vcc 8

In the first step, the 8th pin is defined as Vcc.

#define s A0

A0 pin is defined as S. Here S means the output.

int value = 0;

A variable of data type integer is initialized as 0.

void setup() {
pinMode(vcc, OUTPUT);

Under void setup, the VCC pin is made the output with the code.

digitalWrite(vcc, LOW);

The VCC is set to zero.

void loop() {
 int level = water_level(); 

In the next void loop, the main water level function is requested which contains the major part of the program to be executed.

digitalWrite(vcc, HIGH);

Next, the VCC bit is made high this implies voltage is sent to the senor via code.

delay(10);

A delay of 10ms is introduced.

value = analogRead(s); 

The value obtained after switching on the VCC is stored in the variable S by the code.

digitalWrite(vcc, LOW);

Next, the VCC is again set up to zero.

return value;

With this code, the program returns to the second void loop.

Serial.println(level);

The value saved in the variable S is made available to the integer level and this level is printed.

delay(1000);

This loop repeats in every 1000ms that is every second.


#define vcc 8
#define s A0
int value = 0;
void setup() {
pinMode(vcc, OUTPUT);
digitalWrite(vcc, LOW); 
Serial.begin(9600);
}
void loop() {
 int level = water_level(); 
 Serial.print("Water level: ");
 Serial.println(level); 
 delay(1000);
 }
 int water_level() {
 digitalWrite(vcc, HIGH); 
 delay(10); 
  value = analogRead(s);   
  digitalWrite(vcc, LOW);   
   return value;  
   }


Download the codes from here:-

code
.txt
Download TXT • 439B

Working


The image of the circuit when the switch is off.

OFF switch

When the switch is ON that is code is successfully uploaded to the sensor. The sensor in the case is coded in such a way that when it is immersed in water it shows the water level. In the serial #monitor initially, the sensor shows minimum values when it is not immersed in water. Once the sensor is made to sink in the water the serial monitor readings start to increase and reach a maximum level when the sensor is completely submerged in the water. In the same way, reading starts to decrease when the sensor is taken out of the water.


Note:- The sensor reading won't come to zero as it was in the starting position because the water droplet is still present on the sensor. To make the #reading zero one has to remove all the water droplets from the surface of the sensor.


ON Switch

Video description: -

Learn Electronics. (Sept 8, 2020). "Interfacing Water/Rain Sensor with Arduino". https://www.youtube.com/watch?v=KcGZjaFDvOw


In this article, the water sensor is used for water level #measurement. Besides this water sensor can be used in the rainy season to detect rainfall, can be planted in a water tank as a water level alarm, to detect any leakage. It is also used as a precautionary measure for #submersible electronics.


See Also:

  1. INTERFACING SERVO MOTOR WITH ARDUINO

  2. Interfacing Relay Module with Arduino

  3. Interfacing Sound Sensor with Arduino


41 views
  • Facebook
  • YouTube
  • Instagram
  • LinkedIn
LearnElectronics
Contact Us
© Copyright - LearnElectronics 2021