Wheels4Water : Let's paddle away through water mgmt issues

Are we neglecting the importance of water? Probably, the answer is YES. Go through this different and versatile project to find a solution.


Things used in this project


Hardware components

1 DFRobot I2C 16x2 Arduino LCD Display Module
1 NodeMCU ESP8266 Breakout Board
1 5V Relay
1 DC Motor, 12 V
2 Digilent IR Range Sensor
1 Arduino UNO
1 9V battery (generic)
1 Buzzer, Piezo
1 12V DC adapter
1 Bolt IoT Bolt WiFi Module
2 Ultrasonic Sensor - HC-SR04 (Generic)
1 Water Flow Sensor : YFS401
1 TCS3200 Color Sensor
1 12V DC Solenoid Valve
1 1N4007 – High Voltage, High Current Rated Diode
1 Capacitive Touch Sensor
1 ESP8266 Motor Driver Shield
1 Analog Multiplexer IC CD4051
1 Water Lifting Submersible Pump
1 3-6 V Mini Submersible Water Pump
1 4 way Capacitive Touch Switch Module
2 Breadboard (generic) One is small and the other one was medium in size
1 Robot Chasis
1 Jumper wires (generic)

Software apps and online services


Arduino IDE


Bootstrap Studio




Twilio SMS Messaging API




Mega Creator







Project's Idea


Before diving into the Hardware & Software setup, it is important to first understand what the project is intended to do? Way before starting my IoT & Robotics journey I always wanted to solve the problem of overflowing water tanks.


So, after understanding what do Internet of Things & Machine Learning means I thought of making a project which will eliminate this traditional problem to the full extent. But I was startled to see that there were already thousands of projects covering this area. Almost every sensor out there has been used in these projects.


I think all of the projects which were made earlier have the following drawbacks:


-In the real world scenario the water supply chain, from the water source (eg dam, water facility) to water tanks in our home, is a very long one and we have to admit that the problem of water wastage starts from the initial end of the cycle and penetrates through the very last end of that cycle. All of the previous projects only focus on the very last end of the cycle ie the project only deals with the water tanks of our homes.


-The projects were almost passive. By passive I mean that they will monitor the water level and will turn the water motor off when the water reaches a certain level. This whole computation would be done within the microprocessor and the end-user can’t get to know what is happening inside the code at the moment!


-Less interactive projects. If one can provide some motion or life to the immobile projects then it will greatly enhance the chances of implementing the project in real life.


-Very few of the projects use the concept of Machine Learning. Those who use the ML concepts are just using the pre-built easy structured graphs and anomaly detection things which don’t make much more sense!!


So, I wanted to make a project which must be very different from the existing projects. Then I came up with the project Wheels 4 Water, a perfect amalgamation of IoT, Machine Learning & Cloud. Let me point the main highlights of my project, which make my project stand out from others.


-Apart from the basic sensors, I have used many different sensors. Be it a water flow sensor, solenoid valve, or an analog multiplexer IC (CD4051), all these sensors helped me to almost nullify the water wastage through the whole water supply chain. In this manner, I focused on the whole water supply chain.


-At every instance of the project execution, the end-user will be updated and informed about each major workflow. The project will talk with the user. Thus making the project active.


To make this project more interactive, I dumped the old idea of integrating IFTTT or using the CLI. Even I have not used either the blynk application or the normal switches in my project. Instead of all this, I have provided four custom options to control the project which include a dedicated website, NodeMCU based robot, customized cloud dashboard & voice control (I have not used any drag and drop feature of Blynk or IFTTT applications)


-Rather than using simple and pre-built ML systems I used the Iterative Dichotomiser 3algorithm and implemented it via Python so that the robot can make decisions on its own after analyzing the dataset.


Functioning of Project


-One can break down my project into two major parts. One is the immobile Boltduino/Arduino and the mobile NodeMCU based robot. I will discuss the functioning of each of both sections.



As you can see from the picture that there are 03 water tanks. You can assume the first one to be the main water facility, the second one to be the nearest water tower, and the third one to be the water tanks in homes. The main water facility will get the water from the dam and the water lifting submersible pump will be turned ON and now, the solenoid valve will be turned LOW. Whenever the water level in the nearest water tower will be less than 20% then the solenoid valve will turn ON and thus the water tower will get filled to a certain threshold (say 95%). When the water tower will be filled then the DC water motor will start pumping out the water from the tower to the water tanks in our home.


At the time of pumping the water flow rate will be calculated through the YS-401 water sensor. Then the total time to fill the water tank will be calculated and accordingly, the instructions will be sent to the robot so that it can reach the destination in time to inform the user.


One major aspect of the Arduino setup is that I have to make the Arduino and the python program communicate with each other. I have to do this as Bolt Wifi Module can understand Python language, not Arduino’s language. So I have to make the Arduino pass some certain keywords to the Python program and then the Python program will act accordingly. For this, I used serial communication through the COM port. This was a tricky part as the Arduino has to pass about 6 parameters to the python program and then the python program has to proceed accordingly.


To make the passed variable understandable to the python code, I used the decode and strip methods. In this case, the decode() method converts the string from UTF-8 encoding to binary encoding. Another problem after using this decoding method was that say for example the passed variable was “stop” then the decode method will append some escape sequences to the variable and now the variable will look like “stop/n/r”. To remove the extra escape sequences and also not affect the binary encoding, I used the strip method as it removes any spaces or specified characters at the start and end of a string. This solved the problem of inter-communication between Arduino and python code.


The python code also comes into the picture here. The python code does the following things:


1. Use the ID3 algorithm to predict where the person should be in? For this evaluation, I have made the following custom dataset:


In the dataset, the robot has to predict the place attribute while the other 04 parameters will be computed automatically through the python code. The snippet showing the decision tree made by the python code using the ID3 algorithm is as follows:


After evaluating the place, the same is uploaded to a google sheet so that the user can have a log of the periods and all other details about the water tank. The Integromat scenario for uploading all the attributes’ values to the google sheet is as follows:


A couple of more scenarios are there ie for fetching the data and also uploading the predicted values to the google sheet.


2. To make the project more active, I have used Twilio’s API to send Whatsapp updates for every major workflow.


A total of 04 Whatsapp updates will be posted on the user’s registered number. But what if there is no Internet connectivity with the user? Then, in this case, 04 normal text SMS will be also sent which makes the project more relatable to the real world. Following is one of the snippets of the updates:


Before moving further I would like to present the sketch of the hardware connections for the static Arduino section. Here it is:


I just want to tell you that the I2C LCD will be updated several times during the project. Be it updating and printing the predicted value or displaying the total time to fill, one can easily keep a track of important parameters through the LCD.


There could be many possibilities in which the user may not be able to turn the motor off. In those scenarios, the Arduino will use the TTF (Time To Fill) to turn off the motor, when the TTF is about to be reached. So, in this way, the project becomes quite interactive and the user also gets timely updates regarding the whole project.


As earlier I told you that the python program and Arduino code will communicate via serial communication. According to the project, the Arduino code will have to convey 6 variables to the python code so that the Bolt Wifi module can work accordingly. Those 6 variables are as follows:


a.start: Turning the water motor on when the nearest water tower is full


b.TimeToFill: By theYS-401 water sensor, calculate the time needed to fill the water tank. Has to be reflected on the LCD screen


c.robot/noRobot: If the robot will take more time to reach the place than the ttf, the robot should not be deployed which is conveyed by the noRobot variable. If this is not the case then the robot variable is transferred


d.stop/stopped: After reaching the place, did the user pressed the touch sensor or used any of the 4 mediums to turn the motor off. If he did that then the variable will be set to stop and if the user for any reason did not turn it off the variable stop will be sent so that the autonomous execution can proceed


e.true/false: If the robot has gone for the destination and still not reached the final place due to some obstruction then the prediction variable will be set to false & if it reaches the final place then it will be set to true


f.comm/comm1/comm2/comm3: Passing the variable through which the program will get to know that the user has chosen which option out of the 4 to turn the motor off. So, that at the end of execution there is clarity for the program

From the above video, now you must have understood why the 06 variables play a much important role with the static Arduino and computer. As the video was just for the demonstration purpose the variables were transferred in few seconds but in the actual project’s working this will not happen.


-NodeMCU based robot


The first work for the robot is to fetch the place attribute so that it can find the place where it has to go. Once the robot fetches that value then the TCS3200 color sensor comes into the picture. Basically in the dataset, there are 03 values for place attributes which are balcony, bedroom, and hall. From the starting point of the robot to the final destination I had laid down 03 different colored lines so that the color sensor will follow a particular colored line after getting the predicted value. The place has the following colors:


-Red – Bedroom


-Blue – Balcony


-Green – Hall


So, the robot will find the path through the custom-made direction functions. When the robot will reach to the end then it will wait for 20 seconds and then it will check whether the user clicked on the capacitive touch sensor. If yes, then the NodeMCU will send an API request to the Bolt WiFi cloud and in this manner, the water motor will be switched off in time.


The sketch for the hardware connections for the mobile robot is as follows:


In the hardware configurations, there were two most challenging and tough parts. These were using the ESP8266 motor driver shield & using the multiplexer IC with the motor driver shield.


Using the ESP8266 motor shield was difficult because in the shield’s official datasheet nothing is clearly explained. But after several repeated attempts I sorted the overall functioning of the shield. NodeMCU is placed on the top of the shield so that both become one in the other.A total of 2 DC motors can be connected so that is why I used a 02 wheeled robot which was controlled through the DC motors while the Caster wheel provides the stability to the overall chassis. As I used 02 12V DC motors I have to either use a 12V DC cell combination or can use a 12V DC power adapter to power up the motors. The major drawback of using the 12V cell combination was that the cells get discharged very quickly so this option doesn’t seem viable at that moment. That’s why I turned up for the 12V DC adapter solution as it seamlessly provides enough power to the motor shield and motors. Do note that I have short-circuited the Vin and Vm pins of the motor shield so that the power coming from the motors can also be utilized for powering up NodeMCU.


Using the multiplexer IC with the motor driver shield was also quite a bit of a challenge as the CD4051 multiplexer IC is a 03 select line-based (S0, S1, and S2) multiplexer. This means that we can insert 23 = 8 analog sensors with this IC and use the single port ie A0 of the NodeMCU to read all 8 values. But in my case, I used only 2 IR sensors which means I don’t know what I have to do with the third select pins? In many attempts, the third select line was giving random values which were not even needed. After some trials, I got to know that the third select line must be provided a voltage of 0 so that the pin should not float.



Software Programming


I have almost discussed the difficult tasks of the code up in the above sections. But I want to make it clear that the overall code of this project spans over 2000 lines (excluding the whitespaces). As of now, I am submitting this project in various competitions so I will not be uploading the full code for this one. After my project's evaluation is done then I will surely upload the Github files too. ⏳


Just for your convenience, I am laying out a table that tells the working of each file:


1.robot.ino: Catch the users’ input & reach the predicted place


2. Arduino.ino: Serial communication with python & data collection


The above-listed Arduino files are for Arduino and NodeMCU respectively. The below-listed files are python files that do the manipulation with the dataset and then upload/fetch the same via Integromat.


1.attribute.py: Gathers values for the data points to be pushed in theID3 algorithm


2.credentials.py: Stores API keys, SSIDs, authentication variables


3.integromat.py: Retrieval of information from Integromat’s scenarios


4.prediction.py: Collect the attributes and uses the ML algorithm to predict the place


5.project.py: Main file which ensures smooth functioning of the project


The best understanding of the code will be through the working video of the project. So, do look at the working video of the project at the end of this documentation.


I have explained the hardware connections, defined most of the working of the code, and also shared the code in this documentation. Only the conclusion must be remaining. No, guys as in the introductory part of this documentation I told you that I have made a dedicated website to control the water motor. I know if you had gone through every paragraph of this documentation till now then your expectations must be very high and I am pretty confident that after going through the dedicated website section you will be impressed 😁



Website Programming


Url for the website:https://wheels4water.me

For the front-end part of this website, I have used CSS, Bootstrap. Just to speed up the process I used Bootstrap Studio so that I can make the static website in a quick time. But the static website was not fulfilling the main purpose of this project. How can a user use a static website to interact with the cloud?


So, to turn this into a fully functional dynamic website I added a lot of transitions, JavaScript and also added the back-end (database functionality). After doing so the user can easily interact and thus login into his account whenever needed. For integrating the website into the database I used PHP language so that I can execute the required SQL commands whenever needed (or according to the users’ input).


The SQL database is named wheels4water and inside it, there are 2 tables which are users & vacation_logs. Users table stores the information related to the user whereas the vacation_logs store the information related to the scheduling of a particular account.


The structures for users table is as follows:


The structure for vacation_logs is as follows:


And as I already discussed in the video that the customized email templates, which are sent to every user at the time of signing up or adding a new device, add a visual treat for everyone. The website apart from being visually appealing and responsive allows the user to keep an eye on the project anytime and anywhere. The scheduling section adds more dynamic behavior to the site and the icon glow section perfectly sums up the hard work I put into this project.


All of you must be thinking that at the starting I wrote that there are 4 ways of controlling the water motor but till now I only described NodeMCU based robot, voice command option, and website option. Where is the fourth one ie Cloud Dashboard?



Cloud Dashboard


I have used Bolt’s WiFi Module to turn on and off the water motor through the relay. The main reason for choosing this module to turn on and off the water motor was because through Bolt’s Cloud Dashboard I can easily plot a graph that must be showing the time for which the water motor was turned on/off.


You can find the basic steps to create a product in Bolt Cloud by clicking here. As far as my product is concerned I have to make a dashboard such that through which user can control the motor. For that, I have to place a button on the pre-formatted UI and I assure you that it’s hard to tweak a UI whose HTML structure you don’t know. But there came JS to my rescue. I dynamically add some code in the product code section to make a button live and thus users can interact with this one to turn off the water motor.


The code for the customized product is as follows:

setChartTitle('W4W Motor Stats');

let anchor = document.createElement("a");
anchor.innerHTML = "Off Motor";
anchor.href = "https://cloud.boltiot.com/remote/API_KEY/digitalWrite?pin=0&state=LOW&deviceName=BOLTXXXXXX";
anchor.target = "_blank";
anchor.style = "display: block; width: 100px; text-align: center; margin-top: 20px; margin-left: 450px;border-radius: 10px; border: 2px solid #0000FF";

Okay, now I am equipped with a button on the dashboard which can be used by the users. I have also written the necessary lines of code to use the google chart but wait how am I going to plot/extract the time for which the motor was on/off? For turning on and off the motor I have used the digitalWrite function on pin ‘0’. But we can plot the graph for only analog values gathered through the A0 port of the Wifi module.


To understand the solution for this problem let’s start from the initial step ie creating the product on the cloud. For my product, I opted input device & GPIO commands during the product creation phase. Secondly, in the Hardware section of the product, I assigned pin A0 the name motor. As I have used a relay to connect the bolt wifi module and Arduino so I connected the Vin pin of the relay to the breadboard and from that breadboard’s pin I also connected the A0 pin of the wifi module. So, in this manner, the AO pin’s value increases from 0 and thus in the dashboard, a graph was formed which will drop down to 0 if the motor is off and whenever the motor is on then the graph climbs up.


Now as I have explained everything to you I am sharing the screenshot of the same so that you can have a brief idea about what I was telling.


Project At Work


Till now I have explained every concept of this project. In the documentation, it all looks great but does it even work? Let’s check it out 👇

I think this video must have cleared all of your doubts as it perfectly tells us how the NodeMCU based robot, Arduino, and computer are communicating with each other to bring out a project which is unique and solves the issue of water management to the fullest.





From the starting, when I thought I would make such a project, to finishing off this project I have added each and everything so that this can be the best project out there. At the start, I was just having the idea of what I have to build but don’t know how? It just started with how to calibrate the 22 different sensors and components which I was using for this project.


It was hard to get a perfect hold over each of these but with time I did that beautifully. Be it the hardware coding, software/website designing or even creating the beautiful videos and images for this project I have enjoyed each step of this. Apart from website designing I didn’t have any prior knowledge of other things but I learned along the way and I am confident that this project rightly reflects that hard work.

If you like this project, then do click on the like button 😃

The article was first published in hackster, October 18 2021

cr: https://www.hackster.io/vishalvats2000/wheels4water-let-s-paddle-away-through-water-mgmt-issues-6c0fb4


All Rights