Click here to Skip to main content
15,867,686 members
Articles / Internet of Things

Intel Edison Based Plant Monitoring and Watering System for Agro-IoT with Matlab Driven Real Time Data Analytics over ThingSpeak Channel

,
Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
6 Aug 2016CPOL20 min read 24.6K   200   7   6
Agricultural field monitoring and control is also possible using IoT sensor network
In this article, you will learn about Intel Edison Based Plant Monitoring & Watering System for Agro-IoT with Matlab Driven Real Time Data Analytics over the ThingSpeak Channel.

Objective

You might have already read, heard, seen or watched some forms of plant monitoring system, either embedded based or IoT based. Let's be honest, we all love plants and any hacker one time or the other thinks of building a system for taking care of her plant health and watching it. How then is this article different or unique from tons of other similar projects? Well, if you have observed the most Agro-IoT projects, the objects are similar:

  • Collecting soil and environmental parameters
  • Data visualization
  • Remote or automatic triggering of irrigation/watering system

Many platforms like Windows Azure, IBM Watson offer machine learning on gathered sensor data. But, they are not free and you don't find too many use case examples where a full stack Agro-IoT is demonstrated. So, we wanted to build a poor man's Agro-IoT stack with a fully demonstrable prototype. In a developing country like India, if we expect a farmer to spend on his IT budget for cloud, we may be asking for an improbable scenario. Even hardware costs would be an overhead for them when they suffer extreme challenges starting from getting the right seed and pesticides in time to right till harvesting and selling. Adding a recurring cost of data monitoring would not be a feasible solution. On the other hand, with increasing technologies in hand, right adaptation can lead to better crops and throughput. In this project, we have tried to build a feasible solution for usual Agro monitoring and control along with integrating an efficient data analytics scheme based on clustering techniques. We use ThingSpeak's free framework for the same. Collected data is analyzed at an end node using Matlab.

Introduction

The overall methodology of the work can be summarized into the following modules.

Physical Parameter Monitoring

We have used light sensor (LDR), temperature sensor (seed studio temperature sensor), rainfall sensor (resistor based potentiometer), soil moisture sensor (……), and we have added the sensor with the analog ports of Aurdino compatible extension board with Intel Edison device. These analog ports are of 10bit precisions, therefore, we get A/D values for the sensors within the range of 0, 1, 2, and 3. These values are further converted the precision parameter value by using the formulae given below.

Data Display

The observed data is displayed on a color LCD for local observations of the parameters.

Data Integration to the Cloud

We use thingspeak IoT gateway to mitigate this data using http sockets, encoded with API keys being offered by the thingspeak. Once the data is mitigated into thingspeak, it can be observed in real time from anywhere in the world.

Alert Generation

We have defined threshold for temperature as 40’c, light intensity as more than 70c, and soil moisture as less than “0”, as in unsuitable conditions for the plants, in case such a condition when observed, the farmer is notified through a matt channel.

  1. Temperature=1/ (Math.log (resistance/10000.0)/B+1/298.15)-273.15
  2. lp= lightVal*100 // Light intensity in percentage
  3. var soilVal=1023-soilSensor.read()
    soilVal=soilVal*100/1023 // Soil moisture in %
  4. var rainfall=1023-rainSensor.read()
    rainfall = rainfall*100/1023 // Rainfall in % , though in mm would have been a better metric

Irrigation Control

We have used a 230 volt pump through a relay and we have added it with the data port of Intel Edison board. The irrigation system is connected with the farmers using MQTT protocol which is a high queue guaranteed, low latency communication protocol for Iota farmer can generate particular commands for switching on and turning off of the irrigation system. Once the respective command is asynchronously obtained by Intel Edison, it triggers the relay on and off based on the command.

Data Analytics

We have added a data mining technique based on MATLAB by means of which we can not only observe the value of the environment but we can also predict their future values. Therefore, farmers can be prepared with the future conditions, this is been done with the matlab analysis where the code is deployed directly on the cloud.

Scope and Challenges

Our major goal is to offer an architecture which should help in improving the productivity of the crops, specifically for the Indian farmers. However, this can be adapted to the wide range of applications which includes mining, the parameter monitoring in a mining field is a significant important state. As over the years, lots of lives have been cost due to improper knowledge of the environmental data in the mining filed. The work can also be adopted for other wide range of monitoring, for example, biological reactions in specific soil conditions, it can be observed in bio gas projects, the proposed architecture can also be adopted for roof garden which is popular in cities, small home garden, home monitoring and so on.

Even though IoT architecture is growing and is estimated to be 20 billion at the end of 2020, and several IoT devices which have come up, which have reduced the price of such devices, these devices are still quite costly. At the same time, IoT architecture requires a seamless internet connectivity which is still different to get in many parts of India. Therefore, the dependency of the proposed architecture on IoT gateway, the internet connectivity, available bandwidth and the internet access tariff is the major drawback of the work, alongside the current cost level which sometimes is different for the smaller farmers to bear.

Hardware and Software Requirement

Hardware Requirements

  • Intel Edison
  • Aurdino Compatible Breakout board for Intel Edison
  • Sensors: Temperature, LDR light sensor, Moisture Sensor and Rainfall Sensor
  • Actuators: Relay, Water pump
  • 9v External power supply/ Mobile Power Bank
  • Internet Connectivity (Wife), 3G
  • Intel processor powered PC (minimum 2 GB RAM, iCore3 and above processor)
  • Android Mobile (Android 4.0 and above)
  • Seed Studio Groove Kit

Software Requirements

  • Linux yocto Operating System for Edison
  • IDE: Intel XDK IoT edition
  • Language: JavaScript (Node.js)
  • Windows 7 and Above Operating System (preferably 64 bit)
  • PuTTY
  • WinSCP
  • IoT Gateway: ThingSpeak, IFTTT
  • IoT protocols: MQTT, HTTP

System Design

Block Diagram/System Architecture

Image 1

Block Diagram

The sensed data is mitigated into the thingspeak through an IoT gateway, thingspeak gives a real time visualization. We are using a lightweight communication protocol MQTT, by using which we are having control over the irrigation in the form of controlling the relay.

Data Flow Diagram

Since we are taking input as sensing data from the sensors, which is dissipated in the IoT, and a real time visualization be done at the thingspeak.

Image 2

DFD 0th level

Image 3

DFD 1st level

Sequence Diagram

Image 4

Sequence Diagram

Use Case Diagram

Image 5

Use Case Diagram

Component Diagram/ Context Diagram

Component diagram for the system is shown below, where the Intel Edison board consists of sensing service, a decision and a record. Decision is about to have the control over the irrigation through a relay.

Image 6

Component Diagram

Circuit Diagram

Image 7

Circuit diagram

Note rainfall sensor and plant moisture sensor or Hygrometers are not available with the Grove kit. You need to buy them separately. In case you don't live in a country where Grove components are available, then you can simply go for Arduino compatible Hygrometer and Rainfall sensor and hack that to work with Edison.

You can use this video to learn how to hack incompatible components with Intel Edison.

Coding

Let's first have a look at our complete Node.js code and then, we can look at each module individually.

JavaScript
var mraa=require('mraa');
var sys = require('sys')

var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }

///////// Make connection seeing these pins or change acc to your connection///////
var tSensor=new mraa.Aio(0);
var ldrSensor=new mraa.Aio(1);
var rainSensor=new mraa.Aio(3);
var soilSensor=new mraa.Aio(2);
var relay=new mraa.Gpio(4);
////////////////////////////////////////
relay.dir(mraa.DIR_OUT);
var LCD = require('jsupm_i2clcd');
var myLCD = new LCD.Jhd1313m1(6, 0x3E, 0x62);
var B=3975; 
//////////////// Plant Watering////////
var mqtt    = require('mqtt');
var client  = mqtt.connect('mqtt://iot.eclipse.org');
client.subscribe('rupam/Agro/#')
client.handleMessage=function(packet,cb)
{
var payload = packet.payload.toString()
console.log(payload.length);
payload = payload.replace(/(\r\n|\n|\r)/gm,"");
//console.log(payload.length)
console.log(payload)
try{
//payload=".9 "
var state=Number(payload.trim());
if(state==1)
{
relay.write(1);
setTimeout(null,5000);
relay.write(0);
}
else
{
}

}catch(ex)
{
console.log(ex.message);
}
cb()
}
/////////////////////////////////////

Loop();
function Loop()
{
var a=tSensor.read();

var resistance=(1023.0-a)*10000.0/a;    //get the resistance of the sensor;
var temperature=1/(Math.log
(resistance/10000.0)/B+1/298.15)-273.15;//convert to temperature via datashee
temperature=Math.floor(temperature * 100) / 100;
//setTimeout(Loop,1000);
console.log("temparature="+temperature);

var lightVal=ldrSensor.read();
var lp=lightVal*100/1024;
lp=Math.floor(lp * 100) / 100;
console.log("Light %"+lp);

var soilVal=1023-soilSensor.read();
soilVal=soilVal*100/1023;
soilVal=Math.floor(soilVal * 100) / 100;
console.log("Moisture="+soilVal+"%");

var rainfall=1023-rainSensor.read();
rainfall=rainfall*100/1023;
rainfall=Math.floor(rainfall * 100) / 100;
console.log("Rainfall="+rainfall+"%");

myLCD.clear();
myLCD.setColor(255,0,0);
myLCD.setCursor(0,0);
myLCD.write(""+temperature);
myLCD.setCursor(0,5);
myLCD.write("'C");
myLCD.setCursor(0,8);
myLCD.write("L="+lp);
myLCD.setCursor(1,0);
myLCD.write("R="+rainfall+"%");
myLCD.setCursor(1,9);
myLCD.write("M="+soilVal+"%");
console.log("\n----------------------\n");
///////////// Update ThingSpeak/////////////
s="curl \"http://api.thingspeak.com/update?
api_key=NH0EDP5F7TQSAH90&field1="+temperature+"&field2="+lp+
"&field3="+ soilVal+lp+"&field4="+ rainfall+ "\"";
exec(s);
//////////////////////////////////////////
setTimeout(Loop,15000);
}

As we use the header file <stdio.h> to include libraries in C, here in JavaScript, we use require function to use the modules.

JavaScript
var mraa=require('mraa');

var sys = require('sys')

There are two types of libraries in node js, which are user module and the code module. JavaScript also supports some of the modules so we don’t have to include Jayson, math libraries. Any user defined libraries can install with JavaScript using npm command, so node js has got the repository where we can push our modules and user can download simply by npm install command.

JavaScript
var exec = require('child_process').exec;

function puts(error, stdout, stderr) { sys.puts(stdout) }

Intel Edison uses library called mraa for accessing the pins, the same ‘mraa’ is also been available for Raspberry pi and other devices .The main objective is to push the data into ThingSpeak. When we try to push the data into ThingSpeak, we need to use ‘http’ methods, as get and post methods. The good thing is that from Unix, we can open any website from the command prompt, that is by giving a curl command. curl is a command line url, if any user gives curl google.com, the whole thing is going to be passed on the command part of the website and the page will be displayed to the user. We use curl command to call ThingSpeak APIs and is a Unix system command which will be using a library called sys, which gives access for all Unix system commands. The sys will be executed as a child process because node js runs as a single thread. Puts is a function which that is going to put all standard errors to the command prompt.

We have defined four sensors, which are connected to the analog input. Soil moisture sensor, rainfall sensor, light sensor and the temperature sensors are been connected to the analog 0, 1, 2 and 3 input pins respectively.There is also a controlling of water through relay which is connected to the port number 4.

JavaScript
var tSensor=new mraa.Aio(3);

var ldrSensor=new mraa.Aio(2);

var rainSensor=new mraa.Aio(1);

var soilSensor=new mraa.Aio(0);

var relay=new mraa.Gpio(4);

When we are using Gpio, we need to specify whether it is input or output. Every general purpose digital pin can take the data and can be used for controlling, simultaneously it can be used to read the digital data. But Gpio can be done at the same time, either it can be input or output.

JavaScript
var LCD = require('jsupm_i2clcd');

var myLCD = new LCD.Jhd1313m1(6, 0x3E, 0x62);

var B=3975;

i2c library stands for integrated circuit to integrated circuit communication. i2c is a protocol used to communicate between two chips through serial communication. In LCD, number 6 is the protocol address for i2c, 0x3E is the hardware address of the LCD, 0x62 is the hardware address of the i2c port. While giving this command, we can initialize the LCD.

JavaScript
var MQTT = require('MQTT');
var client = MQTT.connect('MQTT://IoT.eclipse.org');
client.subscribe('rupam/Agro/#')
client.handleMessage=function(packet,cb)
{
var payload = packet.payload.toString()
console.log(payload.length);
payload = payload.replace(/(\r\n|\n|\r)/gm,"");
console.log(payload)
}); 
Loop();

We use MQTT protocol, which is not a part of code library, but through which application we can get connected with the ‘ IoT.eclipse.org’ and will be subscribing to the channel rupam/Agro. Whenever a message is arriving at the MQTT, this following function will be called.This is an event handling so whenever any message is arriving at the MQTT, one module can communicate with other using something called packet within the node js. Packets will be having two fields, namely topic and payload field. Node js is global, so from one module to another module, data is communicated through packets not through variables. The good thing is that it uses packets. Models can be either located locally or remotely. Among the topic and payload fields, we are using the payload. Since we are subscribing to the particular channel, so when we push the data on the channel we are going to receive a packet, so user doesn’t have to check the topic. In MQTT, user needs to give some spaces, tag lines will be replaced in the characters.

Convert the payload into number if it is greater than 0, in that situation, we keeping the relay as 1, else the relay will be off. Similarly when the state is 1, the relay will be on, in this code, we have set an relay automatic time to 5000ms, so even in the case when the user forget to turn off the switch, after 5 seconds, the relay will be off.

Node js is asynchronous. Unlike other programming languages when we are calling a function, it would wait for a function to return a result. But this is not the case with node js, node js will go the function only when there is a message. We are recursively calling ‘cb’. In other programming languages, if we call the same function recursively, then function will get into an infinite loop, which will result in stack overflow. But in node js, when we call the same function recursively and if there is a packet in the cb, that will come out back.

i2c library stands for integrated circuit to integrated circuit communication. i2c is a protocol used to communicate between two chips through serial communication. In LCD, number 6 is the protocol address for i2c, 0x3E is the hardware address of the LCD, 0x62 is the hardware address of the i2c port. While giving this command, we can initialize the LCD.

When we are using Gpio, we need to specify whether it is input or output. Every general purpose digital pin can take the data and can be used for controlling, simultaneously, it can be used to read the digital data. But Gpio can be done at the same time, either it can be input or output.

Cb is the name of the message handling method or call back method, whenever there is a MQTT message, it will read it, prompt it and will look for another MQTT message. Since we are using node js which runs completely asynchronous even though the function is called recursively, it will not get into an infinite loop. It will come back and will enter into a function called loop, where we are reading the temperature value. We use math.floor because double will be too long so to keep the result in two decimal points.

Cb is the name of the message handling method or call back method, whenever there is a MQTT message, it will read it, prompt it and will look for another MQTT message. Since we are using node js which runs completely asynchronous even though the function is called recursively, it will not get into an infinite loop. It will come back and will enter into a function called loop, where we are reading the temperature value. We use math.floor because double will be too long so to keep the result in two decimal points.

Detailed Explanation of Code

1. Package Dependencies

In Unix, we use curl system command to call any website, so that we can put whatever data we acquire by the sensors to the thing speak channel. Because JavaScript cannot have access to Unix system command, we can access the Unix commands by using the sys library which gives node js access to the internal unix API calls.

JavaScript
var exec = require('child_process').exec;

Because node js is an application program and unix is the part that will be calling entirely kernel level call, we cannot call the kernel from the application program so, we are using another library called child_process to call a new process for accessing kernel .

JavaScript
function puts(error, stdout, stderr) { sys.puts(stdout) }

In the above line of code, the function puts will map the console of JavaScript to that of Unix. And here stdout, stderr are the standard output and errors in the output window, ‘sys.puts(stdout)’ means whatever data we get that are going to pass to the Unix system.

2. Variables

JavaScript
var tSensor=new mraa.Aio(3); 
var ldrSensor=new mraa.Aio(2); 
var rainSensor=new mraa.Aio(1); 
var soilSensor=new mraa.Aio(0);

In the above code, we are declaring the pins with which different sensors are connected, here temperature, ldr, rainfall and soil sensors are connected respectively to Aio(3), Aio(2), Aio(1) and Aio(0) which are four analog ports.

JavaScript
var relay=new mraa.Gpio(4);

Because we are also controlling the watering of the plant so, relay is connected with Gpio(4) which is digital pin number(4).

JavaScript
relay.dir(mraa.DIR_OUT);

Because Gpio is a bidirectional, i.e., we can read and output the data from the digital we need to explicitly specify for what purpose we are using the digital port which is connected to relay, so that microprocessor can send command to the particular ping.

JavaScript
var LCD = require('jsupm_i2clcd');

In the above code, i2c means integrated circuit communication which is a small protocol by means of which one electronic chip can communicate with another, so for accessing that, we are using i2clcd library which is called by the protocol i2c.

JavaScript
var myLCD = new LCD.Jhd1313m1(6, 0x3E, 0x62);

The above code shows that LCD in Intel Edison i2c port is manually connected with 0x3E which is hardware level address of i2c pin and this address will automatically search for the port number and 0x62 is the interrupt number.

3. Mqtt Integration for Remote Control of Watering

JavaScript
//////////////// Plant Watering//////// 
var mqtt = require('mqtt');

In the above code, we are adding the mqtt model to get connected to the IoT hub with the help of mqtt protocol.

JavaScript
var client = mqtt.connect('mqtt://iot.eclipse.org');

Here iot.eclipse.org is a free Mqtt broker by using which we can subscribe to a particular channel so that we can send command from the mobile to control the watering service.

JavaScript
client.subscribe('rupam/Agro/#')

Here, we are subscribing to channel rupam/Agro so that whenever there is a message, it will send to the client asynchronously.

JavaScript
client.handleMessage=function(packet,cb)
{ 
var payload = packet.payload.toString() 
console.log(payload.length); 
payload = payload.replace(/(\r\n|\n|\r)/gm,""); //console.log(payload.length) 
                                                //console.log(payload)

In the above code, we are creating an event handler by name client.handleMessage and whenever there is a data in the channel, we are calling the function cb because in node js, every function can communicate with other function through packet and whenever we receive a message from the mqtt channel, we receive it as a packet. Packet has two parts, topic and payload. We are going to take payload and replace the garbage characters from the data.

JavaScript
try{ 
//payload=".9 " 
var state=Number(payload.trim()); 
if(state==1) 
{ 
relay.write(1); 
setTimeout(null,5000); 
relay.write(0); 
} else 
{ 
} 
}catch(ex) 
{ 
console.log(ex.message); 
} cb() 
}

In the above code, we are converting the payload string into the number and calling the trim method to remove the \0 from the command received by the mqtt protocol, so that there will not be any garbage characters remaining in the command and checking if data is 1, we are going to keep the relay ON after 5 seconds, the relay will be closed automatically.

4. Sensing

JavaScript
Loop(); 
function Loop() 
{ 
var a=tSensor.read(); 
var resistance=(1023.0-a)*10000.0/a; 
//get the resistance of the sensor; 
var temperature=1/(Math.log(resistance/10000.0)/B+1/298.15)-273.15;
//convert to temperature via datasheet 
temperature=Math.floor(temperature * 100) / 100; 
//setTimeout(Loop,1000); 
console.log("temparature="+temperature);

In the above code snippet, Loop() is a function which is called to read the data from the sensors, and we are taking the data from the sensor which is in the form of seed studio temperature value and converting that in degree centigrade by using the formula shown above.

JavaScript
var lightVal=ldrSensor.read(); 
var lp=lightVal*100/1024; 
lp=Math.floor(lp * 100) / 100; 
console.log("Light %"+lp);

In the above code, we are reading the data from the ldr sensor and converting that in the form of a percentage of the light intensity by using the formula1 above and the calculated percentage can have a huge decimal number that we cannot display onto the lcd so, to restrict the number to two places of decimal, we are using formula2 above.

JavaScript
var soilVal=1023-soilSensor.read(); 
soilVal=soilVal*100/1023; 
soilVal=Math.floor(soilVal * 100) / 100; 
console.log("Moisture="+soilVal+"%"); 

In the code above, we are reading the value from the soil sensor which is actually inverse to the moisture of the soil so in order to calculate moisture we are subtracting it from the maximum soil value, and calculating the percentage of the moisture using formulae and displaying it as a 2 digit decimal number.

JavaScript
var rainfall=1023-rainSensor.read(); 
rainfall=rainfall*100/1023; 
rainfall=Math.floor(rainfall * 100) / 100; 
console.log("Rainfall="+rainfall+"%");

Here, in the same way as explained for the soil sensor for moisture calculation, we are reading the data from the rainfall sensor and calculating the percentage of the rainfall and displaying it onto LCD.

JavaScript
myLCD.clear();

Clear the lcd by removing past data.

JavaScript
myLCD.setColor(255,0,0);

Setting a red color for LCD display because it has RGB color to display.

JavaScript
myLCD.setCursor(0,0);

Setting cursor at the 0th line and 0th character.

JavaScript
myLCD.write(""+temperature); 
myLCD.setCursor(0,5); 
myLCD.write("'C");

Displaying the temperature from 0th line to the 5th character with ‘C included on lcd.

JavaScript
myLCD.setCursor(0,8);
 myLCD.write("L="+lp);

Displaying light percentage in the 0th line from 8th character after temperature value.

JavaScript
myLCD.setCursor(1,0); 
myLCD.write("R="+rainfall+"%"); 
myLCD.setCursor(1,9); 
myLCD.write("M="+soilVal+"%"); 
console.log("\n----------------------\n");

Displaying rainfall and the moisture value on lcd, in the 1st line from 0th character rainfall rate is displayed an in the same line from the 9th character moisture value in the form of percentage will be displayed.

5. Update Data onto thingspeak Channel

JavaScript
///////////// Update ThingSpeak///////////// 
s="curl \"http://api.thingspeak.com/update?api_key=NH0EDP5F7TQSAH90&field1="+
   temperature+"&field2="+lp+"&field3="+ 
   soilVal+lp+"&field4="+ rainfall+ "\""; 
exec(s); 
setTimeout(Loop,15000); 
}

The above code shows using the API curl command to call the thingspeak channel to update the temperature, light, moisture and rainfall data and execute it, and we are setting the 15 seconds delay for the thingspeak so that after every 15 seconds, we can keep on updating thingspeak channel.

Results

The following figure shows the plant monitoring system being deployed att real time with a power bank. With 5000mAH power bank, the system can send data to ThingSpeak channel continuously for 17 hours @ 4 http requests per minute.

Image 8

Image 9

Fig. Plant Monitoring Systemin Action

Following ThingSpeak channel graph shows simultaneous data mitigation to four fields of the channel. These graphs can be observed in real time by browsing the channel link in PC or mobile.

Image 10

Image 11

Figure: Plant monitoring system with watering arrangement

Testing

We check the variations in the sensors by taking a candle stick near temperature sensor, shadowing the LDR sensor, pouring water to the plant pot and keeping steam water pot near the arrangement to observe variations in temperature, light intensity, rainfall and humidity respectively.

Image 12

Image 13

Temperature Sensor variation

Image 14

Light Intensity Variation

Image 15

Rainfall variation test

Analysis

ThingSpeak provides an easy integration to Matlab scripts right at the cloud. However, more advanced Matlab toolboxes are not yet being supported by ThingSpeak. So, we run a local script to first fetch the values from our ThingSpeak channel and then performing a predictive and cluster analysis. We assume a very simple formula for the prediction. The predicted value = Previous Value + Standard deviation of the past.

Though this is not the most elegant way of predicting a series, and we must always go with more robust methods like feedback kalman filter, the implementation exposes the strategy of predictive analysis. You can always built your own algorithm on the top of it.

We use K-Means clustering separately on all the four parameters to obtain the most prominent trends in the data.

We use a ThingSpeak Matlab toolbox called ThingSpeakFetch.

We perform three primary analysis on the data:

  • Predictive analysis
  • Cluster Analysis
  • Statistical Analysis
JavaScript
clear all;
clc;
close all;
%% Fetching the data
[d t]=thingSpeakFetch(101184,'NumPoints',130);
dtemp=[];

%% Temperature Analysis
for(i=1:size(d,1))
    if(~isnan(d(i,1)))
        dtemp=[dtemp;d(i,1)];
    end
end

%% Statistical Analysis
AvTemp=mean(dtemp)
TempStd=std(dtemp)
MaxTemp=max(dtemp)
MinTemp=min(dtemp)

nextVal=dtemp(length(dtemp))+TempStd;
dpredict=[dtemp;nextVal];
plot(dpredict,'g-');
hold on;
plot(dtemp,'r-');

hold on;
legend('Actual Graph','Prediction');

%% Clustering
[IDX,C]=kmeans(dtemp,2);

for(i=1:length(dtemp))
    if(IDX(i)==1)
        plot(i,dtemp(i),'g*');
        hold on;
    else
        plot(i,dtemp(i),'b+');
        hold on;
    end
end
title('Temperature Analysis');
%% Light Intensity Analysis
figure
title('Light Intensity Analysis');
dLight=[];
for(i=1:size(d,2))
    if(~isnan(d(i,2)))
        dLight=[dLight;d(i,2)];
    end
end

%% Statistical Analysis
AvLight=mean(dLight)
LightStd=std(dLight)
MaxLight=max(dLight)
MinLight=min(dLight)

nextVal=dLight(length(dLight))+LightStd;
dpredict=[dLight;nextVal];
plot(dpredict,'g-');
hold on;
plot(dLight,'r-');

hold on;
legend('Actual Graph','Prediction');

%% Humidity  Analysis(Soil Moisture)
figure
title('Humidity Analysis');

dHumidity=[];
for(i=1:size(d,3))
    if(~isnan(d(i,3)))
        dHumidity=[dHumidity;d(i,3)];
    end
end

%% Statistical Analysis
AvHumidity=mean(dHumidity)
HumidityStd=std(dHumidity)
MaxHumidity=max(dHumidity)
MinHumidity=min(dHumidity)

nextVal=dHumidity(length(dHumidity))+HumidityStd;
dpredict=[dHumidity;nextVal];
plot(dpredict,'g-');
hold on;
plot(dHumidity,'r-');

hold on;
legend('Actual Graph','Prediction');

%% Clustering
[IDX,C]=kmeans(dHumidity,2);

for(i=1:length(dHumidity))
    if(IDX(i)==1)
        plot(i,dHumidity(i),'g*');
        hold on;
    else
        plot(i,dHumidity(i),'b+');
        hold on;
    end
end

%% Rainfall  Analysis
figure
title('Rainfall Analysis');

dRainfall=[];
for(i=1:size(d,4))
    if(~isnan(d(i,4)))
        dRainfall=[dRainfall;d(i,4)];
    end
end

%% Statistical Analysis
AvRainfall=mean(dRainfall)
RainfallStd=std(dRainfall)
MaxRainfall=max(dRainfall)
MinRainfall=min(dRainfall)

nextVal=dRainfall(length(dRainfall))+RainfallStd;
dpredict=[dRainfall;nextVal];
plot(dpredict,'g-');
hold on;
plot(dRainfall,'r-');

hold on;
legend('Actual Graph','Prediction');

%% Clustering
[IDX,C]=kmeans(dRainfall,2);

for(i=1:length(dRainfall))
    if(IDX(i)==1)
        plot(i,dRainfall(i),'g*');
        hold on;
    else
        plot(i,dRainfall(i),'b+');
        hold on;
    end
end

Image 16

Matlab Analysis of ThingSpeak channel

Matlab command prompt shows the statistical values (mean and standard deviation) of temperature data. You can't see much difference between actual and predicted series because predicted series follows the actual series. The cluster analysis divides the points into lower and higher values which are represented by blue + and red *. Based on this, one can take decisions about aggregated environmental status and can set his threshold for watering accordingly. This can even lead to better requirement analysis for pesticides and fertilizers.

Conclusion

Improvement of the crop productivity is a major challenge in the countries like India, the technological improvement is a mandatory work to improve the crop productivity to support and sustain the need for ever green population of our country. In the past, several sensor driven networks have been proposed to successfully monitor the large agriculture field. However, most of the technology does not offer on the data mining technique and predictive analysis, which limits the data usage of accurate state of the field and crop. We propose a novel technology by means of which gathered data from physical sensing devices is mitigated in the cloud, where a machine learning technique could in real time produce not only the alerts corresponding to the current state of the environment and the crop but at the same time can offer predictive analysis of the future state of environment as well as crops.

The IoT based architecture also offers real time realization and analysis of data which can be used across the globe in conjunction with the parameter been monitored through other parts of the world to understand the abnormal behavior of the similar kind of the crop. Our result shows that the proposed system has a very optimal latency for controlling the system as well as high packet delivery rates and accuracy for mitigating the data. The system can further been improved by incorporating new self learning techniques which could be deployed in the cloud to understand the behavior of the sensing data and can take autonomous decisions.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Integrated Ideas
India India
gasshopper.iics is a group of like minded programmers and learners in codeproject. The basic objective is to keep in touch and be notified while a member contributes an article, to check out with technology and share what we know. We are the "students" of codeproject.

This group is managed by Rupam Das, an active author here. Other Notable members include Ranjan who extends his helping hands to invaluable number of authors in their articles and writes some great articles himself.

Rupam Das is mentor of Grasshopper Network,founder and CEO of Integrated Ideas Consultancy Services, a research consultancy firm in India. He has been part of projects in several technologies including Matlab, C#, Android, OpenCV, Drupal, Omnet++, legacy C, vb, gcc, NS-2, Arduino, Raspberry-PI. Off late he has made peace with the fact that he loves C# more than anything else but is still struck in legacy style of coding.
Rupam loves algorithm and prefers Image processing, Artificial Intelligence and Bio-medical Engineering over other technologies.

He is frustrated with his poor writing and "grammer" skills but happy that coding polishes these frustrations.
This is a Organisation

115 members

Written By
Software Developer Integrated Ideas
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionimages (again) Pin
Nelek5-Aug-16 4:11
protectorNelek5-Aug-16 4:11 
AnswerRe: images (again) Pin
Moumita Das5-Aug-16 4:17
Moumita Das5-Aug-16 4:17 
GeneralRe: images (again) Pin
Vincent Maverick Durano5-Aug-16 4:21
professionalVincent Maverick Durano5-Aug-16 4:21 
GeneralRe: images (again) Pin
Nelek5-Aug-16 4:24
protectorNelek5-Aug-16 4:24 
GeneralRe: images (again) Pin
Grasshopper.iics5-Aug-16 4:49
Grasshopper.iics5-Aug-16 4:49 
GeneralRe: images (again) Pin
Nelek5-Aug-16 10:02
protectorNelek5-Aug-16 10:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.