Reevan Miranda
Published © GPL3+

Water Level Monitor & Control

The microcontroller automatically switches the pump ON/OFF based on the water level. The user can use Assistant and a website too.

IntermediateFull instructions provided10 hours4,018
Water Level Monitor & Control

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Power MOSFET N-Channel
Power MOSFET N-Channel
×1
Resistor 10k ohm
Resistor 10k ohm
×5
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Amazon Alexa service
IFTTT Amazon Alexa service

Story

Read more

Schematics

Complete circuit diagram

The diagram contains:
- Interfacing Arduino Nano with Bolt
- Detecting water level via Analog pins of Nano
- Controlling the pump via D3 pin of Nano

Code

Python program for automatic water level control

Python
Running the following code will check water level every 10 seconds and display it. If the water level is below 20%, pump is switched ON and when it reaches 100% the pump is switched OFF.
import json,time,requests
from boltiot import Bolt 
mybolt = Bolt("API Key","Device ID")
while True:
    response = requests.request("GET","https://cloud.boltiot.com/remote/API Key/serialWR?data=getAnalogValues&deviceName=Device ID")
    data = json.loads(response.text)
    csv = data["value"]
    temp = csv.split(",")
    arr=[]
    for i in range(len(temp)-1):
        arr.append(int(temp[i]))
    print(arr)

    if arr[0] < 100:
        print("Water Level below 20%. Turning pump on")
        requests.request("GET","https://cloud.boltiot.com/remote/API Key/serialWR?data=pumpOn&deviceName=Device ID")
    elif arr[4] > 100:
        print("Water level 100%. Turning pump off")
        requests.request("GET","https://cloud.boltiot.com/remote/API Key/serialWR?data=pumpOff&deviceName=Device ID")
    else:
        if arr[3] > 100:
            print("Water level is at 80%")
        elif arr[2] > 100:
            print("Water level is at 60%")
        elif arr[1] > 100:
            print("Water level is at 40%")
        elif arr[0] > 100:
            print("Water level is at 20%")
        else:
            print("Error")
    time.sleep(10)

To check and control via Website

HTML
This is a website to see the water level and control pump manually.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Water Level</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="column s12">
                <div class="card">
                    <div class="card-content">
                        <div id="level">The water Level is : </div>
                        <div id="temp" ></div>
                    </div>
                    <div class="card-action">
                        <button class="btn" onclick="handle()">Update</button>
                        <button class="btn" onclick="on()">Switch On</button>
                        <button class="btn" onclick="off()">Switch Off</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>   
        function handle(){
            setKey("Your API Key","Your Device ID");
            serialWR('getAnalogValues','10','temp');
            setTimeout(()=>{
                var el = document.getElementById("level");
                var arr = temp.innerText.substring(11).split(",");
                if(arr[0]<100){
                    el.innerText += " Below 20%";
                }
                else if(arr[4]>100)
                {
                    el.innerText += " 100%";
                }
                else{
                    if(arr[3]>100)
                        el.innerText += " 80%";
                    else if(arr[2]>100)
                        el.innerText += " 60%";
                    else if(arr[1]>100)
                        el.innerText += " 40%";
                    else if(arr[0]>100)
                        el.innerText += " 20%";
                }
            },1500);
        }
        function on(){
            serialWR('pumpOn','10','temp');
        }
        function off(){
            serialWR('pumpOff','10','temp');
        }
    </script>
    <script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
</body>
</html>

To control pump via Alexa

XML
In IFTTT, create two applets:
- One having Alexa trigger as "Pump on"
- And the other having "Pump Off"
- For "That" section, select Webhooks and insert the given urls respectively.
https://cloud.boltiot.com/remote/ Your API Key /serialWR?data=pumpOn&deviceName= Your Device ID
https://cloud.boltiot.com/remote/ Your API Key /serialWR?data=pumpOff&deviceName= Your Device ID

Credits

Reevan Miranda

Reevan Miranda

1 project • 1 follower

Comments