In this article, we will control our home geyser from anywhere in the world. Life is fast and hectic, and we all want to enjoy the benefits of technology in our everyday lives, automating wherever and whenever we can.
In this experiment, we will automate our geyser in integration with our alarm app so that whenever we wake up, we can get instant hot water. We will achieve this using the MQTT IoT protocol. MQTT is a low-weight, low-bandwidth data transmission protocol. For more details, you can refer to our previous articles.
Technical information
Using IoT, it is possible to control any physical object connected to the internet. By wiring your home with sensors and then connecting them to the Internet, you can control them from your cell phone from your laptop.
An IoT-based water geyser offers control from your mobile device and uses the MQTT protocol as its communication protocol. You can control the geyser from an app, which can be installed on your cell phone or laptop.
Basic network of our geyser control system
The geyser is connected to a unit with an ESP module programmed with an MQTT client program to connect to an MQTT broker. The ESP module connects to a Wi-Fi router for Internet connectivity. The broker is hosted in the cloud, so there will be no need to open any ports on the internal router.
The anatomy of the complete project
Note: To understand the basics of MQTT and IoT, refer to previous articles.
The ESP8266 is connected to the broker and receives instructions through the mobile application.
Let's discuss in detail about the main functions:
- To control the geyser there is a mobile app which is basically a daily alarm app, you can set an alarm for any suitable time.
- The application calculates hours and minutes until the alarm rings and sends the minutes to the broker followed by the “on” command, in the “ToESP” topic, the ESP module is subscribed to the topic.
- When the ESP module receives the “on” command it stores the minutes in an integer.
- The converted value is then passed to a function that calculates the time in seconds and other formats and returns the second.
- To measure time in ESP, there is a block of code containing a for loop that updates the value of a count variable every second. This is how time is compared to received time.
- The variable “time _in_switch_on” is now modified based on the time it takes the geyser to heat the water. When you set an alarm for 5am, the geyser will start at 4:50am and the water will be heated in 10 minutes.
- The “time_in_switch_on” variable stores the value in seconds and is compared with a “tick_seconds” variable in a “function_to_trigger_gyeser_on” function.
- After the geyser is turned on, it starts counting up to 15 minutes exactly, and when 15 minutes pass, the geyser turns off and the message is sent to the App.
There is also a feature where you can turn off or turn on the geyser at any time on the mobile app. So this is how the geyser can be controlled via the internet.
Note: We are using an open source library for publishing and subscribing through the ESP client. We are not changing anything in these public libraries.
Soure Code: