Over a million developers have joined DZone.

Farm Automation System Based on Arduino and Raspberry Pi

The author begins to design a farm automation system using microcontrollers, listing all the requirements the system needs to address.

· IoT Zone

Access the survey results 'State of Industrial Internet Application Development' to learn about latest challenges, trends and opportunities with Industrial IoT, brought to you in partnership with GE Digital.

Over the last two weeks in my free time I have been working on a system to automate a greenhouse or an open field. The system is designed using Arduino Nano and Raspberry Pi. The Arduino is used to read sensors and control devices, and the Raspberry Pi is the brain that decides what to do when an event is detected by the Arduino. The systems communicate wirelessly via XBee.

In a normal scenario on a farm we have to:

  • Switch on the drip irrigation pump when the soil humidity is low.
  • Switch off the pump when the soil is wet.
  • Switch on the main motor that connects to a water source when the reservoir level goes down.
  • Switch off the main motor when the reservoir is full.
  • If it’s a greenhouse then we need to monitor the humidity and control devices to increase or decrease the humidity, and we need to control temperature.

Below is a very ugly drawing I came up with to explain the system.

Image title

Arduino Based Nodes

The nodes are connected to different Sensors for Soil Humidity, Temperature, Air Humidity, etc. Also the nodes can switch on/off the drip irrigation motor and the reservoir’s Solenoid valves, or control any hardware needed in the field.

Raspberry Pi Brain

I developed this central/brain system in Node.js. The system is very generic and based on configurations, so nothing is hardcoded. The XBee connected to the Pi acts as the coordinator and receives periodic sensor inputs from Ardunio connected in the field. This system can issue commands to control devices based on the sensor inputs.

Let’s go through some of the scenarios to see how the system works.

Watering the plants: From the above picture you can see there are five Arduinos in the field sensing different parameters. For now let's think that they all read the soil humidity. Say soil humidity values range from 0 to 100, where 0 is dry and 100 is fully wet. We need to switch on the drip irrigation motor when any of the sensor values is less than 20. Once all the sensors give a humidity value greater than 90 we need to switch off the motor.

As you can see the system needs to take action based on the values coming from the sensor. Depending upon the crops, these values can be changed. That’s where the central Node.js system comes into play.

In the central system, we can group the sensor nodes and configure the triggering points. We can also configure what to do when the triggering points are reached. For example, in the above case we can say when the soil humidity of any sensor goes below 20, then send the motor "switch on" command to the node sitting next to the reservoir motor. To switch off the motor the system needs approval from all the sensors, which means the motor will get switched off if all the nodes reported value is greater than 90.

Failover: What happens when a sensor node dies without sending soil humidity a greater than 90 value? Will the motor run whole day? No. The central system can be configured for that too, and during configuration we can set up a timeout period. If the central system is not receiving high water level signals after a configured time, it automatically sends a switch off command to the desired Arduino node to switch off the motor.

Filling Reservoir: From the above diagram, we can see there are two reservoirs and one main motor. The main motor needs to switch on to fill the reservoir. Each reservoir is equipped with sensors to detect the high and low water levels. Also each water input is equipped with a solenoid valve. If the reservoir is high then the solenoid valve will close the input thus protect the reservoir from overflowing. Once all the reservoirs get filled, the system will switch off the main motor before closing the last solenoid. Otherwise the pressure increases and can damage the main motor.

The Arduino node will send a water low message when the water goes down below a desired level. Then the central system will open the solenoid before switching on the main motor. The valve will open only for the reservoir where the water is low.

If more than one reservoir's water is low, then those valves will open and the main pump will work until all the reservoirs are filled. Say reservoir A and B’s water levels are low. Then both the valves will be opened and switch on the main pump. If A gets filled and B is still not full then A’s valve will get closed. Once B is full the system will send the main pump switch the off command then send the command to close B’s valve.

System Design

All the above scenarios are based on certain rules, and all these rules are configurable. The central system is not aware of any rules. Based on the fields condition we need to configure it.

The user can also see the activities in the farm via a dashboard. I haven’t designed any Dashboard UI yet.

Happy farming…

The IoT Zone is brought to you in partnership with GE Digital.  Discover how IoT developers are using Predix to disrupt traditional industrial development models.

arduino,raspberry pi

Published at DZone with permission of Sony Arouje, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}