This circuit is designed to control a car using Bluetooth technology. It consists of an Arduino UNO microcontroller that interfaces with a Bluetooth HC-06 module for wireless communication and an L298N DC motor driver to control two hobby motors. The motors are powered by 9V batteries connected through a 2.1mm Barrel Jack with Terminal Block. The Arduino UNO receives commands via Bluetooth and drives the motors to move the car forward, backward, turn left, turn right, or stop.
/*
* Arduino Sketch for controlling a car using Bluetooth technology.
* This code reads commands from the Serial input (Bluetooth module) and
* controls the car's movement accordingly. The car can move forward,
* backward, turn left, turn right, and stop based on the received commands.
*/
int Input_Pin_4 = 4; // Connected to L298N IN4
int Input_Pin_3 = 5; // Connected to L298N IN3
int Input_Pin_2 = 6; // Connected to L298N IN2
int Input_Pin_1 = 7; // Connected to L298N IN1
char Value;
void setup() {
pinMode(Input_Pin_4, OUTPUT); // Digital pin 4
pinMode(Input_Pin_3, OUTPUT); // Digital pin 5
pinMode(Input_Pin_2, OUTPUT); // Digital pin 6
pinMode(Input_Pin_1, OUTPUT); // Digital pin 7
Serial.begin(9600);
}
void loop() {
while (Serial.available() > 0) {
Value = Serial.read();
Serial.println(Value);
}
if (Value == 'F') {
// Move Forward
digitalWrite(Input_Pin_1, HIGH);
digitalWrite(Input_Pin_2, LOW);
digitalWrite(Input_Pin_3, HIGH);
digitalWrite(Input_Pin_4, LOW);
} else if (Value == 'B') {
// Move Backward
digitalWrite(Input_Pin_1, LOW);
digitalWrite(Input_Pin_2, HIGH);
digitalWrite(Input_Pin_3, LOW);
digitalWrite(Input_Pin_4, HIGH);
} else if (Value == 'L') {
// Turn Left
digitalWrite(Input_Pin_1, LOW);
digitalWrite(Input_Pin_2, LOW);
digitalWrite(Input_Pin_3, HIGH);
digitalWrite(Input_Pin_4, LOW);
} else if (Value == 'R') {
// Turn Right
digitalWrite(Input_Pin_1, HIGH);
digitalWrite(Input_Pin_2, LOW);
digitalWrite(Input_Pin_3, LOW);
digitalWrite(Input_Pin_4, LOW);
} else if (Value == 'S') {
// Stop
digitalWrite(Input_Pin_1, LOW);
digitalWrite(Input_Pin_2, LOW);
digitalWrite(Input_Pin_3, LOW);
digitalWrite(Input_Pin_4, LOW);
}
}
This code is designed to be uploaded to the Arduino UNO microcontroller. It sets up the digital pins connected to the L298N motor driver as outputs and initializes serial communication for receiving Bluetooth commands. The loop function reads the incoming serial data and controls the motor driver to move the car based on the received command character.