By Linnea Allander a.k.a la223sp
This project will give an insight in the area that is the internet of things (IoT) as I explain what I've done and what choises I've made for this project. The plant communicator project will gather sensor values once every half hour or when a button on the board is pressed and send them to an online platform for data storage and presentation. Over time I'll get to know the plant's needs as light, relative airhumidity, moisture of the soil and room tempature is measured. The plant communicator will also notify when something isn't right. I'll discuss components, code, platforms and scaling factors. This project should not take long to assemble, maybe a day.
In order to replicate the project some sensors and a device able to connect to the internet is needed. I bought the sensors and Pycom devices from Electrokit.se and the rest I took from the Arduino starter kit. Estimated total cost: 62 €
The DHT11 sensor is used to measure the tempature and airhumidity in the area around the sensor. This could be of importance if the plant is sensitive to lower or higher tempatures.
Specs | |
---|---|
Operating Voltage | 3.3V to 5.5V |
Humidity range | 20% to 90% RH |
Humidity accuracy | ±5% RH |
Humidity resolution | 1% RH |
Temperature range | 0ºC to 50ºC [32ºF to 122ºF] |
Temperature accuracy | ±2ºC |
Temperature resolution | 1ºC |
The photoresistor sensor measures light intensity. In the presence of light the resistance will decrease and give a higher output value. In the absence of light it'll do the opposite, the recistance will increase and the value gets lower. If the plant needs a lot of time in the sun this sensor should help locate the place. The Electrokit sensor has an build-in 10 kΩ resistor, however, if the sensor is from Arduino the 10 kΩ is needed to be present in circuit.
The DIY moisture sensor consists of 3 cables and one 1MΩ resistor. One cable connected to ground (GND) and the plant, one connected to the power (VCC) through the 1MΩ restistance and the plant and one connected to an analog pin at the device and the circut. The soil closes the circuit and offers resistance depending on level of moisture. The more moist the soil is the less voltage will be measured. The sensor of course has to be calibrated, meaning some values of dry and wet soil are needed in order to know when the plant needs water next time.
The push button, when pushed, note all sensor values and send them online. It will also indicate if the plant needs water or not with a flash of the Pycoms built-in LED.
On the breadboard one can connect the sensors to power, ground and the device easily.
The Expansion board is needed to program the LoPy4 and to supply it with power via the micro USB connection or a lipo battery.
The LoPy4 offers several bands of connectivity and is well suited for the IoT platfrom. It is programmed in the language of MicroPython.
The Pycom devices are programmed in the language of micropython which is much similar to python. To program the device a text editor supported by the pymkr plugin is needed. At present there are only 2 editors available: Atom and Microsoft Visual Studio Code. For this project I was using Atom, which can be downloaded from Atom.io. Open Atom, then under File -> Settings, pick install. There search for pymkr and install the plugin. For it to take effect rerun Atom. Now there will be a new terminal window in the bottom of the window.
Next the extensionboard and the LoPy 4 should be updated. To update the expansionboard follow the instructions given at: link
To update the LoPy 4 download the Pycom Firmware Updater at link and follow the given instructions, the LoPy should be connected to the expansionboard.
It is now possible to write some code and upload it to the device. However, there is a specific structure of the files. A project library consisting of a library with sensor files and one boot file and one main file. The main file should be kept short for readability, this file will be executed on the device. Observe the buttons to the left in the pymakr terminal in Atom, the play icon runs the current open file on the device. This button do not transfer the file nor the library. To upload the code to the device push the button underneath, this will erase excisting files on the device and upload the current project library.
First, as a saftey standard, make sure the breadboard or the pycom device isn't connected to a power supply while connecting sensors. To the far left is the DIY moisture sensor, as described before in material, one cable connected to GND and the plant, one to power through 1MΩ resistance and the plant and one connceted to the pycom device PIN 16 (or one of the analog pins). Next to it is the tempature and relative humidity sensor. Place the sensor at the breadboard so that it is parallel to the breadboard's long side. Connect (from left pin to right) the first pin to the pycom device PIN 23 (or one of the digital pins) then the middle to power and the last to GND. There is a built in resistance in the DHT11 module so not to worry. Then comes the photoresistor, if the photoresistor module from Electrokit is used simply connect it the same way as the DHT11 sensor but to PIN 15 (analog pin). Otherwise, connect it to power and to GND thorugh a 10kΩ resistance and of course to the PIN at the pycom device. For the button, if the Electrokit key swith module (push button) is used connect it like DHT11 sensor and to PIN 10. Otherwise, connect it to power and GND through a 10kΩ resistance and to the PIN. Then connect GND at the expansionboard to the GND row at the breadboard and 3.3V to the power row.
As for the power supply it is possible to connect it to 5V via a micro USB cable or to a lipo battery. If using a battery it is important to think of the power comsumption. As for the LoPy4[1], while in WiFi mode it uses 107 mA and about 19,5 mA in deep sleep. A cycle of the code runs half an hour (no interrupts) in deep slepp and then about 10 seconds of awake time. The power consumption would be (10 * 107 + 1800 * 19,5)/1810 = 20 mA / cycle. If using a power bank of 20000 mAh it would be empty before 6 weeks.
Pybytes is an obvious (and free) platform for this project as it is made for Pycom devices. An account at Pybytes is needed. First configure networks, supply the SSID and credentials to a network near the device. Then choose add device. Preferably using USB, select the device (LoPy4) then select WiFi. Name the device and pick a network for the device to communicate through. Now under provisioning copy the token given at the firmware updater field. Again, start the pycom firmware updater. Make sure the type option is set to Pybytes and "force update Pybytes registration" must be checked. Paste the token and complete the update. Now the Pycom device should be connected to Pybytes via the internet! The code for this project will send signals with sensor information and then visualise the data. It is also possible to work with larger projects with multiple devices.
I've also tried to send my data to Ubidots.com. It is free to register an account but the more advanced functionalities is off limits. To send my data I used their libarary found here and altered my code. Ubidots provides a broader range of different dashboards to visualise data. Their notification system can note when the data is irregular and send an email or sms which Pybytes can not. The paid version let the user to work on a project with others as they can be given access to view data from one or multiple devices. This version also enables the user to process and conduct analysis on the data in the cloud with custom funtions. To scale the project the paid version of Ubidots platform is prefered.
customMoistureSensor file for reading the moisture level of the soil.
lightSensor file, reads the light intensity.
tempRHSensor file, together with the dht library (not included) reads the value of the DHT11 sensor.
Main file where it all comes together.
Since I'm too far from a LoRa gateway and planning to use the device for indoor plants I'm sending the data through WiFi. Then the device isn't confined by being connected to the computer, however it has to be in range of the WiFi and connected to a power supply. When sending to Pybytes the send_signal function, part of the Pybytes API, send given value to the platform. When sending to Ubidots a HTTPS POST (update of information) is sent and the package is in json fromat allowing more freedom in package contents.
Since the data is directly sent to an online server via WiFi the device needs to send a larger package and has a higher bandwidth than if e.g. LoRa were used. All standard layers (link, internet, transport, application, according to TCP/IP) are added to the payload before it is sent. When using LoRa or the MQTT protocol the packages can be smaller as these methods are made for IoT devices. Thus their power consumptions are lower allowing long battery life.
Sending via WiFi I chose to compensate the larger battery consumption by setting the device to deep sleep mode when it's not sending data. It sends data every half hour if not awakened by the button being pushed.
If this project were to scale, then LoRa would be better. As it can cover large ground like a field of plants or crops and with a battery life that lasts years.
It is possible to create dashboards at both Pybytes and Ubidots. For instructions on how follow Pybytes or Ubidots.
Pybytes:
Ubidots:
Note that one of the light dashboards in the Ubidots picture are in percent. Then the span for values has to be 0 to 1023 as the ADC (analog digital converter, give digital value from analog read) is set to 10 bits resolution (that is 2^10 = 1024). It is, as mentioned before, possible to assign triggers that can send notifications when met. For Pybytes this is done under notifications and create alert. The alert will only be visible in the application. For Ubidots, under events select a variable that will trigger an action. Then select an action, set up email or sms notifications. For example if the moisture variable gets greater than 250, then the soil is very dry and needs water which can trigger and email notifying the user of the plant's needs.
There is a limit to the data preservation on the platforms. Pybytes has a limit of 1-5 MB[2] data storage while Ubidots has a limit to how much you can upload per day and a 1 month data retention[3]. In order to get an understanding of the plant's needs this is plenty of data. By analyzing the produced values and adjust the code accordingly with e.g. moisture levels you'll get an increasingly better idea of what the plant need.
This project went well and without any major problems. For scaling this project a real soil moisture sensor would be prefered as it doesn't need as much adjusting (hopefully) and may not rust. As mentioned before, a closeby LoRa gateway and usage of the MQTT protocol would help when adding more devices/sensors and minimizing power supply. This was a fun and manageable first project!
LoPy 4 datasheet: https://docs.pycom.io/gitbook/assets/specsheets/Pycom_002_Specsheets_LoPy4_v2.pdf ↩︎
Pybytes account information: https://pycom.io/products/software/pybytes-3/ ↩︎
Ubidots STEM account infromation: https://help.ubidots.com/en/articles/639806-what-is-the-difference-between-ubidots-and-ubidots-stem ↩︎