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

Robotics Code

It is a Robotics code Project name- Bluetooth control bot

Uploaded by

Iamin Himel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Robotics Code

It is a Robotics code Project name- Bluetooth control bot

Uploaded by

Iamin Himel
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

// Define motor control pins

const int motor1Pin1 = 3; // IN1 on the L298N

const int motor1Pin2 = 4; // IN2 on the L298N

const int motor2Pin1 = 5; // IN3 on the L298N

const int motor2Pin2 = 6; // IN4 on the L298N

void setup() {

// Set all motor control pins to output

pinMode(motor1Pin1, OUTPUT);

pinMode(motor1Pin2, OUTPUT);

pinMode(motor2Pin1, OUTPUT);

pinMode(motor2Pin2, OUTPUT);

// Start serial communication

Serial.begin(9600);

void loop() {

// Check if data is available to read from Bluetooth

if (Serial.available() > 0) {

char command = Serial.read(); // Read the incoming data as a character

switch(command) {

case 'F': // Forward

forward();

break;

case 'B': // Backward


backward();

break;

case 'L': // Left

left();

break;

case 'R': // Right

right();

break;

case 'G': // Forward Left

forwardLeft();

break;

case 'I': // Forward Right

forwardRight();

break;

case 'H': // Backward Left

backwardLeft();

break;

case 'J': // Backward Right

backwardRight();

break;

case 'S': // Stop

stopCar();

break;

}
}

// in this code the right motor of the rc car is motor1 and the left motor is motor2

void forward() {

digitalWrite(motor1Pin1, HIGH); // right motor

digitalWrite(motor1Pin2, LOW);

digitalWrite(motor2Pin1, HIGH); //left motor

digitalWrite(motor2Pin2, LOW);

void backward() {

digitalWrite(motor1Pin1, LOW);

digitalWrite(motor1Pin2, HIGH);

digitalWrite(motor2Pin1, LOW);

digitalWrite(motor2Pin2, HIGH);

void left() {

digitalWrite(motor1Pin1, HIGH);

digitalWrite(motor1Pin2, LOW);

digitalWrite(motor2Pin1, LOW);

digitalWrite(motor2Pin2, HIGH);

}
void right() {

digitalWrite(motor1Pin1, LOW);

digitalWrite(motor1Pin2, HIGH);

digitalWrite(motor2Pin1, HIGH);

digitalWrite(motor2Pin2, LOW);

void forwardLeft() {

digitalWrite(motor1Pin1, HIGH);

digitalWrite(motor1Pin2, LOW);

digitalWrite(motor2Pin1, LOW);

digitalWrite(motor2Pin2, LOW);

void forwardRight() {

digitalWrite(motor1Pin1, LOW);

digitalWrite(motor1Pin2, LOW);

digitalWrite(motor2Pin1, HIGH);

digitalWrite(motor2Pin2, LOW);

void backwardLeft() {

digitalWrite(motor1Pin1, LOW);

digitalWrite(motor1Pin2, HIGH);

digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);

void backwardRight() {

digitalWrite(motor1Pin1, LOW);

digitalWrite(motor1Pin2, LOW);

digitalWrite(motor2Pin1, LOW);

digitalWrite(motor2Pin2, HIGH);

void stopCar() {

digitalWrite(motor1Pin1, LOW);

digitalWrite(motor1Pin2, LOW);

digitalWrite(motor2Pin1, LOW);

digitalWrite(motor2Pin2, LOW);

You might also like