Using nio, I set up my desk plant (aka Keanu Leaves) to tweet me when it needs water. Using a Raspberry Pi 3 and a soil moisture sensor, nio sends a tweet mentioning me whenever it’s time to water my plant.
Difficulty Level:Easy
Build Time:Beginner: 1 hrs
Experienced: 20 min
Why would you use nio to create this project?Even though I see Keanu Leaves on my desk every day, I sometimes forget to water him. Obtaining data from the sensor and setting thresholds to conclude when the plant is getting low on water and when it needs water was very simple with the nio. The most complicated logic necessary for this use case was formatting the tweet. In order to contextualize the tweet’s content, I had to know when the state of the system changed and what the previous state was.
Get started by installing nio onto your Raspberry Pi
GetSoilMoisture ServiceThe first service in this system, GetSoilMoisture, simply obtains data from the soil moisture sensor in the dirt. The IdentityIntervalSimulator sends a signal through the system every hour. This signal triggers the MCP300X block in the system to gather current data from the moisture sensor and publishes that data to a topic that other services can subscribe to. The reason behind keeping this service small is to make sure the nio system stays modular. By splitting up the services to accomplish one goal, it makes it easy to use this same soil moisture data for a different purpose in the future if necessary.
The second service, SendTweet, subscribes to the soil moisture data from the first service and uses information about the state of the system to create a Twitter message that the service will post. The logic that goes into this service is slightly more complicated than the first one. The first ConditionalModifier block configures the state of the system based on the value of the sensor data. The StateChange block will emit a signal whenever the soil moisture changes between the thresholds set in the previous ConditionalModifier block. This block emits a signal that has the current (new) state of the system and the previous state. Based on that logic, the second ConditionalModifier block configures the text of the tweet. The Filter block just before the tweet is posted makes sure the tweet has content and the PostTweet block posts the tweet to the account configured in the block properties.
Advice for someone recreating this project?- Problem: Using the MCP block in nio requires SPI to be enabled on the Raspberry Pi -- enable SPI in the Raspberry Pi config.
- Enhancement: Have a reservoir of water with a spigot to enable automatic watering.
- Enhancement: Hook up Blink1 to visually see moisture in the soil.
The nio service was throwing an error as soon as signals were passed into the MCP300X block. The problem was that the Raspberry Pi needs SPI enabled in order for nio to read from the sensor using the MCP300X block. This interface can be enabled in the Raspberry Pi’s config.
To make this system even better, I would have liked to have added a couple of features and additional hardware pieces. First, I would create a reservoir of water so the plant could decide when it needs water and how much water to give itself. In addition, adding a Blink1 LED or some other sort of indicator to portray the state of the system would be helpful instead of just waiting for a tweet to be sent out. Both of these enhancements would have been fairly simple to add using nio.
Have questions on how to build it? Watch the step by step tutorial below:Kylie Dale
Comments