solenoid valve controlled by arduino and sim800l

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: 

  • Arduino UNO R3

  • Solenoid Valve Plastic
  • 
    
  • SIM800L V2 module
  • 
    
  • Water Level Sensor Float Switch
  • 
    
  • Relay Module
  • 
    
  • Breadboard
  • 
    
  • Jumper Wires
  • 
    
  • Micro USB to USB cable
  • Software Used: 


    Application Description: 

    • SIM800L V2 module
    The SIM800L V2 is a GSM/GPRS module which allows you to send an SMS message, make a call, and transfer data through the GPRS/GSM unit. This SIM800L module has a set of TTL level serial interfaces, a set of power supply interfaces, as well as a set of antennae for use when interfacing the module to a microcontroller like Arduino.
    • Solenoid Valve Plastic 

    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 Water Level Sensor Float Switch is used to sense the level of the liquid within a tank. It may actuate a pump, an indicator, an alarm, or other device.

    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

    Relay module Connections
    • 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

     

    Water Float Level Switch 
    • 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 

     

    SIM800L V2 module
    • 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 
      Here the Software Serial library is included and initialized so that the communication between the SIM800L module and the Arduino Uno happens through the Pin 2 and 3 of the Uno. Next, the necessary variables are initialized. 
      • setup()
      Serial.begin(9600) and sim800L.begin(9600) tells the Arduino to get ready to exchange messages with the Serial Monitor and the SIM800L module at a data rate of 9600 bits per second.
      • 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_StateThe 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()
      This function is used to access the SIM800L module.
      • 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/ 

      1-channel solid state relay12v/2a solenoid lockArduinoArduino unoFloat switchRelayRelay moduleSim800lSim800l v2SolenoidSolenoid valveWater level float switch

      Leave a comment

      All comments are moderated before being published