How does the Azure IoT Garden Project hardware work?
In Part 1, I described the context of an IoT Project that focused on managing and reporting on a garden environment. To improve productivity results, I have decided to put my Azure IOT and Cloud service knowledge to good use at home. Fortunately, with IoT Microcontrollers not only can I measure the common environmental sensor readings I can control external systems to support the environment in the form of Fertilizer and Chicken feed delivery systems.
The Mini Farm environment for this Project includes three plots of garden beds, a worm farm and a chicken house. The main goal is for the IoT solution to monitor the environment and control the water and feeding systems for the plants and animals.
The picture below shows my two raised beds and standard plot.
This blog will describe the infrastructure components.
Traditional watering systems work with timer systems and soil moisture level triggers. They do not provide measurements of water usage and environmental impacts over time. With the Azure IoT Garden project, my main goal is to measure the soil condition and evaporation rates over time and to be accountable for water usage. To achieve evaporation measurements, I will have a series of soil moisture sensors at surface level and one at 30 cm below the surface.
The difference between moisture levels at the surface and 30cm below over time should enable calculations of evaporation over time and help to generate trends on how much water is required for the garden. Depending on the age, maturity and the kind of plants the watering requirements will also differ. Seedlings will require constant management of moisture at the surface level for the first two weeks and mature plants in fruit also need additional water.
Azure Device Twins is an excellent service that allows the logical digitising of the farm into spaces, plant varieties and environmental settings. Digital twins allow me to code specific requirements for the environment pending on the plant, location and its maturity, more on this in a future blog. Through sending environmental measurements to the cloud for storage and monitoring trends we can use Azure machine learning services to predict evaporation rates.
We will also use reinforcement learning strategies in Azure Machine Learning to calculate the most effective watering strategies over time. To ensure I collect the environmental statistics I need to determine trends I will need IoT sensors to collect Temperature, Humidity, Light, UV index and soil moisture. The hardware devices needed to collect sensor data needed to work outside with low power and some internet connectivity.
In this project, the Arduino MKR NB 1500 and the ENV environmental sensor board works well for my requirements. Of interest is low power and Narrowband connectivity. As the microcontroller needed to work off a solar battery system and Mobile data network this board which I got from Telstra does the job
The Narrowband communication for the IoT Garden project with the MKR NB 1500 is perfect for devices in remote locations without an Internet connection, or in situations in which power isn't available like on-field deployments, remote metering systems, solar-powered devices, or other extreme scenarios. The board's main processor is a low power Arm® Cortex®-M0 32-bit SAMD21, like in the other boards within the Arduino MKR family. The Narrowband connectivity is performed with a module from u-blox, the SARA-R410M-02B, a low power chipset operating in the different bands of the IoT LTE cellular range. On top of those, secure communication is ensured through the Microchip® ECC508 crypto chip. Besides that, the PCB includes a battery charger and a connector for an external antenna.
The board connectivity is on TELSTRA LTE's Cat M1/NB1. The USB port or 5V pin can be used to supply power (5V) to the board. It has a Li-Po charging circuit that allows the board to run on battery power or an external 5-volt source, charging the Li-Po battery while running on external power. Switching from one source to the other is done automatically.
The MKR NB 1500 runs on 5 Volts. This provided a challenge as all my batteries and solar systems work on 12 Volts. I need one of the power supply regulator modules to turn 12v to 5v
High-Quality 3A Adjustable input 4V-35V Output 1.23V-30V dc-dc Step-down Power Supply Regulator module:
On completion of the project, I measured the current drawn from the power supply and it was 150 mAmps. The 80 Watt Solar Panel and 12v 40AH battery does the job well.
Soil Moisture Sensors
The Soil Moisture sensor below consists of two probes that are used to measure the volumetric content of water. The two probes allow the current to pass through the soil, which gives the resistance value to measure the moisture value. These cheap sensors cost me $1 AUD from Aliexpress.com.au in China. They are so cheap; However, I do not expect them to last more than one year in an external environment exposed to the weather. The fact is they started to break down after 3 months from corrosion. The devices are active and operate on 5Volts. The resistance between the two probes tends to be high with no water and low within the water. The resistance change affects the return voltage to the analogue input on the MKR NB 1500 input pin. Arduino code routines will monitor the voltage and report its value between 0 and 100. Low values of less than 10 are very moist and high values over 90 is very dry.
I have ordered some new soil moisture sensors as below to get a more resilient sensor:
Arduino Code to report Soil Moisture:
The basic steps to configure the Arduino MKR NB 1500 code to report the soil moisture is:
Assign pins to sensor variables
int watersensorpin_a = A1;
int watersensorpin_b = A2;
int watersensorpin_c = A3;
I initially have three sensors in place. The above code assigns a variable to an analogue PIN number:
Read each sensor pin
soilmoisture_a = analogRead(A1);
soilmoisture_a = map(soilmoisture_a,0,1023,0,100);
soilmoisture_b = analogRead(A2);
soilmoisture_b = map(soilmoisture_a,0,1023,0,100);
The microcontroller will initially measure the voltage as a value between 0 and 1023. I would rather work with less sensitive data and re-map the readings between 0 and 100 so its easier to work with
Measuring Water flow
The measurement of the water flow is essential to the project for monitoring the amount of water sent to the sprinkler system. This device is a hall effect sensor and as the water flows through a miniature spindle will spin and as it rotates a small magnet will also spin and generate a hall effect and send an electrical pulse back to the Arduino Microcontroller. The frequency of the Pulses is measured to determine the water flow.
///////Calc water flow
X = pulseIn(waterflowinput, HIGH);
Y = pulseIn(waterflowinput, LOW);
TIME = X + Y;
FREQUENCY = 1000000/TIME;
WATER = FREQUENCY/7.5;
//LS = WATER/60;
if(FREQUENCY >= 0)
TOTAL = TOTAL + LS;
The code will determine water flow in litres and calculate the total water used.
Chicken Feed level Sensor:
I have automated the chicken feed dispensing system. The IoT Garden project monitors a large feed container for remaining feed, dispense the chook feed pellets into the feeder and send Email and Teams alerts when the store is nearly empty. The Ultrasonic Transducer SR-04 is mounted at the top of the Large feed container and it is configured to measure the distance between the top of the container to the top of the feed that is stored in the container. Measurements of 5cm will equate to full and measurements of 35 cm will equate to empty, at which time email, TEAMS alerts over the internet will be sent so I can top up the main Chook pellet storage.
Chicken feed dispenser:
The delivery system for chicken pellets into the feeder tray is through the 3d printed Auger above. A 30kg rated servo motor is used to drive the Auger which spins. The main Chicken feed container is placed on top of the Auger and pellets will drop into the Auger. When the Auger is commanded to activate the feed will be forced out into a feeder tray. The feeder activation is automatic on a timer or voice-activated through Google assistant.
The Fertiliser Level Sensor:
The Environmental ENV board:
The MKR ENV Shield allows an MKR board to acquire environmental data collected by an array of sensors.
These sensors are of the latest generation and measure:
- Atmospheric pressure
- Temperature and humidity
- Ultraviolet UVA intensity
Ultraviolet UVB intensity,
- UV Index (calculated)
- Light intensity (in LUX)
To help you build projects and store the data collected locally, this shield has a slot for a microSD card (not provided).
There is a ready to use the library with examples and methods to read values from the different sensors, that provides an easy and smooth integration path.
The water solenoid will turn on if 12V is applied the actuator opening the valve and allowing water to flow to the sprinkler system. The Arduino microcontrollers are only a 5V system so it does not have enough power to drive the 12V solenoid. The microcontroller output pin does have enough power to activate relays that when activated provide power directly from the 12v battery. The output pin of the microcontroller is directed to go high or low to switch the water relays on.
The microcontroller can activate water flow in several ways:
- Internal triggers and routines
- Azure IoT HUB event triggers.
- Machine learnings web service calls
- Azure microservices
- Google Home assistant
I will show how this works in an upcoming blog.
Part 3 will explore the data flow of the Telemetric data and action commands.