IOT Based Water Level Controller Using NodeMCU ESP8266

Introduction: IOT Based Water Level Controller Using NodeMCU ESP8266

About: I am a professional blogger from India.

This is Instructable on how to create an IOT based water level controller.

Features of this project are:-

  • Real-time water level updates on the Android app.
  • Automatically turn ON the water pump when water reaches below a minimum level.
  • Automatically turn OFF water pump when water reaches above a maximum level.
  • Manual option to control the water pump at any water level.

Requirements:-

    1. NodeMCU ESP8266 development board
    2. HCSR04 ultrasonic sensor
    3. Breadboard
    4. Single channel relay board (to control water pump)
    5. LM7805 +5V voltage regulator IC.
    6. Battery (9V-12V).
    7. WiFi Router (to connect NodeMCU to internet)
    8. Firebase (to create a database)
    9. MIT app inventor 2 (to create Android application)

    So let's get started.

    Step 1: Setup Firebase and Get Secret Key

    We are going to use a real-time database by Google firebase. This real-time database will act as a midway broker between Nodemcu and Android device.

    • First of all, navigate to firebase site and log in using your google account.
    • Create a new real-time database.
    • Get real-database URL and secret key to access the database from the app. For a detailed tutorial, you can check out how to integrate firebase with MIT app inventor.

    Step 2: Create App Using MIT App Inventor 2

      We are going to use MIT app inventor 2 to create our Android app. Its very simple to use and easy to integrate win Google firebase.

      Just follow these steps:-

      • Download MIT app inventor project file (.aia file) attached below.
      • Then go to MIT app inventor >> projects >> import project (as shown in screenshot 1). Select the file from your computer and upload it.
      • Open project and navigate to Screen3 (as shown in screenshot 2).
      • After that, go to layout window, click on firebaseDB1 (located at bottom of the workspace), enter database URL and key. Also set ProjectBucket to S_HO_C_K (as shown in screenshot 3).
      • At last, click on the "build" button and save app file (.apk file) to your computer. Later transfer that file to your Android device.

      Step 3: Configure Arduino IDE for Nodemcu Esp8266

      • First of all, configure Arduino IDE for Nodemcu esp8266. I would recommend this step by step tutorial on NodeMCU basics by Armtronix. Thanks Armtronix for this helpful tutorial.
      • After that, add these two libraries (as shown in screenshot) :-

      1. Arduino Json

      2. Firebase Arduino

      Step 4: Upload Code With Some Necessary Changes

      You must do some necessary changes in code before uploading to Nodemcu.

      • Download attached file (.ino file) and open it with Arduino IDE.
      • At line 3, enter database URL without 'https://'.
      • At line 4, enter database secret key.
      • At line 5 and 6, don't forget to update WiFi SSID and Wifi password (to which you want to connect NodeMCU ESP8266).
      • Scroll down a little bit and update minimum water level, maximum water level, and margins according to the depth of your own water tank.

      After that, upload program to NodeMCU ESP8266.

      Step 5: Configure Hardware

      • Create a circuit as shown in the above figure. You can use either a 9V or 12V battery.
      • Put ultrasonic sensor at the top of the water tank.
      • Connect water pump using a relay board (optional during testing).

      Step 6: Magic Time!

      • Install the app (created in step 2) on your Android device.
      • Supply power to the setup.
      • Wait for NodeMCU to connect to the hotspot (you can use either router or portable hotspot).
      • All Done! Now you can control/monitor water level from anywhere in the world.

      IoT Challenge

      Participated in the
      IoT Challenge

      Be the First to Share

        Recommendations

        • Soup & Stew Speed Challenge

          Soup & Stew Speed Challenge
        • First Time Author Contest

          First Time Author Contest
        • 3D Printed Student Design Challenge

          3D Printed Student Design Challenge

        30 Comments

        0
        citimobile
        citimobile

        2 months ago on Step 4

        i want code compleet citimobilecare@gmail.

        0
        roockstardeva
        roockstardeva

        Question 8 months ago

        Bro, I have to connect it to two more devices. What to do?.

        0
        muhammadamin831996
        muhammadamin831996

        Question 9 months ago

        Hai how did you make the calculation, I did not understand the process of calculation

        0
        Rishi Rishi
        Rishi Rishi

        Answer 9 months ago

        Hi,

        There are different levels defined like min, max and mid. Then actions are triggered automatically as per water level.

        Further manual mode is there to override automatic mode.

        Hope this make sense now.

        0
        sandek80
        sandek80

        Question 10 months ago on Step 5

        ciao, ottimo progetto, ho un lt7206, va bene al posto di lm7805

        0
        muhammadamin831996
        muhammadamin831996

        Question 1 year ago

        May i know can we see the history of data in real time database ?

        0
        Rishi Rishi
        Rishi Rishi

        Answer 1 year ago

        Hi

        I guess we can't see history of data in firebase real time database.

        0
        muhammadamin831996
        muhammadamin831996

        Reply 1 year ago

        I see thank you for responding. The project work perfectly. Only going to test with pump, sill waiting for the item arrive

        0
        Rishi Rishi
        Rishi Rishi

        Reply 1 year ago

        Glad you liked it :)

        0
        muhammadamin831996
        muhammadamin831996

        Reply 1 year ago

        sir may i get some help, my pump is not working because of connection on board, i had try pump connected to the battery direct and the pump was okey

        0
        muhammadamin831996
        muhammadamin831996

        Reply 1 year ago

        the relay work fine as it had on and off but the pump not working. is it i had make an mistake on breadboard

        0
        muhammadamin831996
        muhammadamin831996

        Reply 1 year ago

        the red wire at 60 line 2 was for vin from nodemcu 8266 amica.
        orange wire at 60 line 3 was for trig on hc-sr04
        red wire at 60 line 4 was vcc from relay
        the green wire at 61 line 2 was for GND from nodemcu 8266 amica
        green wire at 61 line 3 was for GND from hc-sr04
        the brown wire at 61 line 5 was for GND from relay

        the coding i did not make any changes

        WhatsApp Image 2020-09-12 at 4.25.00 PM.jpeg
        0
        muhammadamin831996
        muhammadamin831996

        Reply 11 months ago

        the problem all solved but i need to store data in mysql can you help me how, I had try follow your video which no ultrasonic sensor and no water pump.

        0
        hoornhecht
        hoornhecht

        Question 1 year ago on Introduction

        hello sir,
        i love this project and i will aply it to my house.
        just jesterday i put all the compnets togeher and follow your guideline.
        but there is a chaange in the real time database conection.
        please can you help me?
        the esp can not log in the google fire base.
        for faster contact we can comunicate as well via watzapp +5219841642155
        sorry i'm totally new with aduino and maybe i need a bit special help :-)

        0
        Rishi Rishi
        Rishi Rishi

        Answer 1 year ago

        Hi there,

        Glad you liked my project :)

        I'm not sure why esp not logging data to firebase. Are you getting firebase connection failed error in serial monitor?

        If yes, try this : https://m.youtube.com/watch?v=ZZ5JvSA-Ed8

        For more help, please send me personal message here on instructables. I would be happy to help you.

        Thanks

        0
        hoornhecht
        hoornhecht

        Reply 1 year ago

        Hello,
        I found the problem! Now it works fine thanks

        0
        Rishi Rishi
        Rishi Rishi

        Reply 1 year ago

        That's great!!!