Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino Mega 2560 Controlled Multi-Motor Robot with RC Receiver and H-Bridge Drivers

Image of Arduino Mega 2560 Controlled Multi-Motor Robot with RC Receiver and H-Bridge Drivers

Circuit Documentation

Summary

This circuit is designed to control multiple DC motors using an Arduino Mega 2560 microcontroller in conjunction with IBT-2 H-Bridge Motor Drivers. The system is powered by a 12V 7Ah battery and includes an RC Receiver for remote control capabilities. The Arduino Mega 2560 is responsible for processing the input signals from the RC Receiver and accordingly controlling the speed and direction of the DC motors through the motor drivers.

Component List

Arduino Mega 2560

  • Microcontroller board based on the ATmega2560
  • It has 54 digital input/output pins (of which 15 can be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button.

DC Motor

  • A motor that converts DC electrical energy into mechanical energy.
  • It typically has two pins: one for the positive supply and one for the negative supply (ground).

RC Receiver 6 channels

  • A radio receiver that can receive signals from a remote control transmitter and output control signals on its channels.
  • It has 6 channels for different control signals and power supply pins.

12v 7ah Battery

  • A rechargeable battery that provides a 12V output with a capacity of 7Ah.
  • It has two terminals: positive (12v +) and negative (12v -).

IBT-2 H-Bridge Motor Driver

  • A motor driver module that can control the speed and direction of a DC motor.
  • It has pins for power supply (VCC, GND), enable (R_EN, L_EN), and PWM control for both directions (RPWM, LPWM).

Comment

  • A placeholder for additional notes or comments within the circuit design.

Wiring Details

Arduino Mega 2560

  • VIN connected to the 12V supply from the battery.
  • GND connected to the ground of the battery and the ground of the RC Receiver.
  • Digital pins D2 to D13 are used for PWM control and enable signals to the IBT-2 H-Bridge Motor Drivers.

DC Motors

  • Each motor is connected to an IBT-2 H-Bridge Motor Driver, which controls the motor's speed and direction.

RC Receiver 6 channels

  • VCC connected to the 5V output from the Arduino Mega 2560.
  • GND connected to the ground of the Arduino Mega 2560.
  • CH1 to CH6 are used to receive control signals from the remote control transmitter.

12v 7ah Battery

  • 12v + provides the power supply to the Arduino Mega 2560 and the IBT-2 H-Bridge Motor Drivers.
  • 12v - is connected to the ground of the circuit.

IBT-2 H-Bridge Motor Driver

  • VCC connected to the 12V supply from the battery.
  • GND connected to the ground of the battery.
  • R_EN, L_EN, RPWM, and LPWM are connected to the corresponding pins on the Arduino Mega 2560 for motor control.

Documented Code

// Motor Speed Calibration
int D1ForwardSpeed = 255;    // Speed for motor D1 when moving forward
int D1BackwardSpeed = 255;   // Speed for motor D1 when moving backward

int D2ForwardSpeed = 255;    // Speed for motor D2 when moving forward
int D2BackwardSpeed = 255;   // Speed for motor D2 when moving backward

// Drive Curves (adjust speed for curves)
// FORWARD
int driveForwardRightCurveSpeed = 150;  // Speed for right curve while moving forward
int driveForwardLeftCurveSpeed = 150;   // Speed for left curve while moving forward

// BACKWARD
int driveBackwardRightCurveSpeed = 150; // Speed for right curve while moving backward
int driveBackwardLeftCurveSpeed = 150;  // Speed for left curve while moving backward

// Transmitter Pin Configuration
// Variables a and b
int varB = 2;  // Pin 2 for variable b
int varA = 3;  // Pin 3 for variable a

// Stick controls
int rudStick = 4;  // Pin 4 for rudder stick
int troStick = 5;  // Pin 5 for throttle stick
int eleStick = 6;  // Pin 6 for elevator stick
int aleStick = 7;  // Pin 7 for aileron stick

// Transmitter Signal Variables
int varBPwm = 0;   // Pulse width modulation for variable b
int varAPwm = 0;   // Pulse width modulation for variable a
int rudPwm = 0;    // Pulse width modulation for rudder stick
int troPwm = 0;    // Pulse width modulation for throttle stick
int elePwm = 0;    // Pulse width modulation for elevator stick
int alePwm = 0;    // Pulse width modulation for aileron stick

// D1 Motor Drive Pins
int D1RPWM = 10;  // RPWM pin for motor D1 forward (black wire)
int D1LPWM = 11;  // LPWM pin for motor D1 backward (white wire)
int D1LEN = 14;   // LEN pin for motor D1 enable (green wire)
int D1REN = 15;   // REN pin for motor D1 enable (blue wire)

// D2 Motor Drive Pins
int D2RPWM = 8;   // RPWM pin for motor D2 forward (black wire)
int D2LPWM = 9;   // LPWM pin for motor D2 backward (white wire)
int D2LEN = 16;   // LEN pin for motor D2 enable (green wire)
int D2REN = 17;   // REN pin for motor D2 enable (blue wire)

void setup() {
    Serial.begin(9600);

    // Set up pins for transmitter
    pinMode(varB, INPUT);
    pinMode(varA, INPUT);
    pinMode(rudStick, INPUT);
    pinMode(troStick, INPUT);
    pinMode(eleStick, INPUT);
    pinMode(aleStick, INPUT);

    // Set up LED pins
    pinMode(22, OUTPUT); // LED1 - RGB (purple wire)
    pinMode(24, OUTPUT); // LED1 - RGB (grey wire)
    pinMode(26, OUTPUT); // LED1 - RGB (white wire)
    pinMode(23, OUTPUT); // LED2 - RGB (orange wire)
    pinMode(25, OUTPUT); // LED2 - RGB (yellow wire)
    pinMode(27, OUTPUT); // LED2 - RGB (green wire)

    // Set up motor drive pins for D1
    pinMode(D1RPWM, OUTPUT); // Motor D1 forward
    pinMode(D1LPWM, OUTPUT); // Motor D1 backward
    pinMode(D1LEN, OUTPUT);  // Motor D1 enable
    pinMode(D1REN, OUTPUT);  // Motor D1 enable

    // Set up motor drive pins for D2
    pinMode(D2RPWM, OUTPUT); // Motor D2 forward
    pinMode(D2LPWM, OUTPUT); // Motor D2 backward
    pinMode(D2LEN, OUTPUT);  // Motor D2 enable
    pinMode(D2REN, OUTPUT);  // Motor D2 enable
}

// Functions to read signals from transmitter
void varBCh() {
    varBPwm = pulseIn(varB, HIGH); // Read pulse width from varB
}
void varACh() {
    varAPwm = pulseIn(varA, HIGH); // Read pulse width from varA
}
void rudCh() {
    rudPwm = pulseIn(rudStick, HIGH); // Read pulse width from rudder stick
}
void troCh() {
    troPwm = pulseIn(troStick, HIGH); // Read pulse width from throttle stick
}
void eleCh() {
    elePwm = pulseIn(eleStick, HIGH); // Read pulse width from elevator stick
}
void aleCh() {
    alePwm = pulseIn(aleStick, HIGH); // Read pulse width from aileron stick
}

// Function to read all transmitter signals
void txReadings() {
    // Uncomment lines to read more channels
    //varBCh();
    //varACh();
    //rudCh();
    //troCh();
    eleCh();  // Read elevator stick
    aleCh();  // Read aileron stick
}

// Function to print transmitter readings
void printTx() {
    txReadings();
    Serial.print("VarB    : ");
    Serial.print(varBPwm);
    Serial.print("   VarA   : ");
    Serial.print(varAPwm);
    Serial.print("   Rud    : ");
    Serial.print(rudPwm);
    Serial.print("   Tro    : ");
    Serial.print(troPwm);
    Serial.print("   Ele    : ");
    Serial.print(elePwm);
    Serial.print("   Ale    : ");
    Serial.print(alePwm);
    Serial.println("");
}

// Individual motor control functions for D1
void D1Forward(int speed) {
    // Enable D1 drive
    digitalWrite(D1LEN, HIGH);
    digitalWrite(D1REN, HIGH);

    // Set motor D1 to move forward
    analogWrite(D1RPWM,