IoT pH flow controls and automation with Costa Farms
This article showcases IoT setup for Costa Farms using the Atlas Scientific pH Sensor and Adafruit Feather M0 WiFi with the Arduino IDE, sending pH messages to Microsoft Azure.
Key technologies used
- Microsoft Azure IoT Hub
- Adafruit Feather M0 WiFi
- Atlas Scientific pH Sensor
- Arduino IDE
- Azure Stream Analytics
- Azure Event Hubs
- Azure Functions
- Azure SQL Database
Core team
- Mani Peddada – BI Architect, Costa Farms
- Rodney Sanchez – Software Developer, Costa Farms
- Blain Barton – Senior Technical Evangelist, Microsoft
- Joe Raio – Senior Technical Evangelist, Microsoft
- David Crook – Technical Evangelist, Microsoft
Customer profile
Costa Farms is a third-generation, family-owned group of companies headquartered in beautiful Miami, Florida (aka, plant paradise!). The company sprouted in 1961 when the founder, Jose Costa Sr., purchased 30 acres south of Miami to grow fresh, vine-ripened tomatoes in the winter and calamondin citrus in the summer. That soon morphed into houseplants, and the Costa Farms family started innovating and introduced new houseplants such as the canela tree, orchids, and Cecilia Aglaonema. Costa Farms sells to big box stores such as Walmart, Home Depot, and Lowe’s.
Problem statement
It’s time consuming, costly, and difficult for growers to measure and regulate pH throughout the day and across the lifecycle of a plant. Indeed, pH levels are one of the key factors in plant health. Furthermore, pH levels in the water and nutrient streams change constantly. To increase plant health via nutrient uptake and in turn promote a higher yield, pH needs to be more closely monitored and adjusted in real time.
The Azure IoT system helps Costa Farms increase revenue and profitability in using modern technology in agriculture/farming. Recalling optimal pH levels is essential for nutrient uptake. Increased nutrient uptake directly effects yields, in turn driving improved revenue per plant harvested. On the cost side, this system will allow growers to be more productive and utilized across all growing activities as they spend less time manually checking pH values by hand.
Solution, steps, and delivery
This solution uses Azure IoT Hub with pH sensor devices on hydro water systems testing correct pH levels. The goal was to use pH sensors for testing water entering and leaving the customer’s hydro systems. We used the Adafruit Feather M0 WiFi and pHSensor, Microsoft Azure and Azure IoT Hub, Azure Stream Analytics, Azure Event Hubs, Azure Functions, Azure SQL Database, and messaging via Twilio. We built a “proof of concept” that customers can use in their solutions.
Following is the overall flow of the system, which we’ll discuss in detail.
There are multiple technologies for this particular IoT solution.
The code for the hardware and software for this solution is located at https://github.com/blainbar/CostaFarmsIoT.
Hardware
First, let’s start with the hardware, the Adafruit Feather M0 WiFi, breadboard, Atlas Scientific pH Sensor, wires that connect everything, and the pH probe itself.
Following is the breadboard diagram that shows the layout of the components.
This diagram is the Adafruit Feather M0 WiFi using the I2C Arduino C code.
This is the Atlas Scientific pH red circuit board.
Here’s an image of the device we built starting with the pH probe.
Setup
For the Microsoft Azure setup, we used IoT Hub, Stream Analytics, Azure SQL Database, sending messages to Event Hubs and to Azure Functions, and then sending the messages based on the range of the minimum (Min) and maximum (Max) values.
This is the Microsoft Azure setup for Costa Farms.
We started with the hardware and C code setup, which starts the flow into Microsoft Azure.
Next, the messages are sent to IoT Hub.
-
The messages go into a SQL Azure database and are stored to be used for Power BI.
-
The messages are then sent via Stream Analytics within SQL Azure.
-
Event Hubs is then used to receive the data coming in.
-
There is input and output from IoT Hub via a QUERY that is in place to route the messages based on values.
-
QUERY states from SensorIoTHub to pH alerts give us the NurseryId, RowId, SensorId, Strain, MinValue, MaxValue, CurrentValue, DateCreated, SensorType, and also put everything into the Azure SQL database. The messages are then sent to Event Hubs.
-
Event Hubs are configured for pH alerts and pH data.
-
Event Hubs then trigger pH alerts to be sent.
-
We use Azure Functions in the flow to send messages via Twilio.
-
Code is used for the Event Hubs messages, where we log the event, put the message object into a class, create the message, set up and then send to Twilio services to a mobile phone.
-
Azure Functions sends messages based on the min and max pH levels to Twilio.
-
pH alert messages are then sent to the grower’s mobile phone.
The final output sent to the mobile phone is shown in the following screenshot.
Following are some of the plants that are grown at Costa Farms.
Solution architecture
Device used and code artifacts
Conclusion
The partnership between Costa Farms and Microsoft is strong and we have agreed to build a “proof of concept” technology-driven set of best practices for their new crops, increasing remote monitoring, preventive maintenance, and the power of the Microsoft IoT Suite and the latest sensor hardware.
Opportunities going forward
Costa Farms and Microsoft are working on two additional projects to complete using Microsoft Azure technologies. One is a Xamarin mobile app for sensor readings, the other is with Power BI. We look forward to working with Costa Farms on these new technologies.
Testimonials
“I have been able to learn some new and interesting technologies. It has been an amazing experience thanks to the Microsoft team that has worked with us: Blain Barton, Joe Raio and David Crook. The collaboration has been very good and it has been fun to build something from scratch that works and serves its purpose.” —Rodney Sánchez, Software Developer, Costa Farms
“Through this POC I’ve learned about IoT solution architecture that gets deployed using Azure services. Besides the obvious technical learnings from this process, I have also developed a broad understanding on ways to evaluate and design IoT device requirements, infrastructure requirements, and structure engagements. This has been an incredible learning experience; thank you David, Blain, and Joe for coming out here and helping us expand our horizons.” —Mani Mihira Peddada, BI Architect, Costa Farms
Additional resources
- Explore Azure IoT Hub documentation
- Find IoT devices and starter kits: Azure IoT device catalog
- Try any Azure services for free: Create your free Azure account today
- Check out a curated collection of IoT learning resources: Microsoft Technical Community Content on GitHub
- Read more IoT-focused technical case studies (like this one)