Overview:
Have you ever found yourself turning ON or OFF your house's water supply to fill a water tank? This can be a time-consuming process as you have to always wait until the tank is full and turn the water supply off before the tank will overflow to avoid wasting water.
This blog demonstrates a project that automatically fills up a water tank and turns off the water supply once the tank is full. The system then notifies the user regarding the status of the water tank. With this, you don't have to worry about turning ON or OFF your water supply anymore!
Hardware Used:
Software Used:
Application Description:
- SIM800L V2 module
- Solenoid Valve Plastic
A solenoid valve is an electromechanically operated valve. Solenoid valves work by employing the electromagnetic coil to either open or close the valve orifice. When the coil within the solenoid is energized, the plunger is lifted or lowered to open or close the orifice. This is what in turn controls the flow, regulating the movement of gas or liquid.
- Water level float switch
A compact, horizontally mounted float switch which can be configured as a normally-open or normally-closed switch simply by rotating it through 180°. When the water level reaches the float, the float moves and an internal magnet activates a sealed reed relay in the device. The sensor is supplied pre-wired with output leads.
- Relay
A relay module is an electrical switch that is operated by an electromagnet. The electromagnet is activated by a separate low-power signal from a microcontroller, in this case, the Arduino Uno. When activated, the electromagnet pulls to either open or close an electrical circuit.
The relay module used in the project is a single channel relay (those blue cubes). There are other models with two, four and eight channels.
Hardware Setup:
Pin Configuration
- S pin on relay module to pin 11 of Arduino Uno
- Common node to one of the pins on the Solenoid Valve
- Normally open (NO) node to the 12V power supply
- One end of the Float Switch to the pin 10 of Arduino Uno
- The other end of the Float Switch to the GND pin of Arduino Uno
- TXD pin on SIM800L module to pin 2 of Ardiuno Uno
- RXD pin on SIM800L module to pin 3 of Arduino Uno
- When powering the SIM800L module, add a capacitor (around 1000uF) parallel to the power supply to ensure stable supply of power.
Software setup:
How to include the Arduino SoftwareSerial Library
To send SMS messages using the SIM800L module, we will be using the Software Serial library. In order to include this library in your code, go to Sketch -> Include Library -> SoftwareSerial
Code:
#include
SoftwareSerial sim800l(2, 3);
int FloatSensor=10;
int relay = 11;
bool current_State = LOW;
bool previous_State = LOW;
void setup() {
Serial.begin(9600);
sim800l.begin(9600);
pinMode(FloatSensor, INPUT_PULLUP);
pinMode(relay, OUTPUT);
delay(30000); // 30 second delay for the SIM800L v2 module to be connected to the network
}
void loop() {
Serial.println("Reading Water Level. . . .");
current_State = digitalRead(FloatSensor);
if (current_State != previous_State){
if (current_State == LOW){ // Tank is full
digitalWrite(relay, LOW);
SendSMS("Tank is Full. Solenoid Valve is now turned OFF!");
} else { // Tank is Not Full
digitalWrite(relay, HIGH);
SendSMS("Tank is not full. Turning ON the Solenoid Valve");
}
}
previous_State = current_State;
delay(1000);
}
void SendSMS(String text) {
sim800l.print("AT+CMGF=1\r");
delay(100);
sim800l.print("AT+CMGS=\"+63XXXXXXXXXX\"\r"); // Enter the number where the SMS will be sent to
delay(500);
sim800l.print(text);
delay(500);
sim800l.print((char)26);
delay(500);
sim800l.println();
Serial.println("Text Sent.");
delay(500);
}
}
Code breakdown:
- Code block before the setup() function
- setup()
- loop()
Firstly, the signal from the float switch is read using the digital.read() function and is saved in the current_State variable.
Then, the value in curent_State is compared to the value of the previous_State. The code first checks if the values are different, to avoid accessing the Solenoid valve and SIM800L module over and over again. Only when the two states are different, the Solenoid valve and SIM800L module is accessed and the next steps are taken.
- If the float switch detects low water, the solenoid valve is opened to let water into the tank and the SIM800L module sends a message to the user saying, "Tank is not full. Turning ON the Solenoid Valve".
- If the float switch detects a full tank, the solenoid valve is closed and the SIM800L module sends a message to the user saying, "Tank is Full. Solenoid Valve is now turned OFF!".
- SendSMS()
-
sim800l.println("AT+CMGF=1")
-Sets the GSM Module in Text Mode -
sim800l.print("AT+CMGS=\"+63XXXXXXXXXX\"\r")
-Sets the number that the SMS will be sent to - sim800l.println((char)26)
-ASCII code of CTRL+Z as terminating character
Output:
Below is a link to a video demonstration of the working project.
Conclusion:
This blog shows an automated system which can be used to fill up a water tank using a solenoid valve and a float switch. When the float switch detects a low water level, the solenoid valve is opened to fill the tank. Once the water tank is filled up to the level of the float switch, the solenoid valve is then closed to stop the water inflow. A SIM800L module is used to notify the user via SMS regarding the status of the system.
References:
https://miliohm.com/sim800l-v2-tutorial-with-arduino/