---
# System prepended metadata

title: A Plant Monitoring System using WiFi and the Ubidots platform

---

# A Plant Monitoring System using WiFi and the Ubidots platform

**Felix Mossberg - fm222n**

This project involves sending data on temperature, humidity, light and moisture level to a Ubidots dashboard through WiFi, to help you keep check of external conditions for your plants.


**Estimated time for execution:** ~10 hours
**Estimated cost:** ~800kr

# Objective 

Today, not everyone has access to a balcony big enough to incorporate big plants or gardens, but instead chooses to borrow land elsewhere (like from initiatives such as https://grow-here.com/). For these cases it could be good to have more options to monitor your plants, especially if you do not have time to visit them for some time. Or even if you have the plants on your window or your balcony, you might want to monitor the plants to learn more about the optimal growing conditions.
This project explores a way to monitor the external circumstances of the plants so that you can get more data to help you determine why, or why not the plants grow the way you want them to. It involves sending data on temperature, humidity, light and soil moisture through WiFi, to a Ubidots dashboard. This serves as a good foundation to continue experimenting by yourself later, whether you want to connect this to an automated watering system or just receive a text message when the soil moisture level ends up being too low for example.

I chose this project because I think plant monitoring is a very good application for IoT, and because I myself is interested in growing and learning more. It is also frequently mentioned that self sufficiency in Sweden is at a particularily low level today. Home grown food and knowledge of plants can greatly help to tackle this problem and having data collected from several variables of the process could help users better understand what goes into growing plants.

# Material


| Summary of articles                   | Bought at| Price    |
| ------------------------------------- | -------- | -------- |
| Pycom Expansion Board v3.1            |  https://www.electrokit.com/        |  €16        |
| Pycom Lopy4                           |      https://www.electrokit.com/    | €35         |
| Capacitive Soil Moisture Sensor v1.2  | Amazon: https://tinyurl.com/yb36vjwq  |  ~€6        |
| DHT11 Temperature & Humidity sensor   | Amazon (Elegoo arduino-sensorkit): https://tinyurl.com/y8ksjbph         |  ~€3        |
| Light Resistance sensor (non-digital) | Amazon (Elegoo arduino-sensorkit): https://tinyurl.com/y8ksjbph         |   ~€2       |
|   ~10 cables                    |  https://www.electrokit.com/        |   ~€2       |
|    Breadboard                       | https://www.electrokit.com/         |   ~€3       |
|  Micro USB Cable 2.0                      | https://www.electrokit.com/     |  ~€5    |



* **Pycom Expansion Board v3.1** ![](https://i.imgur.com/T9mWbt0.png)
* **Pycom Lopy4** ![](https://i.imgur.com/n9qrKKH.png)
* **Capacitive Soil Moisture Sensor v1.2** ![](https://i.imgur.com/e8BZDFX.png)
* **DHT11 Temperature & Humidity sensor** ![](https://i.imgur.com/B6Nq7N9.jpg)
* **Light Resistance sensor** ![](https://i.imgur.com/wY3cG6t.jpg)



In this project I have chosen to work with the Pycom LoPy4 device as seen above. It is a device that is programmed with MicroPython and has several bands of connectivity. The device has many digital and analog input and outputs and is well suited for an IoT project. Since the connectivity used ended up being WiFi, a cheaper option could have been chosen as well (such as the Wipy 3.0, https://pycom.io/product/wipy-3-0/, or even another ecosystem altogether). However, the LoPy4 gives you more options to send signals through, for example, the LoRa network, allowing for more range, and is overall a very versatile tool to learn.

For the project, the three sensors mentioned in the table above was chosen. 

**The capacitative soil moisture sensor v.1.2** is an analog sensor that, in contrast to other popular soil moisture sensor options, does not corrode as easily. It measures the capacitance and returns a voltage that is based on how much water is present in the soil. 

**The DHT11 Sensor** is a very affordable digital sensor that measures the temperature and humidity in the surrounding air.

**Light Resistance sensor (or Light Dependent Resistor (LDR))** is an analog sensor that measures internal resistance that is decreasing when light reaches the sensor.

# Computer setup

**Updating Expansion Board Firmware**
When initiating the project, you have to make sure that your Expansion Board and Lopy4 board is updated with the latest firmware. For the details on firmware update and other hardware setup, you can, in full, follow the documentation provided by Pycom (https://docs.pycom.io/gettingstarted/). 

The setup of firmware was conducted on a mac, however, at the time of writing, a firmware update of the Expansion board on mac using brewmaster and DFU-util (as outlined in: https://docs.pycom.io/pytrackpysense/installation/firmware/) was impossible due to a bug. However, the expansion board arrived with the latest update already available, and thus the previous step involving the expansion board was not needed.

**Updating LoPy4 and Commisioning Device with Pybytes**

The installation was made on a macbook computer which meant no drivers needed to be installed. Once again, a guide can be found at: https://docs.pycom.io/gettingstarted/installation/firmwaretool/. First, the Pycom Firmware Updater was installed through the provided link. Running the program lets you first designate port and advanced settings, then you get to choose which firmware to update. The firmware that was chosen in this project was the Pybytes firmware (not legacy). The next step is to type in your Pybytes activation token. To get the code and simultaneously provision your device for Pybytes, visit https://pybytes.pycom.io/ and register a new device along with your WiFi credentials. Eventually you will end up with a device that you can provision by going to "provisioning" and copying the activation token into your pybytes firmware updater.


**Downloading IDE**
The IDE chosen for the project was Atom. A download link can be found at https://atom.io/. After downloading Atom, the Pymakr plugin was installed, which handles the connection to the Pycom device. The Pymakr is right now available for Atom and VScode. The installation for Atom is done by following [this online guide](https://docs.pycom.io/pymakr/installation/atom/).


# Putting everything together

**Connecting your first sensor**
The sensors used in this project was picked due to their availability and versatility, but there are likely plenty of sensors that are comparable or perhaps even better. No matter which sensors you end up going with to measure for example temperature or soil moisture, the first step when trying to get everything to work should be to individually try to get your respective sensors to work. The setup for the electrical circuit shown below work well for that as well if you choose to first only connect, say, the DHT11 sensor to get that to work first.

The first step when connecting a sensor should be to consult the data sheet for the sensor, which will help you to determine the correct pins for input voltage, ground and data. For example, below is a snapshot of the documentation provided for the DHT11 sensor from the Elegoo sensor package:

![](https://i.imgur.com/vVDVM69.png)

Furthermore, when connecting the sensors, and especially the analog sensors (the light sensor & the soil moisture sensor), it is also important to consult the [pin-out schematics](https://docs.pycom.io/gitbook/assets/lopy4-pinout.pdf) for the Pycom device, to make sure that no wrong connections are made.

**Electrical Circuit Setup**

The setup for the electrical circuit is illustrated in the figure below. 

![](https://i.imgur.com/RQZW1Zq.jpg)

This setup is an illustrative picture describing the way I connected all the wires without soldering. The wires can of course be longer in order to place the sensors wherever you want. Initially there was a concern that connecting the sensors in a series would have an effect on the output, but that has not been the case for me after some testing, which made me go forth with this setup. It is worth noting that this is an okay setup for experimenting, however it definitely do not hold up for use in production. For a production scale, you would ideally have soldered cables to the sensors and you would be on the safe side and perhaps not connect all the sensors in a series in case it would in fact affect the results (considering at least that the capacitive sensor and the LDR sensor I used are both analog sensor).




# Platform

When presenting and sending the data, several platforms were considered. First, an intention was to send the data over the LoRa network using the The Things Network and presenting it over Ubidots. However, as relatively new, I found it hard to grasp the decoding and encoding, and overall wanted to simplify everything. So instead I chose to send data to Pybytes as well as Ubidots directly from the sensor over WiFi, in order to compare the two offerings. 

**Pybytes**
Pybytes is a platform recently created by Pycom themselves that is very easy to get started with if you have a Pycom device, and it only requires one to define functions and then send them directly over to the pybytes platforms as signals. These signals can then be defined directly at Pybytes, which makes it very quick and easy.

**Ubidots**
Ubidots is an IoT platform that can be used to send data to the cloud from any internet-enabled device. Ubidots can configure actions and alerts from real-time data and help you visualize your data with visual tools. Sending data to Ubidots is almost as easy as to Pybytes but it requires you to construct a Json object which is then sent to the Ubidots server using the specific token that you get when registering to Ubidots. When it comes to functionality, Ubidots is clearly the better platform today as it gives you many options on how to present your data. Pybytes is in that regard way more barebones. 


Both Pybytes and Ubidots are free and are both cloud based services (Ubidots Stem specifically is free for educational purposes, see: https://ubidots.com/stem/). So any hobbyist can hop onto these platforms for free and start experimenting, however Ubidots limits you to 50 000 data points sent per day, and only lets you have a few devices connected unless you pay for a subscription fee (some [pricing examples for Ubidots](https://ubidots.com/pricing/)). If you want to eventually scale your project there is possibilities for doing this with Ubidots as well, however there is likely other options that can be explored as well.


# The code

The code can be seen in full in the following Github Repository: https://github.com/Felllux/Plant_Monitoring. 

To get everything, you first need to sign up for a Ubidots account to eventually receive a token. Signing up for Ubidots can be done [here](https://ubidots.com/stem/), and the process for finding your Token that you need to write in the code is provided [here](https://help.ubidots.com/en/articles/590078-find-your-token-from-your-ubidots-account).

Provided you follow the tips provided above and start getting the sensors to work. This can be individually by looking at and understanding the code in the read_dht, read_moist and read_light files in the repository. The only action needed to get these to work is to connect and specify the right pin that the sensors are connected to. After that you also need to calibrate the max and min value for the light sensor and the soil moisture sensor. After that, you need to specify the Ubidots token, as well as your WiFi credentials in the Boot.py file and the main.py file.

**Calibrating the Sensors**
Within the read_moist and read_light file, you need to specify both the pin that is used and the max and min values for the moisture sensor. The max value is basically what you get when you have the sensor in the air, while the lowest value is the value that is presented after it has been lowered into the water for a few minutes. 

Once the max and min values have been defined, there is a function whose purpose is to redefine volts into percentage, for an easier display in the dashboard. Ex for the moisture within read_moist:

```
def get_moist_perc():
    result = (1-(apin()-water)/(air-water))*100
    #print('Moisture level:', result)
    return result
```



# Transmitting the data/ connectivity

As previously mentioned, LoRa was considered as the first data transmission option, because I wanted the option to create a device that could send data from a remote pallet collar where you are growing vegetables for example. However, in the end I went for transmitting the data through wifi since I ultimately was monitoring the plants in my window and thus had access to WiFi. WiFi is not just simple but also the best way to transfer a lot of data. So in other words the size of the data is not of concern, in contrast to if we were to send the data with LoRa.

To send the data over WiFi, we package our data into a JSON-object which is then sent every 10 minutes (can be changed through the variable "DELAY" in the main.py file) with webhooks through Wifi to the Ubidots API where the data is received in the cloud.


# Presenting the data

Below is what the dashboard on Ubidots looks like in its current state. Something to note is that the light level sensor needs some recalibration which is why you see it dipping below 0%.

![](https://i.imgur.com/DTNXOqE.png)

Instead of presenting the voltage that is output from the analog sensors, I have chosen to do my own "calibration" of the soil moisture sensors mostly, but as evident from my dashboard I also need to tweak the values from the light sensor a little bit. 

Furthermore, I also have a trigger that sends me a text message saying I need to water my plants as soon as the soil moisture drops below 10% for more than 30 min (three measurements):

![](https://i.imgur.com/h2XUeTi.png)

![](https://i.imgur.com/DAanvKL.png)


# Finalizing the design

Below you can see the results of he setup which is now monitoring a chili plant. It is connected with a micro-usb cable directly to the wall for power. I am considering 3D printing a cover for the whole setup as well. It is by no means a perfect setup the way it is, but I am planning on updating and upgrading the setup continously in the near future.

![](https://i.imgur.com/k8mmZeQ.jpg)

When I started the project, I was a total newbie when it came to programming, and this has helped me a ton in getting started with something simple like this. When I took on the project however I expected that I would have way more time to sit and work with it, but in the end, a lot of time went away due to some work that I had to do. Overall I also wish that I had asked the more knowledged people in the course for help more often, but I would also really like to thank the people that did help me, I couldn't have put everything together without you. (And thanks Fredrik for an awesome course!)
