Plant Disease Detection Robot

Agricultural productivity is something on which economy highly depends and that’s why disease detection in plants play an important role. If proper care is not taken here, then it causes serious effects on plants due to which productivity can be affected.

The proposed solution includes a robot with MATLAB image processing algorithm that can detect the abnormalities in the leaf by capturing an image.

IMPLENTATION TOOLS:-

Hardware

 Arduino Uno

 Camera Module

 Robot Chasis

 Motor and motor driver module

 Wifi module

Software

 Matlab

 Autodesk tinker cad

 Arduino IDE

· Matlab support package installer

· Serial Port Reader (To analyze Output Image)

BLOCK DIAGRAM

Block diagram of the Robotic system

HARDWARE:

  1. ARDUINO UNO-

1.Arduino UNO:-

The Arduino Uno is a microcontroller board based on the ATmega328. It has 20 digital input/output pins (of which 6 can be used as PWM outputs and 6 can be used as analog inputs), a 16 MHz resonator, a USB connection, a power jack, an in-circuit system programming (ICSP) header, and a reset button.

ARDUINO UNO

The Arduino Uno is an open-source microcontroller board based on the Microchip ATmega328P microcontroller and developed by Arduino.cc. The board is equipped with sets of digital and analog input/output (I/O) pins that may be interfaced to various expansion boards (shields) and other circuits. The board has 14 digital I/O pins (six capable of PWM output), 6 analog I/O pins, and is programmable with the Arduino IDE (Integrated Development Environment), via a type B USB cable. It can be powered by the USB cable or by an external 9-volt battery, though it accepts voltages between 7 and 20 volts. In our project Arduino is programmed through matlab .For this, Arduino support package is installed so that Arduino can communicate with matlab through Bluetooth, Wi-Fi or directly by USB cable.

2.Camera Module:-

The OV7670 Camera Module is a small image sensor with low operating voltage, providing all functions of a single chip of VGA camera and image processor. Through SCCB bus control, the sensor can output the whole frame, sampling, and various resolution 8 bits of data. The product VGA image can reach up to a maximum of 30 frames per second. Users can completely control the image quality, data format and transmission mode. All the process of image processing functions can through the SCCB programming interface, including gamma curve, white balance, saturation and chroma.

CAMERA MODULE

3. Robot chasis:-

Robot chassis is particularly designed for robots and other mechanical devices. It helps in providing support to PCB, accessories and various parts which are connected to it. Robot chassis is particularly designed for robots and other mechanical devices. ov7670 camera module, ardiuno board with wifi module ,battery placed on this robotic chasis .and two motors are attached to it.

ROBOTIC CHASSIS

4.Motor and motor driver module:-

These motor drivers are used to drive inductive loads that requires forward and reverse function with speed control such as DC Motors, and Stepper Motors. The Motor Driver is a module for motors that allows you to control the working speed and direction of two motors simultaneously . This Motor Driver is designed and developed based on L293D IC. L293D is a 16 Pin Motor Driver IC. This is designed to provide bidirectional drive currents at voltages from 5 V to 36 V.

Motor driver

5.Wifi Module:-

The ESP8266 WiFi Module is a self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.

Wi-Fi module

Wi-Fi module interfacing with Arduino UNO

Hardware connections:





SOFTWARE:-

—MATLAB GUI(graphical user interface):-

Graphical user interfaces (GUIs), also known as apps, provides point-and-click control of your software applications, eliminating the need for others to learn a language or type commands in order to run the application. You can share apps both for use within MATLAB and also as standalone desktop or web apps.

GUI screen in MATLAB used to control and perform all functions

This GUI consists of four blocks as given below:-

 Live view

 Control panel

 Captured image

 Output block

 Live view:-

OV7670 camera module is connected to Arduino board which captures the live images. Wi-Fi module is interfaced with Arduino which maintains communication with matlab GUI. This live view is transferred to MATLAB GUI and displayed in live view block. Axes tool is used in this GUI to display camera output in matlab GUI.

 Control panel:-

Control panel

This panel consists of the control keys for the motors connected to the robotic chasis this panel consist of five keys out of which four keys are used to control the actions of the robot .This button uses window button down and window button up function .The use of this function is that, when the button is pressed using mouse pointer this button will remain in on state until we release the mouse button. So according to button pressed, the robot will move forward back left and right .

One slider is also used for reverse and forward operation when this slider is on “F” and when user press left or right key robot will take forward left or forward right turn respectively, similarly when slider is on” R” and when user press left or right key robot will take reverse left or reverse right turn respectively.

When user press ‘Capture’ button , ‘get snap shot’ function is executed and this will capture image from live view axes and future image processing is done by matlab to detect the affected plant .

Captured image :-

After pressing the ‘Capture’ button the image captured from live view will be displayed in this captured image block. imshow command is used to display image in particular axes in GUI.

 Output block:-

This block consists of edit text box which displays the final result in GUI. i.e plant is affected or not .

IMAGE PROCESSING

Image Acquisition: This is the initial process that responsible in collecting the data. It takes the image as input for further processing.

Image Preprocessing: The images are acquired from the real field it may contain dust, spores and water spots as noise. The purpose of data preprocessing is to eliminate the noise in the image, so as to adjust the pixel values. It enhances the quality of the image. This includes image enhancement before processing the image. The technique used for Image enhancement is Histogram equalization.

Image segmentation: Image segmentation is the third step in our proposed method. The segmented images are clustered into different sectors using Otsu classifier and k-mean clustering algorithm.

k-means clustering– It is a partitioning method. The function k-means partitions data into k mutually exclusive clusters and returns the index of the cluster to which it assigns each observation. K-means treats each observation in your data as an object that has a location in space. The function finds a partition in which objects within each cluster are as close to each other as possible, and as far from objects in other clusters as possible.

Feature extraction: It is the important part to gracefully predict the infected region. Here shape and textural feature extraction is done. The shape oriented feature extraction like Area, Color axis length, eccentricity, solidity and perimeter are calculated.

Output of Image Processing

PROGRAM:-

function varargout = control(varargin) 
% CONTROL MATLAB code for control.fig 
% Begin initialization code - DO NOT EDIT 
gui_Singleton = 1; 
gui_State = struct('gui_Name', mfilename, ... 
'gui_Singleton', gui_Singleton, ... 
'gui_OpeningFcn', @control_OpeningFcn, ... 
'gui_OutputFcn', @control_OutputFcn, ... 
'gui_LayoutFcn', [] , ... 
'gui_Callback', []); 
if nargin && ischar(varargin{1}) 
gui_State.gui_Callback = str2func(varargin{1}); 
end 
if nargout 
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 
else 
gui_mainfcn(gui_State, varargin{:}); 
end 
% End initialization code - DO NOT EDIT 
% --- Executes just before control is made visible. 
function control_OpeningFcn(hObject, eventdata, handles, varargin) 
% This function has no output args, see OutputFcn. 
% hObject handle to figure 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
% varargin command line arguments to control (see VARARGIN) 
% Choose default command line output for control 
handles.output = hObject; 
% Update handles structure 
guidata(hObject, handles); 
% UIWAIT makes control wait for user response (see UIRESUME) 
% uiwait(handles.figure1); 
global a; 
c = videoinput('winvideo',1); 
axes(handles.livec); 
cimage = image(zeros(500,1000,3),'parent',handles.livec); 
preview(c,cimage); 
handles.c = c; 
guidata(hObject,handles) 
% --- Outputs from this function are returned to the command line. 
function varargout = control_OutputFcn(hObject, eventdata, handles) 
% varargout cell array for returning output args (see VARARGOUT); 
% hObject handle to figure 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
% Get default command line output from handles structure 
varargout{1} = handles.output; 
clear all; 
global a; 
global b; 
a= arduino; 
% --- Executes on button press in pushbutton7. 
function pushbutton7_Callback(hObject, eventdata, handles) 
% hObject handle to pushbutton7 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
frame = getsnapshot(handles.c); 
axes(handles.axes2); 
imshow(frame); 
text= ' Image Captured'; 
set(handles.optext,'string',text,'ForegroundColor',[0.6350 0.0780 0.1840]); 
pause(1); 
set(handles.optext,'string',''); 
%=======================================imageprocessing================================================ 
%loading the image
A=frame; 
A_gray=rgb2gray(A); 
%image enhancement using histogram equalization
A_hsv=rgb2hsv(A); 
A_v=A_hsv (:,:,3); 
A_v=histeq(A_v); 
A_hsv(:,:,3)=A_v; 
A_enhanced=hsv2rgb(A_hsv); 
%clustering the image
A_lab= rgb2lab(A); 
ab = A_lab(:,:,2:3); 
nrows = size(ab,1); 
ncols = size(ab,2); 
ab = reshape(ab,nrows*ncols,2); 
nColors = 3; 
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ... 
'Replicates',3); 
pixel_labels = reshape(cluster_idx,nrows,ncols); 
segmented_images = cell(1,3); 
rgb_label = repmat(pixel_labels,[1 1 3]); 
for k = 1:nColors 
color = A; 
color(rgb_label ~= k) = 0; 
segmented_images{k} = color; 
end 
Agg=rgb2gray(segmented_images{2}); 
%thresholding the image
otsu_level= graythresh(Agg); 
A_thresh=im2bw(A_lab,1/255); 
A_thresh=~A_thresh; 
%eroding the image to delete background

se=strel ('disk',20); 
A_erosion= imerode (A_thresh,se); 
if A_erosion==0 
text= ' Plant is affected '; 
set(handles.optext,'string',text,'ForegroundColor','red'); 
clear text; 
else 
text= ' Plant is not affected '; 
set(handles.optext,'string',text,'ForegroundColor',[0.4660 0.6740 0.1880]); 
end 
% --- Executes on mouse press over figure background, over a disabled or 
% --- inactive control, or over an axes background. 
function figure1_WindowButtonDownFcn(hObject, eventdata, handles) 
% hObject handle to figure1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
%save the current object (that with focus) 
global a; 
handles.controlWithFocus = gco; 
guidata(hObject, handles); 
if isfield(handles,'controlWithFocus') && handles.controlWithFocus == handles.forwardb 
%%%forward%%%% 
writeDigitalPin(a,'D9',1); 
writeDigitalPin(a,'D10',0); 
writeDigitalPin(a,'D11',1); 
writeDigitalPin(a,'D12',0); 
text= 'Forward'; 
set(handles.optext,'string',text,'ForegroundColor',[0.6350 0.0780 0.1840]); 
elseif isfield(handles,'controlWithFocus') && handles.controlWithFocus == handles.backb 
%%%reverse%%%% 
writeDigitalPin(a,'D9',0); 
writeDigitalPin(a,'D10',1); 
writeDigitalPin(a,'D11',0); 
writeDigitalPin(a,'D12',1); 
text= 'Reverse'; 
set(handles.optext,'string',text,'ForegroundColor',[0.6350 0.0780 0.1840]); 
elseif isfield(handles,'controlWithFocus') && handles.controlWithFocus == handles.rightb 
%%%right%%%% 
global b; 
if b==1 
writeDigitalPin(a,'D9',0); 

writeDigitalPin(a,'D10',1); 
writeDigitalPin(a,'D11',0); 
writeDigitalPin(a,'D12',0); 
text= 'Reverse Right '; 
set(handles.optext,'string',text,'ForegroundColor',[0.6350 0.0780 0.1840]); 
else 
writeDigitalPin(a,'D9',0); 
writeDigitalPin(a,'D10',0); 
writeDigitalPin(a,'D11',1); 
writeDigitalPin(a,'D12',0); 
text= 'Right'; 
set(handles.optext,'string',text,'ForegroundColor',[0.6350 0.0780 0.1840]); 
end 
elseif isfield(handles,'controlWithFocus') && handles.controlWithFocus == handles.leftb 
%%%left%%%% 
global b; 
if b==1 
writeDigitalPin(a,'D9',0); 
writeDigitalPin(a,'D10',0); 
writeDigitalPin(a,'D11',0); 
writeDigitalPin(a,'D12',1); 
text= 'Reverse Left'; 
set(handles.optext,'string',text,'ForegroundColor',[0.6350 0.0780 0.1840]); 
else 
writeDigitalPin(a,'D9',1); 
writeDigitalPin(a,'D10',0); 
writeDigitalPin(a,'D11',0); 
writeDigitalPin(a,'D12',0); 
text= ' Left'; 
set(handles.optext,'string',text,'ForegroundColor',[0.6350 0.0780 0.1840]); 
end 
else 
%%%%%stop%%%%%S 
writeDigitalPin(a,'D9',0); 
writeDigitalPin(a,'D10',0); 
writeDigitalPin(a,'D11',0); 
writeDigitalPin(a,'D12',0); 
end 
% --- Executes on mouse press over figure background, over a disabled or 
% --- inactive control, or over an axes background. 
function figure1_WindowButtonUpFcn(hObject, eventdata, handles) 
% hObject handle to figure1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
global a; 
handles.mouseUpTime = now; 

handles.controlWithFocus = []; 
guidata(hObject, handles); 
writeDigitalPin(a,'D9',0); 
writeDigitalPin(a,'D10',0); 
writeDigitalPin(a,'D11',0); 
writeDigitalPin(a,'D12',0); 
set(handles.optext,'string',''); 
%%%===============================================slider=============================%%% 
% --- Executes on slider movement. 
function slider1_Callback(hObject, eventdata, handles) 
% hObject handle to slider1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
% Hints: get(hObject,'Value') returns position of slider 
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider 
global a; 
global b; 
b= get(hObject,'value'); 
if b==1 
%revrese led% 
writeDigitalPin(a,'D2',1); 
else 
writeDigitalPin(a,'D2',0); 
end 
% --- Executes during object creation, after setting all properties. 
function slider1_CreateFcn(hObject, eventdata, handles) 
% hObject handle to slider1 (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles empty - handles not created until after all CreateFcns called 
% Hint: slider controls usually have a light gray background. 
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 
set(hObject,'BackgroundColor',[.9 .9 .9]);

RESULTS:-

IMAGE CAPTURED
RESULT FOR UNAFFECTED PLANT
RESULT FOR AFFECTED PLANT

2 thoughts on “Plant Disease Detection Robot”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.