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.
// 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,