Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mega 2560-Based Obstacle-Avoiding Robot with Ultrasonic Sensors and Motor Drivers

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560-Based Obstacle-Avoiding Robot with Ultrasonic Sensors and Motor Drivers

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to control motors and detect obstacles using an Arduino Mega 2560 microcontroller. The circuit includes motor drivers, ultrasonic sensors, limit switches, potentiometers, and a battery. The Arduino Mega 2560 is programmed to control the motors and read sensor data to navigate and avoid obstacles.

Component List

  1. BTS7960 Motor Driver

    • Description: High-power motor driver module.
    • Pins: Pin 1, Pin 2, Pin 3, Pin 4, Pin 5, Pin 6, Pin 7, Pin 8, Pin 9, Pin 10, Pin 11, Pin 12
  2. 12V 200Ah Battery

    • Description: Power source for the circuit.
    • Pins: GND, 12V
  3. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic distance sensor.
    • Pins: VCC, TRIG, ECHO, GND
  4. Limit Switch

    • Description: Mechanical switch for detecting limits.
    • Pins: C, NO, NC
  5. Arduino Mega 2560

    • Description: Microcontroller board.
    • Pins: IOREF, RESET, 3V3, 5V, GND, VIN, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, D21/SCL, D20/SDA, D19/RX1, D18/TX1, D17 PWM/RX2, D16 PWM/TX2, D15/RX3, D14/TX3, D0 RX0, D1 TX0, D2 PWM, D3 PWM, D4 PWM, D5 PWM, D6 PWM, D7 PWM, D8 PWM, D9 PWM, D10 PWM, D11 PWM, D12 PWM, D13 PWM, AREF, SDA, SCL, D52, D50, D48, D46, D44, D42, D40, D38, D36, D34, D32, D30, D28, D26, D24, D22, D53, D51, D49, D47, D45, D43, D41, D39, D37, D35, D33, D31, D29, D27, D25, D23
  6. 775 Motor

    • Description: High-torque DC motor.
    • Pins: positive, negative
  7. Potentiometer

    • Description: Variable resistor for adjusting voltage.
    • Pins: GND, Output, VCC
  8. Rocker Switch (SPST)

    • Description: Single-pole single-throw switch.
    • Pins: 1, 2

Wiring Details

BTS7960 Motor Driver

12V 200Ah Battery

HC-SR04 Ultrasonic Sensor

Limit Switch

Arduino Mega 2560

775 Motor

Potentiometer

Rocker Switch (SPST)

Documented Code

// Motor Pins
int R1_en = 2;
int L1_en = 3;
int R_pwm = 4;
int R2_en = 8;
int L2_en = 9;
int L_pwm = 10;

// Relay Pins
int R_Relay = 5;
int L_Relay = 6;

// Potentiometer Pins
const int xMaxPin = A2; // Potentiometer for X max
const int yMaxPin = A3; // Potentiometer for Y max

// Ultrasonic Sensor Pins
const int trigPins[6] = {A0, A1, A4, A5, A6, A7}; // Trigger pins for 6 ultrasonic sensors
const int echoPins[6] = {7, 12, 13, 11, 14, 16};   // Echo pins for 6 ultrasonic sensors

// Limit Switch Pins
const int limitSwitchLeft = 17;
const int limitSwitchRight = 18;

// Button Pin
const int buttonPin = 15;

// Global Variables
int