Authors: Oktay Saygin (os222qv) & Armin Hosseini Akram (ah225xi)
This tutorial presents the steps to build a Moisture sensor reader with Pycom Lopy4 to measure the value of the soil. The code will also tell you if the plant needs more water, if it is too dry or if its in perfect condition. This project has been developed through the IoT course at Linnaeus University in Sweden.
The estimated time to build and develop this kind of project after you have recieved all of the essential parts, would take approximately five hours.
The reason why we choosed to develope this device, is because we have alot of plants at home that needs to be taken care of. And there is plenty of times were we have been confused about how much water is needed for the plant, or if the plant even need any more water. With this project, the purpose is to know if the amount of water that has been given is enough, or to use the sensor before giving water to the plant to see if it needs to be filled with more water or not.
By building and developing this project as a pair, we have gained more knowledge and understanding about using Pycom device and writing codes. We have even gained more knowledge with how we can establish a WiFi connection using the device and send data from the device to visualize it.
The list below, will present all material thats needed for this project.
Product | Links | Description | Price |
---|---|---|---|
Jumper wire male to female | Link | For connecting the sensors | 79 SEK |
Soil moisture sensor | Link | Measures resistance | 29 SEK |
Pycom Expansion board 3.1 | Link | Allows to create and connect new IoT project | 245 SEK |
Jumper wire female to female | Link | For connecting the sensors | 89 SEK |
Adapter cable RP-SMA | Link | Cable that connects the antenna to the device | 59 SEK |
Antenna cable 2.4GHz | Link | Antenna used for connecting to internet | 109 SEK |
Micro-USB cable | Link | Used for connecting the device with the computer | 99 SEK |
Lopy4 | Link | Micropython bearer board | 405 SEK |
Table 1. Picture on all of the materials needed.
For this project, we choosed to use Atom with the pymakr plugin to program the microcontroller and write the codes thats needed. To install the Atom IDE and the Pymark plugin you will need a computer and Internet connection. We are using a windows computer but it will also work with Mac and Linux depending on which operating system you have.
After you have downloaded Atom, start the program and navigate to the install packages menu. You can do this by clicking on File –> Settings –> Install. Search for Pymakr and install it, it will take a short time but make sure you have it installed.
The reason for updating your device is to be updated with the latest firmware and so you can use your code or even try a small code to confirm that everything is working fine. For this step, we are using a Pycom board Lopy4 for connecting it to the computer and being able to update/flash the device.
Be sure to connect all of the cables correctly so you don´t have to interuppt the firmware update process since it could damage the board. Make sure to have Atom closed when doing theese steps aswell.
Start by connecting your Pycom board to your computer with the USB cable that we provided in the list above.
Make sure you know which COM port that your Pycomboard is connected, to make the process even more smooth.
Download the Firmware Update from here
Install the file and open it. Press Continue twice and then make sure to select the correct COM port that is connected to your Pycom board. Then on the "type" section, choose development and continue. After that make sure the information about the device is correct and check the box for "Erase during update" and then press continue. Watch the result and make sure the board was successfully updated and press done. You have now flashed and updated your device and it is ready to run codes.
This is how it should be when you have your pycom device connected to your computer
You can now open Atom, reconnect your board and you should then be able to connect the device in Atom and you should see a green light toogled on the Atom program when connected.
So how is all the electronics connected?
By doing the steps before, you have updated your pycom device and you have also set it up in the Atom with the Pymakr plugin. You are now ready to connect the wires together with the other materials.
To make the process more easy, open this link so you have a better understanding of were you should connect the cables. Press here
When you have connected all these wires. Proceed to next step. Note, the Soil moisture sensor in this case is the small blue chip, the larger sensor that you use to put in the plant will in this tutorial be called for Moisture reader.
For the next step you need to take two wire jumpers female to female and insert them to the other end of the Soil moisture sensor. When you connect the female to female on the Soil moisture sensor, make sure that the wire thats connected on the plus side, needs to be connected to the right side of the Moisture reader. And the wire connected to the minus, needs to be connected to the left side of the Moisture reader. After doing this step, it should look like the picture below.
You have now succesfully connected all of the materials together and can now proceed to use the platform Pybytes. Pybytes is the platform that we used to Visualize collected data and to be able to send our sensor data to the cloud. Pybytes is a free platform, use thislink to register online
With the Pybytes platform you can manage and have full control over pycom device to be able to check status, track signal get firmware updates and even visualise data by using their dashboards. However we will talk more about the dashboard later on the tutorial.
You do even have the ability to use Pybytes own Terminal to execute commands and gather information from your device, and track your device geolocation trought the Google Maps API.
Other alternatives platforms to choose from are Ubidots, Datacake and Adafruit.
Ubidot is a platform similar to the other alternatives where you can register for free, but it also have a subscription pricing if you want to take your project to higher levels and need more devices.
Datacake is a low-code IoT platform (free) where you don´t need any programming skills and it takes minimal time to create you´re dashboards.
Adafruit is also a free platform to stream, log and visualize your data. However there is a subscription for "Power Up" where you get acces to log more data points per minute and aquire more days of data storage.
We will first demonstrate how to connect your Pycom board to access the internet. Since this Pycom device has a built-in WiFi we will access the internet through WiFi. Other alternatives could be LoRaWAN via Chirpstack, The Things Network and Helium, or LTE via CAT-M1 and NB-IoT. But for this tutorial we will shows the steps to connect to the Wi-Fi.
Make sure to have your Pycom device connected to your computer and open up the Atom program and connect the device. Create a folder named test or something you like, and create a file called boot.py
After you created the file, insert the code on the right side of Atom.
Make sure to change "YourSSID" and "YourPassword" on line 14 to your own home WiFi name and password. Note, make sure that your pycom board works on 2.4 GHz and the same with your home router. After inserting the code, press on run and wait. You should then se that the device is now connected to your WiFi.
You can also click on "Get device info" in Atom to check if you are connected to your WiFi.
When you are done with connecting to WiFi you can now proceed to the Pybytes website where you have registered. We will now show you the way to use Pybytes to add your device and use Pybytes to Visualize data.
When you are done with creating your device in Pybytes, navigate on the Pybytes website to Provisioning and choose Pymakr plugin. Make sure that you have the Pymakr plugin installed, connect your device with USB to your computer, have the Atom program opened. Generate activation string on the website, copy it in to the pymakr window on Atom and run it. After a few moments your device should be connected to the platform.
Once you are connected to Pybytes, you will now proceed to create a new file on the existing folder you are using on Atom. Name the file main.py
The reason for this new file is because you will now insert the code that will make it possible to read the moisture level on your plants. Here is the link to the code that you will insert in main.py click here
After you have inserted the code click on run. You can now proceed to put the Moisture reader on your plants to get the value
The READING_DELAY_IN_S = 2 indicates that the moisture reader will read the soil every two seconds, and the NUM_READINGS = 5 indicates that it will read the soil five times before giving a average reading. The average reading is done through the code average_reading = int (total/NUM_READINGS) and will then print the average moisture value.
For this project we have given a low and high value based on if the plants have to much water or if its to dry, the values are 1800 and 3500. If the sensor is getting a average value from the plants that is to high, to low or in between the stage of low and high it will print out a information for you and tell you if the plant is living a good life, if it is drowning or if the plant needs a refill. The codes for this are located between line 22 and 32.
The device used for this project, the pycom lopy4 has a WiFi built-in which is why we are using the WiFi connection to transmit the data between the device to the internet. For this kind of projects, the WiFi is good to use because the plants that we use to monitor are in the range for the WiFi connection. The transport of the data from the device sends its information to the Pybytes website and gives 5 value signals for every minute.
For the visualizing of the data we are using the functions for dashboard through Pybytes website. If you navigate to the Signal section you will also be able to see 5 value signals for every minute showing the value of the Moisture that the reader has given us on the plant. When it comes to presenting the data through dashboards, we have experienced that the websites widgets and the analyze are bugging, we don´t really know if it depends on the trafficing on the website. But for us it seemed like we were unable to establish a good dashboard that gives information on the average value and single value on the plant we used for this project. When we tried setting up different dashboards, we discovered that the platform would crash for us, meaning that we had to redo the whole process by deleting our device from the website and creating a new device. The tutorials that are shown on the pybytes are also outdated and creating widgets for the dashboards as described does not work. But if the dashboard would work correctly, it should give us a estimated information about the data the past hour, and data for the whole day. We were expecting alot more from the dashboard tools by Pybytes, and if we had the chance to redo this project again, we would use another platform to visualize and present our data.
However, we will present a picture on the signal value that the plant has given to us, which was 5 signals per minute.
This is the results of our project in pictures after connecting the device to the computer, inserting the codes in the Atom, connecting it to internet and putting the Moisture reader on the plant.
We are satisfied with what we had accomplished being a beginner in this course. And we are glad to create a device that we would use at home and monitor our plants. However there are some issues that we had encountered.
First of all, the two of us authors owns Macbook and we tried doing the projects with the Mac. The problem we encountered was that on our computers we dont have a USB port for connecting the Pycom device directly, we had to use a usb hub but we experienced that the hub was giving a weak connection making it unable to update the firmware and conneting to internet. We had several workshops that we attended to solve the problem, but it took alot of our time to focus on the project, so we decided to continue with the project by using a Windows computer. When using the windows computer everything worked smooth and there was no problem with the USB connection.
Second problem was the Pybytes dashboards as we mentioned earlier. It was very buggy and outdated, it also made us redo the process of creating a device several times. If we were to do another project, we would first of all use a windows computer or a Mac with a USB port, and we would also switch to another platform where they have better tools for dashboards.
Having no experience joining this course, we have learned and gained new insight and knowledge about IoT, the devices that we used, connectivity through internet and to write codes. The course was also very uniqe because all of our lectures and information was through the Discord application. But it was also very fun to use the Discord application to navigate because we like how the setup of the course was and we think that having a distance course through Discord was very effective compared to other distance course we have attended.
But for the end result, we are very happy to accomplish this project and being able to use all of our materials that we had and forfill the purpose of the project. This will be a good memory for both of us and the course has opened new paths for us to explore in the future.