Skip to content

An integrated project combining Arduino robotics and computer vision. It features an Obstacle Avoiding Robot using ultrasonic sensors and an Object Detection App built with YOLO and TensorRT for real-time AI-powered perception.

License

Notifications You must be signed in to change notification settings

longlivewama/obstacle-Avoiding-Robot-Using-Arduino-and-Computer-Vision-Object-Detection-App

Repository files navigation

Obstacle Avoiding Robot Using Arduino and Computer Vision Object Detection App

Obstacle Avoiding Robot Using Arduino

This project combines embedded robotics and AI-based computer vision to demonstrate two powerful applications of automation:

  1. An Arduino-based autonomous obstacle-avoiding robot that navigates its surroundings using an ultrasonic sensor.
  2. A YOLO Object Detection Streamlit App for real-time image and video object detection powered by TensorRT and GPU acceleration.

Table of Contents


Introduction

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.


Objectives

  1. Build an autonomous robot capable of avoiding obstacles.
  2. Demonstrate integration of sensors, actuators, and microcontrollers using Arduino.
  3. Provide hands-on experience in motor control, sensor interfacing, and AI-powered computer vision.

Hardware Components

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.

Circuit Diagram & Connections

Ultrasonic Sensor

Pin Connection
VCC Arduino 5V
Trig Pin 4
Echo Pin 2

Motor Driver (L298N)

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

Arduino Code

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")

Installation

git clone https://github.com/yourusername/Obstacle-Avoiding-Robot-Arduino-YOLO.git
cd Obstacle-Avoiding-Robot-Arduino-YOLO
pip install -r requirements.txt

Update your YOLO TensorRT model path in app.py:

MODEL_PATH = "path/to/best.engine"

How to Run

Run the Arduino Robot

  1. Assemble components as per the circuit diagram.
  2. Upload Arduino code via Arduino IDE.
  3. Power the robot to start autonomous navigation.

Run the Streamlit App

streamlit run app.py

Then open the provided local URL in your browser.


Output

  • The robot autonomously avoids obstacles.
  • YOLO app detects and annotates objects in real time.

Conclusion

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.

About

An integrated project combining Arduino robotics and computer vision. It features an Obstacle Avoiding Robot using ultrasonic sensors and an Object Detection App built with YOLO and TensorRT for real-time AI-powered perception.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages