This circuit is designed to control a 4-wheeled robot car via Bluetooth communication. The car is capable of moving in different directions (forward, backward, left, and right) based on commands received from a mobile app. It also features front and back lights that can be toggled on or off, as well as a buzzer for auditory signals. The core of the control system is an Arduino UNO microcontroller, which interfaces with an HC-05 Bluetooth module for wireless communication. The motor driver controls the DC motors responsible for the car's movement, while the capacitors and diodes are used for noise suppression and protecting the circuit from voltage spikes, respectively.
/*
* Arduino Sketch for a 4-wheeled robot car controlled via Bluetooth.
* The car can move forward, backward, left, and right based on commands
* received from a mobile app. It also has front and back lights that can
* be switched on or off via the app.
*/
#include <SoftwareSerial.h>
// Pin definitions
const int LF = 4; // Left Forward
const int LB = 5; // Left Backward
const int RF = 6; // Right Forward
const int RB = 7; // Right Backward
const int frontLight = A0; // Front Light
const int backLight = A2; // Back Light
const int buzzer = A4; // Buzzer
SoftwareSerial BTSerial(0, 1); // RX, TX
void setup() {
// Initialize serial communication
Serial.begin(9600);
BTSerial.begin(9600);
// Initialize pins
pinMode(LF, OUTPUT);
pinMode(LB, OUTPUT);
pinMode(RF, OUTPUT);
pinMode(RB, OUTPUT);
pinMode(frontLight, OUTPUT);
pinMode(backLight, OUTPUT);
pinMode(buzzer, OUTPUT);
// Initial state
digitalWrite(frontLight, LOW);
digitalWrite(backLight, LOW);
digitalWrite(buzzer, LOW);
Serial.println("Car is Ready");
}
void loop() {
if (BTSerial.available()) {
char command = BTSerial.read();
Serial.print("Command: ");
Serial.println(command);
switch (command) {
case 'F':
moveForward();
break;
case 'B':
moveBackward();
break;
case 'L':
turnLeft();
break;
case 'R':
turnRight();
break;
case 'S':
stopCar();
break;
case '1':
digitalWrite(frontLight, HIGH);
break;
case '0':
digitalWrite(frontLight, LOW);
break;
case '3':
digitalWrite(backLight, HIGH);
break;
case '2':
digitalWrite(backLight, LOW);
break;
default:
Serial.println("Unknown command");
break;
}
}
}
void moveForward() {
Serial.println("Moving forward");
digitalWrite(LF, HIGH);
digitalWrite(RF, HIGH);
digitalWrite(LB, LOW);
digitalWrite(RB, LOW);
}
void moveBackward() {
Serial.println("Moving backward");
digitalWrite(LB, HIGH);
digitalWrite(RB, HIGH);
digitalWrite(LF, LOW);
digitalWrite(RF, LOW);
}
void turnLeft() {
Serial.println("Turning left");
digitalWrite(LF, LOW);
digitalWrite(RF, HIGH);
digitalWrite(LB, HIGH);
digitalWrite(RB, LOW);
}
void turnRight() {
Serial.println("Turning right");
digitalWrite(LF, HIGH);
digitalWrite(RF, LOW);
digitalWrite(LB, LOW);
digitalWrite(RB, HIGH);
}
void stopCar() {
Serial.println("Stopping");
digitalWrite(LF, LOW);
digitalWrite(RF, LOW);
digitalWrite(LB, LOW);
digitalWrite(RB, LOW);
}
This code is responsible for interpreting Bluetooth commands and controlling the robot car's movements and features accordingly. It sets up the necessary pins as outputs and initializes the SoftwareSerial library for Bluetooth communication. The loop
function listens for incoming commands and calls the appropriate functions to control the car.