0% found this document useful (0 votes)
13 views3 pages

Bluetooth-Controlled Car Movement Program

This document describes a program to control the movement of a car via Bluetooth. It defines the connections between a Bluetooth module HC-06, an L298N controller, and an Arduino. The program allows controlling the car using commands for forward, left turn, stop, right turn, and reverse sent via Bluetooth.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Bluetooth-Controlled Car Movement Program

This document describes a program to control the movement of a car via Bluetooth. It defines the connections between a Bluetooth module HC-06, an L298N controller, and an Arduino. The program allows controlling the car using commands for forward, left turn, stop, right turn, and reverse sent via Bluetooth.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//Car movement program controlled via Bluetooth - PHYSICS FOR EVERYONE

Connection of the Bluetooth Module HC-06 and the Arduino


ARDUINO Bluetooth HC-06
0 (RX) TX
1 (TX) RX
5V VCC
GND GND
!!Caution!! The TX and RX connections to the Bluetooth module must be disconnected
at the moment the code (Sketch) is uploaded to the Arduino.

L298N Driver Connection


ARDUINO L298N
2 IN1
3 IN2
5 ENA
7 IN3
8 IN4
6 ENB

*/

int IN1 = 2; // IN1 a pin digital 2


int IN2 = 3; IN2 a pin digital 3
int IN3 = 7; // IN3 a pin digital 7
int IN4 = 8; // IN4 a digital pin 8
c

void setup() {

[Link](9600); // initializes the serial port for communication with the Bluetooth pins 0
(RX) and 1 (TX)

pinMode(IN1, OUTPUT); // IN1 as output


pinMode(IN2, OUTPUT); // IN2 as output
pinMode(IN3, OUTPUT); // IN3 as output
pinMode(IN4, OUTPUT); // IN4 as output

void loop() {

if([Link]()>0){ read the bluetooth and store in state


state = [Link]();
}

if(state=='a'){ Front Move Button


Advance(); advance function both motors A and B
}

if(status=='b'){ Left Button


TurnLeft();
}

if(state=='c'){ Stop Button


Stop(); // function that stops both motors
}

if(state=='d'){ Right Button


TurnRight();
}

if(state=='e'){ Reverse Button


Reverse();
}
}

void Advance(){ // function for advance of motor A and B

digitalWrite(IN1, LOW); // IN1 to logical zero


digitalWrite(IN2, HIGH); // IN2 to logic one

digitalWrite(IN3, LOW); // IN3 to logical zero


digitalWrite(IN4, HIGH); // IN4 to logical one
}

void TurnLeft(){ // function for motor B advancement

digitalWrite(IN1, LOW); // IN1 to logical zero


digitalWrite(IN2, LOW); // IN2 to a logical one

digitalWrite(IN3, LOW); // IN3 to low logic


digitalWrite(IN4, HIGH); // IN4 to a logical one
}

void TurnRight(){ // function for motor A advancement

digitalWrite(IN1, LOW); // IN1 to logical zero


digitalWrite(IN2, HIGH); // IN2 to logical one

digitalWrite(IN3, LOW); // IN3 to logical zero


digitalWrite(IN4, LOW); // IN4 to logical one
}

void Stop(){ // function that stops both motors


digitalWrite(IN1, LOW); // IN1 to logical zero
digitalWrite(IN2, LOW); // IN2 to a logical one

digitalWrite(IN3, LOW); // IN3 to logical zero


digitalWrite(IN4, LOW); // IN4 to logical one
}

void Reverse(){ // function for reverse of motor A and B

digitalWrite(IN1, HIGH); // IN1 to logical zero


digitalWrite(IN2, LOW); // IN2 to logical one

digitalWrite(IN3, HIGH); // IN3 to logic zero


digitalWrite(IN4, LOW); // IN4 to logical one
}

Common questions

Powered by AI

It is crucial to disconnect the TX and RX connections to the Bluetooth module before uploading the code to the Arduino. This is necessary to prevent any interference with the serial communication used during the upload process .

The "TurnLeft" function involves setting IN1, IN2, and IN3 to LOW and IN4 to HIGH. This operation ensures that only one motor (motor B) is active, causing the car to pivot by moving the wheels on one side, facilitating a left turn. The approach uses digitalWrite to assign logic levels to control the motor actions specifically for a left turn .

To stop the car's motors, the program must execute the "Stop" function, which sets all pins (IN1, IN2, IN3, IN4) to LOW. This action ceases motor activity, ensuring that both motors come to a halt, thus stopping the car .

The use of digitalWrite is significant because it allows direct control over the HIGH and LOW states of digital pins connected to the motor driver. This control is crucial for determining the direction and state of the motors, enabling precise movement control such as advancing, turning, stopping, and reversing .

Pins IN1, IN2, IN3, and IN4 are configured as output pins and are used to control the movements of the motors connected to the L298N motor driver. IN1 and IN2 control one motor, while IN3 and IN4 control the other. By sending HIGH or LOW signals to these pins, different motor functions such as advance, reverse, stop, left turn, and right turn can be achieved .

The "Reverse" function reverses the direction of both motors A and B. It achieves this by setting IN1 and IN3 to HIGH and IN2 and IN4 to LOW. This logic configuration reverses the rotation direction of the motors, causing the car to move backward .

The Arduino program establishes communication with the Bluetooth module by initializing serial communication using Serial.begin(9600). This sets the data rate for the serial communication between the Bluetooth module and the Arduino, allowing the Arduino to read incoming Bluetooth signals and write data to the Bluetooth module, enabling car control .

The "Advance" function sets IN1 and IN3 to LOW and IN2 and IN4 to HIGH. This configuration allows both motors A and B to move forward simultaneously, effectively advancing the car. This function uses digitalWrite to send logic signals to the respective pins, ensuring that the motors rotate in the forward direction .

The Arduino code uses conditional statements to switch between motor states based on Bluetooth input. For moving forward, it executes the "Advance" function by setting IN1 to LOW, IN2 to HIGH, IN3 to LOW, and IN4 to HIGH. To stop, it executes the "Stop" function by setting all these pins to LOW. This setup enables seamless switching between advancing and stopping based on Bluetooth commands .

The Arduino continuously checks for available Bluetooth input using Serial.available(). When a Bluetooth signal is received, it is read using Serial.read() and stored in a variable. The program then compares this input against predefined characters ('a', 'b', 'c', 'd', 'e') and executes the corresponding function—Advance, TurnLeft, Stop, TurnRight, Reverse—to adjust the car's movement accordingly .

You might also like