Hello everyone! We are Chiara and Stefano. We teamed up for developing a very intuitive and useful project for the Cyber Physical System Architectures course. It consists in the use of a Telegram Bot for controlling a Lifely Agrumino sensor, which sensor can be used for watering the plant where it is placed (using a water pump attached to the sensor itself) or for delivering to the user informations regarding illuminance, temperature and moisture soil of the place surrounding the plant. With this project, users are able, through Telegram, to immediately activate the water plant, specify a certain time at which the sensor have to activate the water pump and receive informations regarding temperature, illuminance and soil moisture in the place surrounding the plant.
The feature of programming the watering of the plants is very useful, since in summer this process must be done at early morning or night (in order to avoid water vaporization and so water wasting) and in winter it must be done at afternoon (in order to avoid water freezing and so ice upon plants). Considering these constraints regarding seasons, the feature of programming watering is effective since the time of watering is chosen by the user.
Of course, the sensor can work with the Telegram bot only via Internet. The sensor can access to the Internet only through its WiFi module, so the sensor itself must be connected to a WiFi network in order to connect itself to the Internet.
Step 1 - Setup your Telegram bot and your Arduino Code!In order to make use of this system, a Telegram bot must be setup. In short lines, the process for creating a Telegram bot is the following:
- Install Telegram on your PC/cellphone and follow the procedure to become a Telegram User (it is very simple and it doesn't have particular requirements).
- Find the user "BotFather" on Telegram; this user is actually a bot and it is the only bot authorised by Telegram to create new Telegram bots. To recognise it on Telegram, in the following image it is shown the BotFather Telegram icon:
- Once the BotFather has been found, start a conversation to it by writing and sending the following message:
/start
- Then, write and send the following message (it will say to the BotFather that it must be created a new Telegram bot):
/newbot
- At this point, the BotFather requires a name for the new bot; write and send to the BotFather the name that you want on the bot;
- Suddenly, the BotFather requires a username for the new bot; write and send to the BotFather the username that you want on the bot. Notice that this part can be a bit long since the BotFather rejects usernames that are already been taken by other users/bot users.
- Finally, once the username has been accepted by the BotFather, your Telegram bot is ready to go! Notice that, in the message sent by BotFather to confirm the creation of the bot, there is string with alphanumerical symbols (called
token
) which is used to access to your new bot. Be careful to not let it be seen by other users!. The token will be used in the setup of the Agrumino sensor in order to let it receive orders from Telegram.
For more information regarding Telegram bot creation, please visit: https://core.telegram.org/bots#:~:text=for%20existing%20ones.-, Creating%20a%20new%20bot, mentions%20and%20t.me%20links.
Congratulations, you have a working Telegram bot! Now, you must have an Arduino code that will be able to use your Telegram bot and that will make the sensor able to connect to the Internet. To achieve this, you can download the Arduino code available in this project and insert few informations inside the code in order to let it work with your Telegram bot and your WiFi network.
In fact, you have to insert in your code these informations:
- The name and password of your WiFi network. For inserting them, you have to go in the code and search the declaration of the variables "
String ssid
" and "String password
". Here, you must replace the terms "MySSID
" and "MyPassword
" with, respectively, the name and the password of your WiFi network. Notice that both name and password contents must be between double quotes (like"abcdef123"
)! - The token for controlling your Telegram bot. For inserting it, you have to go in the code and search the declaration of the variable "
String token
". Here, you must replace the term "MyToken
" with the token that you have received when you were creating the Telegram bot. Notice that the token symbols must be between double quotes (like"12345...:abcdef..."
)!
Your code now is ready, but there is one important thing missing: the water pump! For let the sensor controlling the water pump, of course you must connect the water pump to the sensor. You can connect any water pump you want, as long the water pump has an input voltage of 3 V. The pins of the sensor where connect the water pump are shown in the following picture:
Finally, you have to upload your modified code to your Agrumino sensor. In order to do so, you can use the Arduino Integrated Development Environment (IDE).
Once this last task has been done, that's it: you now have completed the setup of your system!
Step 2 - Use your Telegram bot!Once the system has been setted up, the only thing you must do is to give commands to your Telegran bot. Commands can be sent just by opening a conversation with your bot, writing the desired command and sending it to the Telegram bot.
The list of supported commands in this code is the following:
Water
: by sending this command, the system will immediately activate the water pump for two seconds
Example
Input to the bot: Water
Response of the bot: Watering completed
Info
: by sending this command, the system return info regarding temperature, illuminance and soil moisture of the environment surrounding the plant.
Example
Input to the bot: Info
Response of the bot:Temperature:
30 °C,Soil Moisture:
80 %,Illuminance:
10 lux
Set time_of_watering
: by sending this command, the system will activate the water pump for two seconds at the time specified by the user inside the command. The time must be inserted inside the command in the format 4-digits, where time hours are separated from time minutes by a ":".
Example
Input to the bot: Set 08:00
Response of the bot: Watering scheduled at: 08:00
... time passes until 08:00 arrives...
Response of the bot: Watering schedule has been respected
Step 3 - Let the system handle the rest!Once you have completed the system setup and have defined, through the Telegram bot, the time at which the system will activate the water pump, you now have an autonomous system capable of watering the plants at the time you prefer and capable of giving you informations about the environment surrounding your plants! Feel free to relax while the system water the plants when you want and informs you about the environment of your plants just by using Telegram!
The project has shown how to implement a very intuitive system that, using Telegram, let users monitoring plants status and setting a time at which do plants watering.
Future improvements can be the insertion of new commands for the bot (for example, a possible new command that can automatically set up an optimal routine according to the local weather forecast, which weather forecast can be obtained from Internet) and the functionality of alerting the user if some critical events have happened (for example, if the water pump is running out of water).
Thank you for your attention!
Comments
Please log in or sign up to comment.