This project combines embedded robotics and AI-based computer vision to demonstrate two powerful applications of automation:
- An Arduino-based autonomous obstacle-avoiding robot that navigates its surroundings using an ultrasonic sensor.
- A YOLO Object Detection Streamlit App for real-time image and video object detection powered by TensorRT and GPU acceleration.
- Introduction
- Objectives
- Hardware Components
- Circuit Diagram & Connections
- Arduino Code
- Code Explanation
- Applications
- YOLO Object Detection Streamlit App
- Output
- Conclusion
- License
The Obstacle Avoiding Robot is an autonomous system that can detect and avoid obstacles without human intervention.
Using an Arduino Uno, ultrasonic sensor (HC-SR04), and L298N motor driver, the robot intelligently changes direction when it detects nearby objects.
The project also includes an advanced YOLO-based Object Detection Streamlit application, showcasing the AI side of robotics — detecting objects from images and videos in real-time using GPU acceleration.
- Build an autonomous robot capable of avoiding obstacles.
- Demonstrate integration of sensors, actuators, and microcontrollers using Arduino.
- Provide hands-on experience in motor control, sensor interfacing, and AI-powered computer vision.
| Component | Description |
|---|---|
| Arduino Uno | Central processing unit for the robot. |
| Ultrasonic Sensor (HC-SR04) | Measures the distance to obstacles. |
| L298N Motor Driver | Controls motor direction and speed. |
| 2 DC Motors | Drive the robot’s wheels. |
| 9V Battery | Powers the Arduino Uno. |
| AA Battery Pack | Provides power to the motors. |
| Connecting Wires | Assemble the circuit. |
| Pin | Connection |
|---|---|
| VCC | Arduino 5V |
| Trig | Pin 4 |
| Echo | Pin 2 |
| Pin | Connection |
|---|---|
| ENA | Arduino Pin 5 |
| ENB | Arduino Pin 6 |
| Left Motor Forward | Pin 8 |
| Left Motor Backward | Pin 9 |
| Right Motor Forward | Pin 10 |
| Right Motor Backward | Pin 11 |
void setup() {
pinMode(4,OUTPUT); // Trigger
pinMode(2,INPUT); // Echo
pinMode(5,OUTPUT); // EnA
pinMode(6,OUTPUT); // EnB
pinMode(8,OUTPUT); // Left motors forward
pinMode(9,OUTPUT); // Left motors backward
pinMode(10,OUTPUT); // Right motors forward
pinMode(11,OUTPUT); // Right motors backward
Serial.begin(115200);
}
void loop() {
digitalWrite(4, LOW);
delayMicroseconds(2);
digitalWrite(4, HIGH);
delayMicroseconds(10);
digitalWrite(4, LOW);
int duration = pulseIn(2, HIGH);
int distance = duration * 0.034 / 2;
Serial.println(distance);
delay(10);
if (distance >= 20) {
analogWrite(5, 255);
digitalWrite(8, 1);
digitalWrite(9, 0);
analogWrite(6, 255);
digitalWrite(10, 0);
digitalWrite(11, 1);
} else if (distance < 20) {
analogWrite(5, 255);
digitalWrite(8, 1);
digitalWrite(9, 0);
analogWrite(6, 255);
digitalWrite(10, 1);
digitalWrite(11, 0);
}
}
---
## Code Explanation
* **Initialization:** Sets up sensor and motor pins.
* **Distance Calculation:** Uses ultrasonic sensor with `distance = duration × 0.034 / 2`.
* **Logic:**
* If distance ≥ 20 cm → Move forward.
* If distance < 20 cm → Turn to avoid obstacles.
* **Motor Control:** Controlled by L298N driver using PWM for speed and direction.
---
## Applications
* Autonomous Vehicles: Collision avoidance foundation.
* Robotics Education: Ideal beginner Arduino project.
* Home Automation: Adaptable for robotic cleaners and lawn mowers.
---
## YOLO Object Detection Streamlit App
This app demonstrates real-time object detection using YOLO + TensorRT in Streamlit with GPU acceleration.
### Features
* Real-time object detection in images/videos.
* Optimized inference with TensorRT.
* GPU memory and inference time tracking.
* Download annotated outputs.
* Multi-threaded video processing.
---
### Sample Code (YOLO + Streamlit + TensorRT)
```python
import streamlit as st
from ultralytics import YOLO
import torch
from PIL import Image
st.title("YOLO Object Detection App")
MODEL_PATH = "runs/detect/train/weights/best.engine"
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
@st.cache_resource
def load_model():
model = YOLO(MODEL_PATH, task='detect')
return model
model = load_model()
conf_threshold = st.sidebar.slider("Confidence", 0.0, 1.0, 0.25, 0.05)
uploaded_file = st.file_uploader("Upload Image", type=["jpg", "jpeg", "png"])
if uploaded_file:
image = Image.open(uploaded_file)
results = model.predict(source=image, conf=conf_threshold, device=DEVICE, verbose=False)
annotated_image = results[0].plot()
st.image(annotated_image, caption="Detected Objects")git clone https://github.com/yourusername/Obstacle-Avoiding-Robot-Arduino-YOLO.git
cd Obstacle-Avoiding-Robot-Arduino-YOLO
pip install -r requirements.txtUpdate your YOLO TensorRT model path in app.py:
MODEL_PATH = "path/to/best.engine"- Assemble components as per the circuit diagram.
- Upload Arduino code via Arduino IDE.
- Power the robot to start autonomous navigation.
streamlit run app.pyThen open the provided local URL in your browser.
- The robot autonomously avoids obstacles.
- YOLO app detects and annotates objects in real time.
This project merges robotics and AI to build an autonomous robot capable of environmental awareness through sensors and vision — a practical step toward intelligent robotic systems.
