0% found this document useful (0 votes)
6 views

Chat GPT code

The document contains an Arduino sketch for controlling a Bluetooth-enabled car. It defines functions for moving the car forward, backward, turning left, turning right, and stopping, using specific digital pins for motor control. The setup initializes Bluetooth communication and ensures the car starts in a stopped state.

Uploaded by

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

Chat GPT code

The document contains an Arduino sketch for controlling a Bluetooth-enabled car. It defines functions for moving the car forward, backward, turning left, turning right, and stopping, using specific digital pins for motor control. The setup initializes Bluetooth communication and ensures the car starts in a stopped state.

Uploaded by

Mamtha K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <SoftwareSerial.

h>

SoftwareSerial BT(10, 11); // RX, TX (for Bluetooth module)

#define IN1 6
#define IN2 7
#define IN3 8
#define IN4 9

void setup() {
Serial.begin(9600);
BT.begin(9600); // Start Bluetooth communication

pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

stopCar(); // Ensure car starts in stopped state


}

void loop() {
if (BT.available()) {
char BT.available
Serial.println(command); // Debugging output

switch (command) {
case 'F': forward(); break;
case 'B': backward(); break;
case 'L': turnLeft(); break;
case 'R': turnRight(); break;
case 'S': stopCar(); break;
}
}
}

void forward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}

void backward() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}

void turnLeft() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}

void turnRight() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}

void stopCar() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}

You might also like