Weeding is one of the most labour-intensive farm tasks in India, consuming 25-40% of total crop production costs. A weed detection robot with camera and servo arm on Arduino uses computer vision to identify weeds from crop plants and mechanically removes them with a servo-driven arm, reducing herbicide use and labour costs. This project combines image processing, machine learning, and robotics – an excellent advanced project for engineering students and precision farming enthusiasts.
Table of Contents
- Project Concept and Architecture
- Hardware Components
- Robot Chassis and Movement
- Camera and Weed Detection Algorithm
- Servo Arm Design
- Arduino and Python Code
- Frequently Asked Questions
Project Concept and Architecture
The weed detection robot operates as follows:
- Camera mounted on the robot scans the ground between crop rows
- Raspberry Pi runs a Python image classification model (TensorFlow Lite or OpenCV colour-based)
- When a weed is detected, the Pi sends coordinates to Arduino via Serial
- Arduino calculates servo arm positions using inverse kinematics
- 2-DOF servo arm extends to the weed location and cuts or pulls it
- Robot moves forward to the next position and repeats
This architecture separates the computational heavy lifting (Pi handles vision) from real-time mechanical control (Arduino handles servos), giving the best of both platforms.
Hardware Components
- Raspberry Pi 5 (4GB) – vision processing
- Arduino Mega 2560 – motor and servo control
- Arducam IMX219 wide-angle camera (120 degree) – crop row scanning
- 2x MG996R servo motors – 2-DOF weeding arm (shoulder + elbow)
- 1x SG90 servo – wrist/cutting tool rotation
- 2x N20 DC gear motors with encoders – differential drive chassis
- L298N motor driver module – N20 motor control
- 12V 5Ah LiPo or SLA battery – power supply
- 2x Ultrasonic sensors (HC-SR04) – obstacle avoidance
- 3D-printed or laser-cut chassis frame
Estimated BOM cost: Rs 8,000-15,000. The Raspberry Pi 5 is the most expensive component; a Pi 4 also works for this application.
Robot Chassis and Movement
Use a differential drive chassis with two powered rear wheels and a single front castor wheel. Track width of 200-250mm allows movement in standard crop row spacing (30cm for tomato, 45cm for brinjal). The chassis should be at most 180mm wide to fit between standard row spacing without touching plants.
Row guidance: use two IR sensors on either side of the chassis to detect the soil-mulch boundary and maintain row tracking without GPS. This simple approach works reliably for straight rows.
Camera and Weed Detection Algorithm
Two approaches for weed vs crop detection:
Approach 1: Colour-based (simpler, less accurate)
import cv2
import numpy as np
def detect_weeds_by_colour(frame):
# Convert to HSV for better colour segmentation
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# Green range for crop plants (calibrate for your specific crop)
crop_green = cv2.inRange(hsv, (35, 50, 50), (85, 255, 255))
# Broad green-yellow range catches weeds with different hue
weed_range = cv2.inRange(hsv, (25, 30, 30), (100, 255, 255))
# Weeds = broad green MINUS crop green (different hue/intensity)
weed_mask = cv2.subtract(weed_range, crop_green)
weed_mask = cv2.dilate(weed_mask, None, iterations=3)
# Find weed contours
contours, _ = cv2.findContours(weed_mask,
cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
weeds = []
for c in contours:
if cv2.contourArea(c) > 500: # Filter noise
M = cv2.moments(c)
if M["m00"] > 0:
cx = int(M["m10"] / M["m00"])
cy = int(M["m01"] / M["m00"])
weeds.append((cx, cy))
return weeds
Approach 2: TensorFlow Lite classifier (more accurate)
Train a MobileNetV2 model on a dataset of your specific crop and local weed species. The CWFID (Crop/Weed Field Image Dataset) is a free starting dataset for fine-tuning. Pi 5 runs TFLite at 10-15 FPS for 224×224 input resolution – sufficient for a slow-moving robot.
Servo Arm Design
A 2-DOF arm with 150mm link lengths provides a 300mm reach radius – sufficient to cover the full crop row width from the robot centreline. Mount a small rotating cutter (driven by the wrist servo) at the arm tip to sever weed stems at soil level. Alternatively, use a suction nozzle connected to a small 12V air pump to aspirate small weeds.
Arduino and Python Code
// Arduino Mega - servo arm control
#include <Servo.h>
Servo shoulder, elbow, wrist;
void setup() {
Serial.begin(115200);
shoulder.attach(9);
elbow.attach(10);
wrist.attach(11);
// Home position
shoulder.write(90);
elbow.write(45);
wrist.write(90);
}
struct ArmTarget { int sx, ex; }; // shoulder, elbow angles
// Simple 2D inverse kinematics for planar arm
ArmTarget inverseKinematics(float x, float y) {
float L1 = 150.0, L2 = 150.0; // Link lengths in mm
float dist = sqrt(x*x + y*y);
// Clamp to reachable workspace
dist = constrain(dist, 50, L1+L2-10);
float cos_e = (dist*dist - L1*L1 - L2*L2) / (2*L1*L2);
float e_angle = acos(cos_e) * 180.0 / PI;
float s_angle = atan2(y, x) * 180.0 / PI
+ asin(L2*sin(e_angle*PI/180.0)/dist)*180.0/PI;
return {(int)s_angle, (int)e_angle};
}
void loop() {
if(Serial.available() >= 8) {
// Receive target coordinates from Raspberry Pi
float x = Serial.parseFloat();
float y = Serial.parseFloat();
ArmTarget t = inverseKinematics(x, y);
shoulder.write(constrain(t.sx, 0, 180));
elbow.write(constrain(t.ex, 0, 160));
delay(500); // Allow arm to reach position
// Activate cutter for 1 second
wrist.write(0); delay(1000); wrist.write(90);
// Return to home
shoulder.write(90); elbow.write(45);
Serial.println("DONE");
}
}
Frequently Asked Questions
What row spacing does the robot work in?
With a 180mm chassis width, the robot fits comfortably in 30cm+ row spacing covering most Indian vegetable crops. For smaller spacing (e.g. 20cm for spinach), a narrower chassis (120-140mm) is needed. Crops like sugarcane with 75-90cm spacing allow larger, heavier robots with more powerful weeding tools.
How does the robot distinguish weeds from crop seedlings?
For colour-based approaches, the robot is programmed for a specific crop’s colour profile – anything outside that profile at the expected plant locations is treated as a weed. For ML-based approaches, a trained classifier distinguishes based on leaf shape, texture, and colour simultaneously. Both approaches require calibration for each crop and growing stage.
What is the weeding capacity per hour?
A basic servo-arm robot moving at 3-5 cm/second with 2-second arm cycle time achieves approximately 0.01-0.02 acres per hour. This is much slower than manual weeding (0.05-0.1 acres/hour) but operates continuously without fatigue. Commercial agricultural robots (Ecorobotix, Naio Oz) achieve 1-3 acres/day. The DIY version is better suited for demonstration, research, and small test plots.
Can solar power run the robot all day?
A 20W solar panel combined with a 5Ah LiPo battery provides approximately 4-6 hours of continuous operation for a small robot drawing 3-5W average (servo actuations are intermittent). For full-day 8-hour operation, a 40W panel with 10Ah battery is more appropriate.
Are there any open-source weed detection datasets for Indian crops?
The Plant Village dataset includes disease images but limited weed data. The CWFID dataset covers sugar beet and spinach rows. For Indian crops, you may need to create your own dataset – photograph 200-500 examples each of your target crop and local weed species, label them, and fine-tune a MobileNetV2 model. Transfer learning from a pre-trained ImageNet model requires only 30-60 minutes of GPU training time.
Add comment