IoT Prototyping Series: Building an IoT Plant Cultivation System Pt. 3
In this three-part series, I’m building my very own IoT plant cultivation system from start to finish to keep my houseplants green and fresh from anywhere in the world.
Today, we’re going to start collecting data from our sensors and visualize it using Soracom Lagoon and Harvest!
Without further ado, let’s get started!
Fixing the Sensor Readings
Now that we’re done setting up the LED lighting using Soracom Funk, Soracom Beam and Unified Endpoint, it’s time to read the values from our CO2 sensor.
You can find sample code for this on GitHub, but the control ended up being a little bit complex. The sensor needs to be calibrated and can only be read if it’s operating for over a week.
Once the baseline value is gathered, it needs to be held in the EEPROM or somewhere and set it to the sensor when the device starts. This may seem rather straightforward but it also ended up being slightly complicated.
You can save the value in EEPROM (or Flash), but for this project I decided to save the value in the SIM tag.
Therefore, when the baseline value was obtained, it was sent to AWS Lambda via Soracom Funk along with the value. From there, the AWS Lambda side called the SORACOM API and saved it in the metadata.
When the device starts up, it gets the baseline via metadata and sets that value to the sensor.
Trying to acquire the metadata by HTTP communication immediately after the device was started up failed with a high probability.
The reason for the failure is that an error occurs at the time of connection, so it seems that there may be a timing problem but it may be necessary to keep it locally with EEPROM, etc. However, this will be something that I work to solve in the future.
Implementing Binary Parser
For all of the other sensors – brightness, soil moisture and temperature – we were able to acquire data quickly without any problems.
This data is serialized to binary and all 18 bytes of it are sent over UDP. Once you set the binary parser on the Soracom side, you can send data from the device in binary format to reduce data traffic. This works well because the Lambda beyond Funk can conveniently receive data in JSON format.
On the other hand, the response from Lambda was in JSON format, so it was necessary to parse the JSON on the Wio 3G side. There was a convenient library called ArduinoJson, so it was not a difficult process if you used it, but here is a function that reverses the binary parser (converts it from JSON to binary format and sends it to the device side).
This is something useful that we might look to have on the Soracom platform as well.
Visualizing the Data with Harvest and Lagoon
Harvest and Lagoon are both simple to use and sophisticated, so once you get used to them, you can get things done in mere minutes.
You can also set an alert so this time, we have set up a notification by email when the value of the soil moisture sensor exceeds a certain threshold (when the soil dries).
Future Improvements
Now that the project is finished, I’ve been sharing it with friends and colleagues to get feedback on ways that I can improve it.
Here are a few thoughts that I’ll be exploring along with interesting non-related matters I figured I’d share:
- It’d be great if I can automate the watering management. The method to automate watering by controlling the opening and closing of the water supply valve may work in a full-scale system, but in a smaller system like this, I can reduce water waste by instead controlling the supply of power to the pump.
- Plants need red and blue light to grow, but in fact green light is meaningful because it penetrates leaves and shines from the ground and hits the back of the leaves. So it’s better to turn on all of the LEDs for RGB. This is something that I learned through the project and applied after initially only using red and blue to illuminate.
- With the sensor measuring soil nutrients being so expensive, I wonder if we can build something cheaper that enables more people to experiment.
- Integrating this IoT project with Alexa can allow users to talk about moisture alerts, not just emails, which will make you feel like you’re communicating with your plants.
- There should be an AI that monitors a camera and takes time-lapse images to find signs of illness, judge nutrition status, give advice and more!
- If you waterproof it so that it can be used outdoors, the veranda garden can be automated, making it the ultimate spot for local consumption. This would make traceability a non issue while providing elderly couples and others who can’t easily go out with access to fresh vegetables every day.
- I wonder if the location of the soil moisture sensor should be closer to the root of the plant. In addition, since the soil temperature is more important than the air temperature, it is better to measure it. The rice taste seems to be determined by the soil temperature of the first two weeks after planting rice.
Overall, this project was a great experience. By creating something and letting everyone see it, I built a discussion point that can lead to improvements and suggestions from various people.
My plant cultivation system started from the desire to grow my houseplants. At first, I had only two leaves smaller than my little fingernail. Over more than two months, these two have grown at an incredible rate, with new leaves sprouting that are larger than the initial first two.
In addition to the joy I’m feeling now that the plants are growing, the feedback from the audience was much more than I anticipated, and was a very valuable experience.
Thanks for staying for the three-part blog series. If you have a familiar problem that can be solved with IoT, quickly create a working concept and share it with friends and colleagues!