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

Arduino Mega 2560 Bluetooth-Controlled Motor Driver System

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 Bluetooth-Controlled Motor Driver System

Circuit Documentation

Summary

This circuit involves an Arduino Mega 2560 microcontroller, an HC-06 Bluetooth module, an L298N DC motor driver, four DC motors, and a 9V battery. The Arduino Mega 2560 controls the motors via the L298N motor driver, and the HC-06 Bluetooth module allows for wireless communication. The 9V battery powers the motor driver and motors.

Component List

  1. Arduino Mega 2560

    • Description: A microcontroller board based on the ATmega2560.
    • Pins: IOREF, RESET, 3V3, 5V, GND, VIN, A0-A15, D0-D53, AREF, SDA, SCL
  2. HC-06 Bluetooth Module

    • Description: A Bluetooth module for wireless communication.
    • Pins: RXD, TXD, GND, VCC
  3. L298N DC Motor Driver

    • Description: A dual H-Bridge motor driver.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
  4. DC Motor

    • Description: A simple DC motor.
    • Pins: negative, positive
  5. 9V Battery

    • Description: A 9V battery for power supply.
    • Pins: -, +

Wiring Details

Arduino Mega 2560

HC-06 Bluetooth Module

L298N DC Motor Driver

DC Motors

9V Battery

Code Documentation

const int motorA1  = 5;
const int motorA2  = 7;
const int motorB1  = 6;
const int motorB2  = 4;
int i=0; 
int j=0;
int state;
int vSpeed=255;

void setup() {
    pinMode(motorA1, OUTPUT);
    pinMode(motorA2, OUTPUT);
    pinMode(motorB1, OUTPUT);
    pinMode(motorB2, OUTPUT);    
    Serial.begin(9600);
}

void loop() {
    if(Serial.available() > 0){     
      state = Serial.read();   
    }
  
    if (state == '0'){
      vSpeed=0;
    } else if (state == '1'){
      vSpeed=100;
    } else if (state == '2'){
      vSpeed=180;
    } else if (state == '3'){
      vSpeed=200;
    } else if (state == '4'){
      vSpeed=255;
    }

    if (state == 'F') {
      analogWrite(motorA1, vSpeed);
      analogWrite(motorA2, 0);
      analogWrite(motorB1, vSpeed);  
      analogWrite(motorB2, 0);
    } else if (state == 'A') {
      analogWrite(motorA1,vSpeed );
      analogWrite(motorA2, 0);  
      analogWrite(motorB1, 100);
      analogWrite(motorB2, 0); 
    } else if (state == 'B') {
      analogWrite(motorA1, 100);
      analogWrite(motorA2, 0); 
      analogWrite(motorB1, vSpeed);
      analogWrite(motorB2, 0); 
    } else if (state == 'C') {
      analogWrite(motorA1, 0);
      analogWrite(motorA2, vSpeed); 
      analogWrite(motorB1, 0);
      analogWrite(motorB2, vSpeed); 
    } else if (state == 'D') {
      analogWrite(motorA1, 0);
      analogWrite(motorA2, 100); 
      analogWrite(motorB1, 0);
      analogWrite(motorB2, vSpeed); 
    } else if (state == 'F') {
      analogWrite(motorA1, vSpeed);
      analogWrite(motorA2, 150); 
      analogWrite(motorB1, 0);
      analogWrite(motorB2, 0); 
    } else if (state == 'G') {
      analogWrite(motorA1, 0);
      analogWrite(motorA2, 0); 
      analogWrite(motorB1, vSpeed);
      analogWrite(motorB2, 150);     
    } else if (state == 'H'){
      analogWrite(motorA1, 0);
      analogWrite(motorA2, 0); 
      analogWrite(motorB1, 0);
      analogWrite(motorB2, 0);
    }  
}

This code is for the Arduino Mega 2560 microcontroller. It sets up the pins for controlling the motors and reads commands from the serial input to control the speed and direction of the motors. The setup function initializes the pins and the serial communication. The loop function continuously checks for serial input and adjusts the motor speeds and directions based on the received commands.