

This document provides a detailed overview of a circuit designed to control four hobby motors using an L293D motor driver shield and an HC-05 Bluetooth module. The circuit allows for remote control of the motors via Bluetooth communication. The L293D driver shield is connected to the motors and the Bluetooth module, which receives commands to control the motors' movements.
#include <AFMotor.h>
// Create motor objects
AF_DCMotor motor1(1); // Motor connected to M1
AF_DCMotor motor2(2); // Motor connected to M2
AF_DCMotor motor3(3); // Motor connected to M3
AF_DCMotor motor4(4); // Motor connected to M4
char command = 'S'; // Default command is Stop
void setup() {
Serial.begin(9600); // Initialize serial communication
// Set initial motor speed to 0
motor1.setSpeed(0);
motor2.setSpeed(0);
motor3.setSpeed(0);
motor4.setSpeed(0);
}
void loop() {
if (Serial.available() > 0) {
command = Serial.read(); // Read the command from Bluetooth
}
// Execute the command
switch (command) {
case 'F': // Move forward
motor1.setSpeed(255);
motor1.run(FORWARD);
motor2.setSpeed(255);
motor2.run(FORWARD);
motor3.setSpeed(255);
motor3.run(FORWARD);
motor4.setSpeed(255);
motor4.run(FORWARD);
break;
case 'B': // Move backward
motor1.setSpeed(255);
motor1.run(BACKWARD);
motor2.setSpeed(255);
motor2.run(BACKWARD);
motor3.setSpeed(255);
motor3.run(BACKWARD);
motor4.setSpeed(255);
motor4.run(BACKWARD);
break;
case 'L': // Turn left
motor1.setSpeed(255);
motor1.run(BACKWARD);
motor2.setSpeed(255);
motor2.run(BACKWARD);
motor3.setSpeed(255);
motor3.run(FORWARD);
motor4.setSpeed(255);
motor4.run(FORWARD);
break;
case 'R': // Turn right
motor1.setSpeed(255);
motor1.run(FORWARD);
motor2.setSpeed(255);
motor2.run(FORWARD);
motor3.setSpeed(255);
motor3.run(BACKWARD);
motor4.setSpeed(255);
motor4.run(BACKWARD);
break;
case 'S': // Stop
motor1.setSpeed(0);
motor1.run(RELEASE);
motor2.setSpeed(0);
motor2.run(RELEASE);
motor3.setSpeed(0);
motor3.run(RELEASE);
motor4.setSpeed(0);
motor4.run(RELEASE);
break;
}
}
This code initializes the motors and sets up serial communication. It reads commands from the Bluetooth module and controls the motors accordingly. The commands include moving forward, backward, turning left, turning right, and stopping.