In Colombia, and the world at large, there is an urgent need to obtain renewable energy resources as ecosystems due to climate change have been affected.
Here is a clear example of the events that can occur due to a lack of renewable alternatives:
During the Cesar Gaviria governmental administration (1992), Colombia suffered energy rationing as the result of a drought. The reservoirs used for the generation of electricity depleted; the phenomenon affected us and left us in a position that, although it was believed that the system was prepared to support it, still the generation of energy was very affected. The constant cuts of the energy supply had affected productive sectors (commercial, industrial), educational and home. In some homes, performance is very restricted (lighting, ventilation, cooling) due to the lack of this fluid, affecting its inhabitants. The high temperatures of the town, make it mandatory to have at least in each house: two fans, a refrigerator, plus lighting during the night. The company providing this service does not provide enough energy as our society needs.
In addition to this, drought leads to millions of crop losses on our farms
IntroductionDue to the aforementioned problems, adding millions of dollars, structural losses in agronomy and scarcity due to effects of nature that could have been avoided, the urgent need arose to find alternatives to prevent and diagnose our crops.
That is why I am entrusted with the task of designing and building an intelligent monitoring system controlled by the innovative and multifunctional Netduino 3 WiFi board and a series of grove sensors.
Basic Hardware TermsNetduino 3 WiFi: The Netduino 3 is based on a Cortex-M4 microcontroller running at 168 MHz with 384 KB of flash storage and 164 KB of RAM.
Netduino 3 is offered in 3 different models, the N3 base model, N3 Ethernet model, and the N3 WiFi model; which vary by their internet connectivity mode and their code/flash storage size. All N3 models support persistent storage with SD cards up to 2GB. Both the Ethernet and WiFi models have a Micro SD slot built in to the board. The base model can use SD cards via most Arduino SD Card add-on shields. ( Wikipedia)
Step 1: Design and SketchTo carry out this project it is necessary to have an optimal and efficient computer, with the current version of Visual Studio.
Hardware:
- Netduino 3 WiFi
- USB Cable for Netduino in perfect conditions. (Yes, it is possible extensive cable.)
- Grove Shield Base V2
- Grove Cables
- Water Grove sensor.
- Barometer grove sensor.
- UV grove sensor.
- Temp&Hum Grove sensor.
- Sunlight Grove Sensor.
- Air Quality Grove sensor.
For its structure:
NOTE: If you have a 3D printer, I will leave you the file of the design of the structure.
For all those who do not have a 3D printer:
- 1x Modeling carton.
- 1x Scalpel
- 4x 20cm sticks
- 1x Glue or silicone.
Software weuse:
- Visual Studio Community 2017
- MIT App Inventor 2
These instructions are valid for Netduino 2 and 3 boards.
Installation of Visual Studio Community 2017:
In the following link you will be able to download each and every one of the tools and software that you will need.
Install Development Tools:
Make Sure the Board Firmware is Up to Date:
Once your development environment is configured, make sure your board has the latest firmware on it. The firmware includes a customized.NETMF runtime specific to the board hardware. Firmware update instructions are here.
Create a new.NET MicroFramework App:
Visual Studio for Windows- Launch Visual Studio and create a new solution of type Visual C# > Micro Framework > Console Application and name it whatever you want:
Right-click on the References folder in the Solution Explorer and add:
- Microsoft.Spot.Hardware
- SecretLabs.NETMF.Hardware
- SecretLabs.NETMF.Harware.Netduino (or NetduinoPlus if that’s what you’re using)
- Launch Xamarin Studio and create a new solution of type C# > MicroFramework > MicroFramework Console Application and name it whatever you want:
Double-click on the References folder in the Solution Pad and add:
- Microsoft.Spot.Hardware
- SecretLabs.NETMF.Hardware
- SecretLabs.NETMF.Harware.Netduino
For more information visit: http://developer.wildernesslabs.co/Netduino/Getting_Started/
Add the Application Code
We will load the following code as an example to make sure that everything is in order in terms of configuration.
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.Threading;
using SecretLabs.NETMF.Hardware.Netduino;
namespace NetduinoBlink
{ public class Program
{ public static void Main() { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); int i = 0;
while (true) { led.Write(true); // turn on the LED Thread.Sleep(250); // sleep for 250ms led.Write(false); // turn off the LED Thread.Sleep(250); // sleep for 250ms Debug.Print ("Looping" + i); i++; } } }}
This code does the following things:
- It creates an
OutputPort
. AnOutputPort
allows you to “write” to a pin, e.g. power it on or off.
- Loops forever, writing to the port on, then waiting 250ms, then turning it off.
- Prints to the Debug Window the loop iteration it’s on.
Deploy
Visual Studio for Windows
- Make sure your Netduino is plugged in.
- Double-click on the Properties item in the Solution Explorer, select .NET Micro Framework on the left, and the under Deployment choose USB and in the Devicedrop down, choose your Netduino device.
Visual Studio for Mac
- Make sure your Netduino is plugged in. It should show up in the build bar at the top.
- Hit the “>” button to deploy.
We can see how our board flashes a led:
The connections are very simple: All sensors are connected to the Shield connected to Netduino.
- Water Sensor: Digital Port
- Barometer Sensor: I2C
- UV Sensor: Analog Port
- Temp & Hum Sensor: Analog Port
- Sunlight Sensor: I2C
- Air Qality Sensor: Analog Port
Note: I have formatted the device where it stores the photos of the connections, I will upload them soon. (I must disarm the prototype).Step 5: Code
Finding codes compatible with Netduino is a bit complicated. However, we can find various projects and ideas that will allow us to have a basis for our code.
On this occasion during my search on the internet I have managed to understand a little about its code and programming.
We will use a service in the cloud, in this case Adafruit.io to capture and store the data of our sensors.
We load the following code: Program.CS
*/
using System;
using System.Net;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Net.NetworkInformation;
using SecretLabs.NETMF.Hardware.Netduino;
using smarCrops.NetMF.Sensor;
using smartCrops.IoT.NetMF;
namespace smartCrops.IoT.AdaFruitIO.NetMF.Client
{
public class Program
{
private const string adaFruitIOApiBaseUrl = @"https://IO.adafruit.com/api/v2/";
private const string group = "netduino3";
private const string temperatureFeedKey = "t";
private const string temperatureFeedKey = "te";
private const string uvFeedKey = "uv";
private const string airqualityFeedKey = "aq";
private const string sunlightFeedKey = "s";
private const string humidityFeedKey = "h";
private const string barometerFeedKey = "b";
private const string adaFruitUserName = "YourUserName";
private const string adaFruitIOApiKey = "YourAPIKey";
private static readonly TimeSpan timerDueAfter = new TimeSpan(0, 0, 15);
private static readonly TimeSpan timerPeriod = new TimeSpan(0, 0, 30);
private static OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
private static SiliconLabsSI7005 sensor = new SiliconLabsSI7005();
private static AdaFruitIoClient adaFruitIoClient = new AdaFruitIoClient(adaFruitUserName, adaFruitIOApiKey, adaFruitIOApiBaseUrl);
public static void Main()
{
// Wait for Network address if DHCP
NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
if (networkInterface.IsDhcpEnabled)
{
Debug.Print(" Waiting for DHCP IP address");
while (NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress == IPAddress.Any.ToString())
{
Debug.Print(" .");
led.Write(!led.Read());
Thread.Sleep(250);
}
led.Write(false);
}
// Display network config for debugging
Debug.Print("Network configuration");
Debug.Print(" Network interface type : " + networkInterface.NetworkInterfaceType.ToString());
Debug.Print(" MAC Address : " + BytesToHexString(networkInterface.PhysicalAddress));
Debug.Print(" DHCP enabled : " + networkInterface.IsDhcpEnabled.ToString());
Debug.Print(" Dynamic DNS enabled : " + networkInterface.IsDynamicDnsEnabled.ToString());
Debug.Print(" IP Address : " + networkInterface.IPAddress.ToString());
Debug.Print(" Subnet Mask : " + networkInterface.SubnetMask.ToString());
Debug.Print(" Gateway : " + networkInterface.GatewayAddress.ToString());
foreach (string dnsAddress in networkInterface.DnsAddresses)
{
Debug.Print(" DNS Server : " + dnsAddress.ToString());
}
Timer humidityAndtemperatureUpdates = new Timer(HumidityAndTemperatureTimerProc, null, timerDueAfter, timerPeriod);
Thread.Sleep(Timeout.Infinite);
}
static private void HumidityAndTemperatureTimerProc(object state)
{
led.Write(true);
try
{
double humidity = sensor.Humidity();
Debug.Print(" Humidity " + humidity.ToString("F0") + "%");
adaFruitIoClient.FeedUpdate(group, humidityFeedKey, humidity.ToString("F0"));
}
catch (Exception ex)
{
Debug.Print("Humidifty read+update failed " + ex.Message);
return;
}
try
{
double temperature = sensor.Temperature();
Debug.Print(" Temperature " + temperature.ToString("F1") + "°C");
adaFruitIoClient.FeedUpdate(group, temperatureFeedKey, temperature.ToString("F1"));
}
catch (Exception ex)
{
Debug.Print("Temperature read+update failed " + ex.Message);
return;
}
led.Write(false);
}
private static string BytesToHexString(byte[] bytes)
{
string hexString = string.Empty;
// Create a character array for hexidecimal conversion.
const string hexChars = "0123456789ABCDEF";
// Loop through the bytes.
for (byte b = 0; b < bytes.Length; b++) { if (b > 0)
hexString += "-";
// Grab the top 4 bits and append the hex equivalent to the return string.
hexString += hexChars[bytes[b] >> 4];
// Mask off the upper 4 bits to get the rest of it.
hexString += hexChars[bytes[b] & 0x0F];
}
return hexString;
}
}
}
Now we will configure AdaFruit: Client.CS
*/
using System;
using System.IO;
using System.Net;
using System.Text;
using Microsoft.SPOT;
namespace smartcrops.IoT.NetMF
{
public class AdaFruitIoClient
{
private const string apiBaseUrlDefault = @"http://IO.adafruit.com/api/smartcrops/";
private string apiBaseUrl = "";
private string userName = "";
private string apiKey = "";
private int httpRequestTimeoutmSec;
private int httpRequestReadWriteTimeoutmSec;
public AdaFruitIoClient(string userName, string apiKey, string apiBaseUrl = apiBaseUrlDefault, int httpRequestTimeoutmSec = 2500, int httpRequestReadWriteTimeoutmSec = 5000)
{
this.apiBaseUrl = apiBaseUrl;
this.userName = userName;
this.apiKey = apiKey;
this.httpRequestReadWriteTimeoutmSec = httpRequestReadWriteTimeoutmSec;
this.httpRequestTimeoutmSec = httpRequestTimeoutmSec;
}
public void FeedUpdate(string group, string feedKey, string value)
{
string feedUrl;
if (group.Trim() == string.Empty)
{
feedUrl = apiBaseUrl + userName + @"/feeds/" + feedKey + @"/data";
}
else
{
feedUrl = apiBaseUrl + userName + @"/feeds/" + group.Trim() + "." + feedKey + @"/data";
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(feedUrl);
{
string payload = @"{""value"": """ + value + @"""}";
byte[] buffer = Encoding.UTF8.GetBytes(payload);
DateTime httpRequestedStartedAtUtc = DateTime.UtcNow;
request.Method = "POST";
request.ContentLength = buffer.Length;
request.ContentType = @"application/json";
request.Headers.Add("X-AIO-Key", apiKey);
request.KeepAlive = false;
request.Timeout = this.httpRequestTimeoutmSec;
request.ReadWriteTimeout = this.httpRequestReadWriteTimeoutmSec;
using (Stream stream = request.GetRequestStream())
{
stream.Write(buffer, 0, buffer.Length);
}
using (var response = (HttpWebResponse)request.GetResponse())
{
Debug.Print(" Status: " + response.StatusCode + " : " + response.StatusDescription);
}
TimeSpan duration = DateTime.UtcNow - httpRequestedStartedAtUtc;
Debug.Print(" Duration: " + duration.ToString());
}
}
}
}
IMPORTANT: I still work in the code, therefore I had some problems loading it on the board. I hope to solve each and every one of them to load a more efficient code without errors.
Step 6: Data VisualizationTo visualize our data taken by our sensors, I have been working on an application through APP Inventor. Likewise, a OLED connection screen Grove has been integrated at the last moment.
For those who wish to download the App, as well as its configuration file please enter the following link:
https://drive.google.com/drive/folders/1RprNyiz3JKEm1syBZsszNXdpbFVPbT_E?usp=sharing
Step 7: ConclusionsIn conclusion we have managed to design and build an agricultural monitoring system to diagnose, study and prevent possible complications and catastrophes in the field of Agriculture. All this is possible thanks to the plate of Wilderness Labs Netduino 3 WiFi.
Our system takes samples from different sensors such as:
- Internal temperature of the crop.
- Temperature and Humidity of the environment.
- Levels of sunlight.
- UV levels.
- Wind level and quality.
- Presence of chemical and gaseous compounds in the air.
- Quality of the ecosystem
- Water level of the crops.
All these sensors will be connected in a strategic way representing a sector of the harvest, thus creating different areas to facilitate their study and observation.
For the information to reach our farmers and interested parties, it is necessary to use Adafruit to send the data to a station or observation base where a person will receive and visualize all the information and thus make decisions about the situation..
The person in charge of inspecting the received data can give orders to automatically activate the irrigation valves electronically or to execute another task.
The system that we have just created, connected and working hand in hand with our cultivation system, will allow us to automate the field and meet our objectives.
The biggest advantages of this idea:
Decreases pollution to 0% in all aspects.
Automate field work
Provide the farmer with information about his work in the palm of his hand.
Avoid the loss of crops.
It informs us in advance and lives the problems of our farms.
It is 100% powered with renewable energy.
It provides valuable information and information on many aspects of each location.
Improve the quality of work of our farmers and farmers.
The development of ideas like these will help us in the following fields.
In education:
Make young people aware of the alternatives and new technologies that are currently available.
In the economy:
It is a system that requires little investment but in the long term presents proven profits.
It avoids, to a large extent, the investment for disasters caused by greenhouses or pests or droughts.
It will greatly reduce capital investment in the energy field, since, compared to other systems, it is less expensive.
In daily life:
It improves the quality of life of people.
It will generate an ecological environment.
It improves the living conditions of millions of people.
My reason for this idea: In my country the new government is implementing and financing innovative projects and ideas. As a child I have always wanted to contribute and change the way society sees technology. Thanks to Wilderness Labs I can show the great potential and the advantages that the implementation of the technology brings to the field.
I remember how, being a volunteer in my community, we had to see the peasants and inhabitants of the rural areas on various occasions impacted and terrible by the amount of losses that the natural disasters that could have been diagnosed had left them.
I hope to be able to take this project to great indices and to be able to say with pride: "I have contributed in the agricultural development of my country".
Due to the short time, since only a week ago I received the Netduino badge, this project is in improvements and changes. I hope I can modify the code a little, to get more out of Netduino.
After the contest, I will update the project applying more improvements.
Many thanks to Wilderness Labs for allowing me and all the users of this great platform to participate. Thank you for carrying out these activities that encourage young people and teenagers to create and invent.
Thanks to you, I am raising the interest of the youth and children of my community.
Comments