This circuit is designed to control multiple motors using an Arduino UNO microcontroller and a Bluetooth HC-06 module. The L298N motor driver is utilized to drive the motors, which are equipped with reducers for enhanced torque. The system allows for remote control of the motors via Bluetooth commands, enabling functionalities such as moving forward, backward, turning, and stopping. An LED indicator is also included to provide visual feedback.
/*
* This Arduino sketch controls motors via Bluetooth commands.
* The HC-06 Bluetooth module receives commands to control the motors
* through the L298N motor driver. An LED is used as an indicator.
*/
// Pin definitions
const int motorPin1 = 13; // IN1
const int motorPin2 = 12; // IN2
const int motorPin3 = 11; // IN3
const int motorPin4 = 10; // IN4
const int ledPin = 9; // LED cathode
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize motor control pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
// Initialize LED pin as output
pinMode(ledPin, OUTPUT);
// Turn off motors and LED initially
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
digitalWrite(ledPin, LOW);
}
void loop() {
// Check if data is available on the serial port
if (Serial.available() > 0) {
char command = Serial.read();
// Process the received command
switch (command) {
case 'F': // Move forward
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
break;
case 'B': // Move backward
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
break;
case 'L': // Turn left
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
break;
case 'R': // Turn right
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
break;
case 'S': // Stop
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
break;
case 'O': // Turn on LED
digitalWrite(ledPin, HIGH);
break;
case 'f': // Turn off LED
digitalWrite(ledPin, LOW);
break;
default:
// Unknown command
break;
}
}
}
This documentation provides a comprehensive overview of the circuit, detailing the components used, their connections, and the code that drives the functionality.