This circuit is designed to control a remote-controlled (RC) car using an Arduino UNO microcontroller, an HC-05 Bluetooth module for wireless communication, and an L298N motor driver to control four DC motors. The system is powered by a 2x 18650 battery pack, and a rocker switch is used to control the power supply to the circuit. The Arduino UNO receives commands via Bluetooth and controls the motors accordingly to move the car forward, backward, turn left, right, or stop.
/*
* Arduino-based Bluetooth Controlled RC Car
* This code allows an Arduino UNO to control an RC car using an HC-05 Bluetooth
* module and an L298N motor driver. The car can be controlled via a Bluetooth
* connection from a smartphone or other Bluetooth-enabled device.
*/
#include <SoftwareSerial.h>
// Bluetooth module pins
const int bluetoothTx = 11;
const int bluetoothRx = 10;
// Motor driver pins
const int motorIn1 = 2;
const int motorIn2 = 3;
const int motorIn3 = 4;
const int motorIn4 = 5;
// Create a software serial port for the Bluetooth module
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
// Initialize serial communication
Serial.begin(9600);
bluetooth.begin(9600);
// Initialize motor driver pins as outputs
pinMode(motorIn1, OUTPUT);
pinMode(motorIn2, OUTPUT);
pinMode(motorIn3, OUTPUT);
pinMode(motorIn4, OUTPUT);
}
void loop() {
// Check if data is available from the Bluetooth module
if (bluetooth.available()) {
char command = bluetooth.read();
Serial.println(command);
// Control the motors based on the received command
switch (command) {
case 'F': // Move forward
digitalWrite(motorIn1, HIGH);
digitalWrite(motorIn2, LOW);
digitalWrite(motorIn3, HIGH);
digitalWrite(motorIn4, LOW);
break;
case 'B': // Move backward
digitalWrite(motorIn1, LOW);
digitalWrite(motorIn2, HIGH);
digitalWrite(motorIn3, LOW);
digitalWrite(motorIn4, HIGH);
break;
case 'L': // Turn left
digitalWrite(motorIn1, LOW);
digitalWrite(motorIn2, HIGH);
digitalWrite(motorIn3, HIGH);
digitalWrite(motorIn4, LOW);
break;
case 'R': // Turn right
digitalWrite(motorIn1, HIGH);
digitalWrite(motorIn2, LOW);
digitalWrite(motorIn3, LOW);
digitalWrite(motorIn4, HIGH);
break;
case 'S': // Stop
digitalWrite(motorIn1, LOW);
digitalWrite(motorIn2, LOW);
digitalWrite(motorIn3, LOW);
digitalWrite(motorIn4, LOW);
break;
}
}
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It sets up a software serial connection to communicate with the HC-05 Bluetooth module and configures the digital pins connected to the L298N motor driver as outputs. The loop
function listens for commands from the Bluetooth module and controls the motors accordingly.