Arduino Mega 2560 Controlled Mecanum Wheel Robot with Bluetooth and Stepper Motor
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
The circuit is designed to control a 4WD Mecanum Wheel Car with Bluetooth control capabilities. It includes an Arduino Mega 2560 microcontroller for processing inputs and controlling outputs, two L298N DC motor drivers for driving four DC motors, an HC-05 Bluetooth module for wireless communication, a Servomotor MG995 for additional actuation, an A4988 stepper motor driver for controlling a Nema 17 stepper motor, and multiple 18650 Li-Ion batteries for power supply.
Component List
Microcontroller
- Arduino Mega 2560: A microcontroller board based on the ATmega2560, with a wide range of input/output pins.
Motor Drivers
- L298N DC Motor Driver: A high-power motor driver capable of driving up to two DC motors.
- A4988 Stepper Motor Driver (Red): A compact driver for controlling stepper motors, commonly used in 3D printers and CNC machines.
Motors
- DC Motor: A standard motor used for driving wheels or other mechanical parts.
- Nema 17 42-STH48: A stepper motor used for precise control of mechanical movement.
- Servomotor MG995: A high-torque servomotor for precise angular positioning.
Communication Module
- HC-05 Bluetooth Module: A widely used Bluetooth module for wireless communication.
Power Supply
- 18650 Li-Ion Battery: A rechargeable battery commonly used in portable electronics.
Wiring Details
Arduino Mega 2560
5Vconnected to HC-05 Bluetooth Module VCC, A4988 Stepper Motor Driver VDD, and Servomotor MG995 VCC.GNDconnected to HC-05 Bluetooth Module GND, A4988 Stepper Motor Driver GND, and Servomotor MG995 GND.D0 RX0connected to HC-05 Bluetooth Module TXD.D1 TX0connected to HC-05 Bluetooth Module RXD.D2 PWMconnected to L298N DC Motor Driver ENB.D3 PWMconnected to L298N DC Motor Driver ENA.D4 PWMconnected to second L298N DC Motor Driver ENA.D5 PWMconnected to second L298N DC Motor Driver ENB.D7 PWMconnected to Servomotor MG995 SIG.D8 PWMconnected to A4988 Stepper Motor Driver STEP.D9 PWMconnected to A4988 Stepper Motor Driver DIR.D22toD29connected to L298N DC Motor Driver IN1 to IN4 for both motor drivers.
L298N DC Motor Driver (Two Instances)
12Vconnected to 18650 Li-Ion Battery Positive.GNDconnected to 18650 Li-Ion Battery Negative.OUT1toOUT4connected to corresponding DC Motor pins.
A4988 Stepper Motor Driver (Red)
VMOTconnected to 18650 Li-Ion Battery Positive.GNDconnected to 18650 Li-Ion Battery Negative.RESETconnected to A4988 Stepper Motor Driver SLEEP.2B,2A,1A,1Bconnected to Nema 17 42-STH48 corresponding pins.
HC-05 Bluetooth Module
VCCandGNDconnected to Arduino Mega 2560 5V and GND.TXDconnected to Arduino Mega 2560 D0 RX0.RXDconnected to Arduino Mega 2560 D1 TX0.
Servomotor MG995
VCCandGNDconnected to Arduino Mega 2560 5V and GND.SIGconnected to Arduino Mega 2560 D7 PWM.
Nema 17 42-STH48
- Connected to A4988 Stepper Motor Driver corresponding pins.
18650 Li-Ion Battery (Multiple Instances)
- Providing power to the motor drivers and stepper motor driver.
Documented Code
/*
* Arduino Sketch for 4WD Mecanum Wheel Car with Bluetooth Control
* Controls:
* F - Move Forward
* B - Move Backward
* L - Turn Left
* R - Turn Right
* S - Stop
* U - Stepper Motor Clockwise 200 steps
* D - Stepper Motor Counter-Clockwise 200 steps
* Q - Glide Left
* W - Glide Right
*/
#include <Stepper.h>
// Motor driver pins
const int Enable_Rear_Right = 3;
const int Enable_Rear_Left = 2;
const int Rear_Right_Pin1 = 22;
const int Rear_Right_Pin2 = 23;
const int Rear_Left_Pin1 = 24;
const int Rear_Left_Pin2 = 25;
const int Enable_Front_Right = 4;
const int Enable_Front_Left = 5;
const int Front_Right_Pin1 = 26;
const int Front_Right_Pin2 = 27;
const int Front_Left_Pin1 = 28;
const int Front_Left_Pin2 = 29;
// Stepper motor pins
const int STEP_PIN = 8;
const int DIR_PIN = 9;
const int STEPS_PER_REV = 200;
Stepper stepper(STEPS_PER_REV, STEP_PIN, DIR_PIN);
void setup() {
Serial.begin(9600);
pinMode(Enable_Rear_Right, OUTPUT);
pinMode(Enable_Rear_Left, OUTPUT);
pinMode(Rear_Right_Pin1, OUTPUT);
pinMode(Rear_Right_Pin2, OUTPUT);
pinMode(Rear_Left_Pin1, OUTPUT);
pinMode(Rear_Left_Pin2, OUTPUT);
pinMode(Enable_Front_Right, OUTPUT);
pinMode(Enable_Front_Left, OUTPUT);
pinMode(Front_Right_Pin1, OUTPUT);
pinMode(Front_Right_Pin2, OUTPUT);
pinMode(Front_Left_Pin1, OUTPUT);
pinMode(Front_Left_Pin2, OUTPUT);
stepper.setSpeed(60);
}
void loop() {
if (Serial.available() > 0) {
char command = Serial.read();
switch (command) {
case 'F': moveForward(); break;
case 'B': moveBackward(); break;
case 'L': turnLeft(); break;
case 'R': turnRight(); break;
case 'S': stopCar(); break;
case 'U': stepper.step(STEPS_PER_REV); break;
case 'D': stepper.step(-STEPS_PER_REV); break;
case 'Q': glideLeft(); break;
case 'W': glideRight(); break;
}
}
}
void moveForward() {
digitalWrite(Rear_Right_Pin1, HIGH);
digitalWrite(Rear_Right_Pin2, LOW);
digitalWrite(Rear_Left_Pin1, HIGH);
digitalWrite(Rear_Left_Pin2, LOW);
digitalWrite(Front_Right_Pin1, HIGH);
digitalWrite(Front_Right_Pin2, LOW);
digitalWrite(Front_Left_Pin1, HIGH);
digitalWrite(Front_Left_Pin2, LOW);
analogWrite(Enable_Rear_Right, 255);
analogWrite(Enable_Rear_Left, 255);
analogWrite(Enable_Front_Right, 255);
analogWrite(Enable_Front_Left, 255);
}
void moveBackward() {
digitalWrite(Rear_Right_Pin1, LOW);
digitalWrite(Rear_Right_Pin2, HIGH);
digitalWrite(Rear_Left_Pin1, LOW);
digitalWrite(Rear_Left_Pin2, HIGH);
digitalWrite(Front_Right_Pin1, LOW);
digitalWrite(Front_Right_Pin2, HIGH);
digitalWrite(Front_Left_Pin1, LOW);
digitalWrite(Front_Left_Pin2, HIGH);
analogWrite(Enable_Rear_Right, 255);
analogWrite(Enable_Rear_Left, 255);
analogWrite(Enable_Front_Right, 255);
analogWrite(Enable_Front_Left, 255);
}
void turnLeft() {
digitalWrite(Rear_Right_Pin1, LOW);
digitalWrite(Rear_Right_Pin2, HIGH);
digitalWrite(Rear_Left_Pin1, HIGH);
digitalWrite(Rear_Left_Pin2, LOW);
digitalWrite(Front_Right_Pin1, HIGH);
digitalWrite(Front_Right_Pin2, LOW);
digitalWrite(Front_Left_Pin1, LOW);
digitalWrite(Front_Left_Pin2, HIGH);
analogWrite(Enable_Rear_Right, 255);
analogWrite(Enable_Rear_Left, 255);
analogWrite(Enable_Front_Right, 255);
analogWrite(Enable_Front_Left, 255);
}
void turnRight() {
digitalWrite(Rear_Right_Pin1, HIGH);
digitalWrite(Rear_Right_Pin2, LOW);
digitalWrite(Rear_Left_Pin1, LOW);
digitalWrite(Rear_Left_Pin2, HIGH);
digitalWrite(Front_Right_Pin1, LOW);
digitalWrite(Front_Right_Pin2, HIGH);
digitalWrite(Front_Left_Pin1, HIGH);
digitalWrite(Front_Left_Pin2, LOW);
analogWrite(Enable_Rear_Right, 255);
analogWrite(Enable_Rear_Left, 255);
analogWrite(Enable_Front_Right, 255);
analogWrite(Enable_Front_Left, 255);
}
void stopCar() {
analogWrite(Enable_Rear_Right, 0);
analogWrite(Enable_Rear_Left, 0);
analogWrite(Enable_F