Skip to content

Smart Irrigation System is a simple embedded software and IoT project that permit to automatically water you plant, offering at the same time a Telegram interface to interact with it.

Notifications You must be signed in to change notification settings

dongi01/SmartIrrigation_IoTUniTN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Irrigation System IoT UniTN

Table of Contents
  1. About The Project
  2. Project Layout
  3. Basic
  4. IoT Integration
  5. Authors
  6. Links

About the project

Welcome to the Smart Irrigation System!

This system is designed to help you water your plants efficiently and effectively. It uses a combination of sensors, microcontrollers, and a water pump to automatically water your plants, or even control it remotely.

The system includes the following components:

  • MSP432: This device reads the data from the sensors, determines whether the plants need to be watered and is connected to internet by an ESP32.
  • ESP32: This microcontroller is uesd to connect the system to internet in order to use a Telegram bot that lets overview the framework.
  • Soil moisture sensor: This sensor measures the moisture level in the soil and sends data to the msp microcontroller.
  • Temperature and light sensor: This sensor measures the temperature and light of the surrounding environment and sends data to the msp microcontroller.
  • Water pump: This pump is connected to a water source and is used to water the plants when necessary.

The system works by continuously monitoring the soil moisture level and environmental conditions. If the moisture level is too low and the temperature and humidity are within acceptable ranges, the microcontroller will activate the water pump to water the plants.

Otherwise the user can control the system remotely with our Telegram bot. It is integrated with the microcontroller and can receive data from the sensors. It can also send commands to the microcontroller to control the water pump. The user can access the Telegram bot from their smartphone or computer.

Overall, the Telegram bot is a useful feature that adds flexibility and convenience to the Smart Automatic Irrigation System.

Project Layout

SmartIrrigation_IoTUniTN
├── ccsProject
│   ├── mainProjectFolder           # main code for MSP
│   └── sensorsLibraries            # MSP sensors libraries 
├── ESP32code
│   ├── ESP32code.ino               # ESP32 main code
│   ├── httpClient                  # personal libraries
│   ├── httpServer                  # |
|   └── readUARTdata                # └
├── node_server
│   ├── app.js                      # main nodejs app
│   ├── sensorsDataAPI.js           # functions to manage data in DB
│   ├── servers.js                  # declaring nodejs http server and telegram bot
│   ├── startServer.js              # start telegram bot, http server and connect to database
│   ├── supportFunction.js          # personal function
│   └── usersAPI.js                 # functions to manage users data in DB
├── readmeImages
│   └── images                      # images for readme
├── ProjectPresentation.pptx
└── README.md

Basic

The basic idea of the project is based on a offline irrigation system, which can be controlled directly by the MSP432. Using the LCD screen, it has different features to be execute by choosing with its own integrated controller and buttons.

Basic Requirements

Basic Hardware

You will need an MSP432p401r of the Texas Instrument company with its own expansion: the BOOSTXL-EDUMKII. Moreover you will have to use a capacitive soil moisture sensor for the moisture detection, a 5v relay, a 5v pump and some jumper wires.

Basic Software

In order to flash the program into the Texas Instrument components, you first need to install Code Composer Studio.

The next step is to create a new CCS project, choosing the right target system (MSP432P401R), and paste all the files in ccsProject/mainProjectFolder and ccsProject/sensorsLibraries folders. You need also to exlude all the .c files, exept for the main.c and the one from the sensorsLibraries, from the build with a right click on them.

Finally to run the project you will need to add to the linker option and to the compiler option the driverlib library downloading it at this link.

Linker option

Compiler option

Basic Project wiring

Basic Get started

If all the software requirements are satisfied, you need to connect all the sensors and the microcontroller as you can see in the electric schema above. Now, you are able to flash the program on the MSP, using the command flash on CCS, and start using the whole offline system.

As you can see in the image above, once the program start running you will see the app logo appearing for a few seconds and you will soon be able use the app menu to try the different functionalities.

In particular, in the second image it is shown a sample of the sensors data page that is constantly refreshing with the brand new data collected by the sensors.

NOTE: If you start manually the pump from the menu, the pump will run until you stop it from menu or Telegram bot(read below for IoT extension)

IoT integration

This extension allows you to connect the basic system to the internet. In this way you can visualize all your data from your Telegram account with different mode, like in real time or on demand. You will also be able to start and stop manually the water pump.

This bot can respond to different Telegram accounts and the people that start it will be included in a group. The group created will always be update with a message when the pump changes its state, for whatever reason (by manual command, by telegram command or automatically).

IoT Requirements

IoT Hardware

You will only need an ESP32 (ESP-WROOM-32) and some other jumpers wire.

IoT Software

  1. NodeJS
  2. npm
  3. Arduino IDE (version 1.8.19 is recommended)
  4. Telegram app and at least one account
  5. Telegram bot
  6. MongoDB, MongoDBCompass

NodeJS, npm

How can I install all of this? Just follow next instructions. To install NodeJS and npm you can easily follow the instruction on this guide.

Now that NodeJS and npm are installed, opne the node_server folder in your terminal and type this command

npm install

This command will install for you all the NodeJS packages needed.

Arduino IDE

Simply download the version for you on their official web site and follow the installation procedure.

Once you have installed it you have to download some libraries to be able to operate on the ESP32 and manage http communication between NodeJS server and ESP32.

First of all open Arduino IDE and go to Tools > Board > Boards Manager, search for ESP32 by Espressif Systems and press install.

Then we want to install the libraries required for the http comunication.

Go to Tools > Manage Libraries and search for:

  1. HttpClient by Adrian McEwen
  2. WebServer_ESP32_SC_ENC by Khoi Hoang
  3. WiFiManager by tablatronix

Nice, now your Arduino enviroment is ready.

Telegram app, account

You can download Telegram app directly from your store and create a new account if you haven't already.

Telegram bot

For this extension you have to create your own bot for obvious reason but don't worry, it will be easy!

To create your own bot open BotFather and press start button below.

Then you will see some of the operations that the BotFather can do for you so digit or press

/newbot

Now you only have to follow its instruction. Remember to save safely the token that it will give you, you will need it later! The last thing you should do in the BotFather is to set commands. Simply digit

/setcommands

and then copy and paste this list of commands

commands - for all commands
get_last_moisture - for the last soil moisture value recived
get_last_brightness - for the last enviromental brightness value recived
get_last_temperature - for the last temperature value recived
get_last_data - for last data recived
get_last_n_data - for the last n data (if possible). NOTE: write your number after command
get_realtime_data - to enter in realtime mode and see real time data
stop_realtime - to exit realtime mode
start_pump - to manually star the pump
stop_pump - to manually stop the pump

Now the configuration of the bot is done too!

MongoDB, MongoDBCompass

Now you have two solution:

  1. running the database on your local machine
  2. running the database on the cloud

You can create your local cluster with MongoDB and MongoDBCompass following this guide (how to create the database and how to connect it, don't look at how to connect from server NodeJS). This method is good if you have a home server but it is not the best if you haven't because your machine should run 24/7.

Otherwhise you can create your MongoDB account and create your cluster online. Follow this guide for that.

Once you have your cluster you have to create one database, witch will be composed of two collections:

  1. Users
  2. Sensors_data

It is very important to name these collection exactly in this way.

At the end you should have something like this in your Database.

Now the configuration of the software is done, later we will have to modify some code!

IoT Project wiring

IoT Get started

Now we have to modify some code to make it work for you.

Set NodeJS server IP adress in ESP32 code

We need to tell the ESP32 which address to send the data to so, in the ESP32code folder open httpClient.cpp in a text editor and change the 6th line. Insert the local IP address of the pc where the server will be running.

// node server address
String serverNode = "http:https://<yourServerIP>:3000";

Now ESP32 code is ready!

Create .env file

Now you have to create a file named .env in the node_server folder.
Once you have created it, open it and in the first 2 line write:

TELEGRAM_TOKEN = '<yourTelegramBotToken>'
DB_URL = '<yourMongoDBconnectioinLink>/<yourDatabaseName>'

In the first you need to copy and paste the token given to you by the BotFather and in the second you have to copy and paste the connection link of your database, followed by the name of your cluster.
If your database is locally hosted the string will look something like

mongodb:https://localhost:27017

otherwise it will look something like

mongodb+srv:https://<username>:<password>@<clusterName>.[randomCharacter].mongodb.net

Load program image on ESP32

It is time to load the ESP32 code on the board.

In the ESP32code folder open ESP32code.ino with Arduino IDE, connect the ESP32 to the computer with a USB cable and then press the little arrow icon on the top left of the screen to load the code in the board. It will take some time.

NOTE: when a sequence of dots appears in the bottom of the Arduino IDE, make sure to press the boot button on the ESP32 until the dots stop.

You should end with something like that

Start the all project

First of all power the ESP32 via USB or input pin.

In this first phase we want to tell to ESP32 what network it should connect to.
The board will act like an access point, so go to your wifi settings (via pc or smartphone) and connect to AutoConnectAP: a web page like below should open automatically, if not open your browser and search for WiFiManager in the top bar

After connecting to local WiFi with ESP32, you can power the MSP432 as well and replicate the project wiring.

Lastly we have to start our NodeJS server. Just open the node_server folder in a terminal and digit

node app.js

In this terminal you will see lots of log information that can be usefull, in some cases.

At this point the project should be perfectly running!

Telegram bot interface

If you want to be able to use your Telegram bot just open your app and search for the bot that you have created, start it and enjoy! You can ask for the last soil moisture, enviromental brightness and temperature registered in the database, you can see data in real time activating realtimie mode (it will send you data every 10 seconds), you can ask for the last N data saved on the database and finally you can manually start and stop the pump!

NOTE: If you start manually the pump from the bot, the pump will run until you stop it from MSP432 menu or Telegram bot

Here an example of the telegram interface.

Authors

Links

About

Smart Irrigation System is a simple embedded software and IoT project that permit to automatically water you plant, offering at the same time a Telegram interface to interact with it.

Topics

Resources

Stars

Watchers

Forks