IOT Based Water Level Controller Using NodeMCU ESP8266
by Rishi Rishi in Circuits > Microcontrollers
33575 Views, 24 Favorites, 0 Comments
IOT Based Water Level Controller Using NodeMCU ESP8266
![Water Level Controller Using NodeMCU ESP8266](/proxy/?url=https://content.instructables.com/F9J/E6MH/JUWXVOWP/F9JE6MHJUWXVOWP.jpg&filename=Water Level Controller Using NodeMCU ESP8266)
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:-
- NodeMCU ESP8266 development board
- HCSR04 ultrasonic sensor
- Breadboard
- Single channel relay board (to control water pump)
- LM7805 +5V voltage regulator IC.
- Battery (9V-12V).
- WiFi Router (to connect NodeMCU to internet)
- Firebase (to create a database)
- MIT app inventor 2 (to create Android application)
So let's get started.
Setup Firebase and Get Secret Key
![welcome firebase.PNG](/proxy/?url=https://content.instructables.com/FEN/MERV/JTEN1BEP/FENMERVJTEN1BEP.png&filename=welcome firebase.PNG)
![realtime databse settings.PNG](/proxy/?url=https://content.instructables.com/FUS/RH25/JTEN1BEO/FUSRH25JTEN1BEO.png&filename=realtime databse settings.PNG)
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.
Create App Using MIT App Inventor 2
![tricksumo.com 1.PNG](/proxy/?url=https://content.instructables.com/FA7/U86Y/JUWXVPPH/FA7U86YJUWXVPPH.png&filename=tricksumo.com 1.PNG)
![tricksumo.com 7.PNG](/proxy/?url=https://content.instructables.com/F07/P3HN/JV0T8WJA/F07P3HNJV0T8WJA.png&filename=tricksumo.com 7.PNG)
![tricksumo.com 2.PNG](/proxy/?url=https://content.instructables.com/FZ9/66OE/JUWXVPZ5/FZ966OEJUWXVPZ5.png&filename=tricksumo.com 2.PNG)
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.
Downloads
Configure Arduino IDE for Nodemcu Esp8266
![library.PNG](/proxy/?url=https://content.instructables.com/FO2/K2L5/JTEN35CU/FO2K2L5JTEN35CU.png&filename=library.PNG)
- 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
Upload Code With Some Necessary Changes
![tricksumo.com 3.PNG](/proxy/?url=https://content.instructables.com/FQU/JNS4/JUWXVQJU/FQUJNS4JUWXVQJU.png&filename=tricksumo.com 3.PNG)
![tricksumo.com 4.PNG](/proxy/?url=https://content.instructables.com/FLP/9DIL/JUWXVQKJ/FLP9DILJUWXVQKJ.png&filename=tricksumo.com 4.PNG)
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.
Downloads
Configure Hardware
![NodeMCU2.jpg](/proxy/?url=https://content.instructables.com/FZV/XRR2/JUWXVQV3/FZVXRR2JUWXVQV3.jpg&filename=NodeMCU2.jpg)
![NodeMCU1.jpg](/proxy/?url=https://content.instructables.com/F27/P3HM/JUWXVQV1/F27P3HMJUWXVQV1.jpg&filename=NodeMCU1.jpg)
![How to Interface HC-SR04 Ultrasonic Sensor With NodeMCU ESP8266](/proxy/?url=https://content.instructables.com/F63/9SJR/JV2R8X2C/F639SJRJV2R8X2C.jpg&filename=How to Interface HC-SR04 Ultrasonic Sensor With NodeMCU ESP8266)
- 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).
Magic Time!
![tricksumo blog.png](/proxy/?url=https://content.instructables.com/FCA/X72D/JUWXVR9P/FCAX72DJUWXVR9P.png&filename=tricksumo blog.png)
![k.png](/proxy/?url=https://content.instructables.com/FZI/NXEU/JV0S3OK2/FZINXEUJV0S3OK2.png&filename=k.png)
![m.png](/proxy/?url=https://content.instructables.com/FAH/JGHK/JV0S3O2D/FAHJGHKJV0S3O2D.png&filename=m.png)
- 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.