The Agricultural Sensor Array
A project by Jackson Breakell, Tyler McCubbins and Jakob Thaler for EF 230
Agriculture is a vital factor of production in the United States. Crops can be used for a wide variety of different purposes, ranging from raw materials for the production of clothing, pharmaceuticals and food additives to direct consumption of the parts of the crop, most often the germinating fruit. The majority of crops in the United States are grown outdoors, where weather conditions nor temperature cannot be controlled on a large scale. Given how drastically adverse weather conditions can affect the growth of crops, in turn affecting the United State's economy, monitoring the conditions of a crop field becomes vital.
Our device, the Agricultural Sensor Array, allows farmers to monitor the condition of pre-selected parts of their field using 4 sensors: a rainwater sensor, a soil moisture sensor, a temperature sensor and a photoelectric sensor. The combination of these sensors allows a farmer to adequately plan the season's crop output, adjust for too little or too much rain, better deal with disasters that may kill crops and save time and trouble from taking soil samples and using more expensive sensor equipment. In this Instructable, we will walk you through the wiring and coding behind our Agricultural Sensor Array, so you too can make your own.
Gather Required Materials
Below is a list of the required materials you'll need to get started"
1. Arduino Board, preferably Arduino Uno
2. Basic breadboard
3. 1x 220 ohm resistor
4. Assorted wires of different colors
5. Micro USB to USB cable
6. Board-mountable speaker
7. Photoelectric Sensor
8. Temperature Sensor
9. Rainwater Sensor
10. Soil Moisture Sensor
11. Computer with Matlab 2017 and Arduino Support Package installed (Support package can be found under Add-Ons)
Wire the Board and Connect
Begin by either wiring the board as shown above, or in whatever way best fits you. There are literally unlimited ways the board can be wired, so the exact configuration is really up to you. After the board is wired, begin attaching your sensors. The rainwater, soil moisture and photoelectric sensors are all analog outputs, so make sure they are wired into the analog-in section of the Arduino. The temperature sensor, on the other hand, is a digital output, so make sure it is wired into an available digital input on your Arduino. The Arduino should have outputs for 3.3v and 5v, so be sure that the sensors are connected to voltages that they are compatible with.
After you are sure that the board has been wired correctly, plug the Micro USB to USB cable from your computer into the Micro USB port on your computer, and power your Arduino on. Open Matlab, and, making sure you have installed the Arduino Support Package under Add-Ons, run the command, "fopen(serial('nada'))", without the ". An error should pop up, and the error should tell you there is an available comport with a number. Run the command "a=arduino('comx','uno')", where x is the number of your comport, to map your Arduino to an object. The LED on the Arduino should flash rapidly to indicate it is connected.
Code the Photoelectric and Temperature Sensors
Before you start coding, make a note of where your sensors are connected on the Arduino, as this will be important for the readVoltage command. Begin your code by setting the variable sunlight equal to the command "readVoltage(a,'X#')', where X# is the port you are connected to, and a is simply calling the Arduino you mapped to that variable. Start an if statement, and set the first condition for sunlight<3. Set the output as "info.TOD='night'" to output the time of day as a structure, and then add an else statement with the output as "info.TOD='day'". Since this is an else statement, we don't need a condition, as it will work for all other values not defined in the if statement. Make sure you finish your if statement with an end, and move on to programming the temperature sensor.
Set the variable thermo equal to another readVoltage command, the command being "readVoltage(a,'X#')". In our case, the temperature was had to be converted from units of voltage into Celsius, so the equation "tempC=(thermo-.5).*100" to convert from the voltage to Celsius. For the sake of ease, we converted the temperature in Celsius to Fahrenheit, but this is purely optional.
Code for pasting purposes
sunlight=readVoltage(a,'A1')
if sunlight<3
info.TOD='night'
else
info.TOD='day'
end
thermo=readVoltage(a,'A3');
tempC=(thermo-.5).*100;
info.tempF=(9/5.*tempC)+32
Code the Rainwater and Soil Moisture Sensors
As stated in the last step, make sure you know what ports your sensors are plugged into on the Arduino board, as it will make this step much less frustrating. Begin with the rainwater sensor, and start an if statement. Set the first condition for "readVoltage(a,'X#')>4", and set its output to "info.Rain='no precipitation". Add an elseif, and set its conditional to the readVoltage command before, but set it to >2. Add an "&&" to signify another condition that must be fulfilled, and set it to a readVoltage command like before, and set it to <=4. The output will be "info.Rain='misting'". Finally, add an else and set its output to "info.Rain='downpour'". You may have to adjust the values for the conditions based on the ambient humidity of the room you are working in.
Next, begin the code for the soil moisture sensor, and start with an if statement. Set the condition of the if statement to "readVoltage(a,'X#')>4, and add the output "info.soil='dry'". Add an elseif statement, and using the readVoltage command above, set it for >2. Add an "&&", and set another readVoltage command for <=4. Set its output to "info.soil='optimal saturation'". Add an else statement and set its output to "info.soil='flood'", and don't forget to add an end.
Code for pasting purposes
if readVoltage(a,'A0')>4
info.Rain='no precipitation'
elseif readVoltage(a,'A0')>2 && readVoltage(a,'A0')<=4
info.Rain='misting'
else
info.Rain='downpour'
end
if readVoltage(a,'A2')>4
info.soil='dry'
elseif readVoltage(a,'A2')>2 && readVoltage(a,'A0')<=4
info.soil='optimal saturation'
else
info.soil='flood'
end
Speaker and Message Box Output Coding
Outputs for this device can vary widely, but, in this case, we will be walking you through a speaker output mounted directly on a device and a message box output that can be viewed on a remote computer. Our speaker is designed to output different frequencies, lower meaning worse, for optimal crop temperature, sunlight, soil moisture and precipitation. Begin your speaker output code with an if statement, and set its condition to the command "readVoltage(a,'X#')>4 || info.tempF<32". Then, set the output to the command "playTone(a,'S#',200,1)", where S# is where the speaker is on the board. Add an elseif, and set its condition to "sunlight>=3 || readVoltage(a,'A2')>2 && readVoltage(a,'A0')<=4". Add the same playTone command as shown above, but change 200 to 1000 to produce a higher, more positive tone. Then, add an else, and add the same playTone command again, but change 1000 to 1500. These varying tones indicate the severity of the situation of the field. Make sure you add an end to complete your if statement.
Our final section of code will be an output that produces a message box. Create a string using ' marks in brackets, and convert the parts of your structure to strings by using the command "num2str(info.x)", where x is a substructure name in the info structure. Use "string newline" to add newlines into your message box, and type your message in text using the quotation mark, adding the actual value of the field into the string using the aforementioned num2str command. Finally, with the string defined, used the command "msgbox(string)" to display the data as a message box on your monitor.
Code for pasting purposes
if readVoltage(a,'A2')>4 || info.tempF<32
playTone(a,'D9',200,1)
elseif sunlight>=3 || readVoltage(a,'A2')>2 && readVoltage(a,'A0')<=4
playTone(a,'D9',1000,3)
else
playTone(a,'D9',1500,5)
end
string = ['The temp is (deg F) ',num2str(info.tempF)]
string=[string newline 'The soil is ', num2str(info.soil)]
string=[string newline 'Outside precipitation is ', num2str(info.Rain)]
string=[string newline 'The time of day is ', num2str(info.TOD)]
msgbox(string)
Conclusion
While the world is continuing to rely more and more on synthetic alternatives to items previously harvested from crops, agriculture will certainly remain a relevant and important factor of the economy for a long time. Adequately monitoring farmland is crucial for a farmer to get to most out of his or her harvest, and, with our device, it is not only possible to monitor the entire farmland remotely, but it is possible to do it in a cheap, easy to install and reliable manner. We hope this guide has proved informative and easy to follow, and we hope the device proves useful for however you wish to implement or experiment with it.
Happy coding,
The Agricultural Sensor Array Team