Arduino and Raspberry Pi-Based Robotic Weeding Machine with Ultrasonic Obstacle Detection
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This document provides a detailed overview of a robotic weeding machine circuit. The circuit includes an Arduino UNO, an HC-SR04 Ultrasonic Sensor, an OV7725 camera module, a Raspberry Pi 4B, an L298N DC motor driver, a DC motor, and a 12V battery. The Arduino UNO controls the motor and ultrasonic sensor, while the Raspberry Pi 4B interfaces with the camera module. The L298N motor driver is used to control the DC motor, and the 12V battery powers the motor driver.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
HC-SR04 Ultrasonic Sensor
- Description: An ultrasonic sensor used for distance measurement.
- Pins: VCC, TRIG, ECHO, GND
OV7725
- Description: A camera module used for capturing images.
- Pins: 3V3, GND, SIOC, SIOD, VSYNC, HREF, PCLK, XCLK, D9, D8, D7, D6, D5, D4, D3, D2, RESET, D1, D0, PWDN
Raspberry Pi 4B
- Description: A single-board computer used for processing and interfacing with the camera module.
- Pins: 3V3, 5V, GPIO2, GPIO3, GND, GPIO4, GPIO14, GPIO15, GPIO17, GPIO18, GPIO27, GPIO22, GPIO23, GPIO24, GPIO10, GPIO9, GPIO25, GPIO11, GPIO8, GPIO7, ID_SD, GPIO5, GPIO6, GPIO12, GPIO13, GPIO19, GPIO16, GPIO26, GPIO20, GPIO21, ID_SC, TR01_TAP, TR00_TAP, TR03_TAP, TR02_TAP, RUN, GLOBAL_EN, ETH, HDMI 0, HDMI 1, CAMERA, AV
L298N DC Motor Driver
- Description: A motor driver used to control the DC motor.
- Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
DC Motor
- Description: A motor used for rotating a blade to cut weeds.
- Pins: pin 1, pin 2
Battery 12V
- Description: A 12V battery used to power the motor driver.
- Pins: +, -
Wiring Details
Arduino UNO
5V connected to:
- ENA on L298N DC motor driver
- VCC on HC-SR04 Ultrasonic Sensor
GND connected to:
- GND on HC-SR04 Ultrasonic Sensor
- GND on L298N DC motor driver
- - on 12V battery
D9 connected to:
- TRIG on HC-SR04 Ultrasonic Sensor
D8 connected to:
- ECHO on HC-SR04 Ultrasonic Sensor
D6 connected to:
- IN2 on L298N DC motor driver
D5 connected to:
- IN1 on L298N DC motor driver
HC-SR04 Ultrasonic Sensor
VCC connected to:
- 5V on Arduino UNO
GND connected to:
- GND on Arduino UNO
TRIG connected to:
- D9 on Arduino UNO
ECHO connected to:
- D8 on Arduino UNO
OV7725
3V3 connected to:
- 3V3 on Raspberry Pi 4B
GND connected to:
- GND on Raspberry Pi 4B
SIOD connected to:
- GPIO3 on Raspberry Pi 4B
XCLK connected to:
- GPIO18 on Raspberry Pi 4B
VSYNC connected to:
- GPIO23 on Raspberry Pi 4B
HREF connected to:
- GPIO24 on Raspberry Pi 4B
PCLK connected to:
- GPIO25 on Raspberry Pi 4B
SIOC connected to:
- GPIO5 on Raspberry Pi 4B
Raspberry Pi 4B
3V3 connected to:
- 3V3 on OV7725
GND connected to:
- GND on OV7725
GPIO3 connected to:
- SIOD on OV7725
GPIO18 connected to:
- XCLK on OV7725
GPIO23 connected to:
- VSYNC on OV7725
GPIO24 connected to:
- HREF on OV7725
GPIO25 connected to:
- PCLK on OV7725
GPIO5 connected to:
- SIOC on OV7725
L298N DC Motor Driver
ENA connected to:
- 5V on Arduino UNO
GND connected to:
- GND on Arduino UNO
- - on 12V battery
IN2 connected to:
- D6 on Arduino UNO
IN1 connected to:
- D5 on Arduino UNO
OUT1 connected to:
- pin 1 on DC Motor
OUT2 connected to:
- pin 2 on DC Motor
12V connected to:
- + on 12V battery
DC Motor
pin 1 connected to:
- OUT1 on L298N DC motor driver
pin 2 connected to:
- OUT2 on L298N DC motor driver
Battery 12V
+ connected to:
- 12V on L298N DC motor driver
- connected to:
- GND on Arduino UNO
- GND on L298N DC motor driver
Documented Code
Arduino UNO Code
/*
* Robotic Weeding Machine
* This Arduino sketch controls a robotic weeding machine that uses a DC motor
* to rotate a blade for cutting weeds. The machine uses an ultrasonic sensor
* to detect obstacles and avoid collisions. The motor is controlled via an
* L298N motor driver.
*/
// Pin definitions
const int trigPin = 9; // Trigger pin for HC-SR04
const int echoPin = 8; // Echo pin for HC-SR04
const int motorIn1 = 5; // IN1 pin for L298N
const int motorIn2 = 6; // IN2 pin for L298N
// Variables for ultrasonic sensor
long duration;
int distance;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set pin modes
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motorIn1, OUTPUT);
pinMode(motorIn2, OUTPUT);
}
void loop() {
// Measure distance using ultrasonic sensor
distance = measureDistance();
// Print distance to serial monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Control motor based on distance
if (distance > 20) {
// If no obstacle, run motor
runMotor();
} else {
// If obstacle detected, stop motor
stopMotor();
}
// Small delay before next loop
delay(100);
}
// Function to measure distance using HC-SR04
int measureDistance() {
// Clear the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Set the trigPin HIGH for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculate the distance