Bluetooth-Controlled Car Movement Program
Bluetooth-Controlled Car Movement Program
*/
void setup() {
[Link](9600); // initializes the serial port for communication with the Bluetooth pins 0
(RX) and 1 (TX)
void loop() {
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 .