Choi HyunBeengledel
Published © GPL3+

Software Serial Bluetooth RC Car

Bongilcheon high school created this RC car.

AdvancedShowcase (no instructions)30 minutes3,393
Software Serial Bluetooth RC Car

Things used in this project

Story

Read more

Code

Untitled file

Arduino
#include <SoftwareSerial.h>
SoftwareSerial BTSerial (11, 12);
// BTSerial (Rx, Tx); Based on the Aduno board
// Connect the pin of 11 pin of Arduino board to TX pin of Bluetooth module, connect Pin 12 and RX
#define EN1 3 // Motor A to motor driver A-1A pin connection
#define EN2 4 // Motor A to Motor Driver A-1B Pin Connection
#define EN3 6 // motor B and motor driver B-1A pin connection
#define EN4 7 // motor B and motor driver b-1B pin connection
int carSpeed = 200; // Speed of RC car
void setup () {
BTSerial.begin (9600); // Communication with Bluetooth module via software serial communication
// Initialize both pins of motor A to output mode
pinMode (EN1, OUTPUT);
pinMode (EN2, OUTPUT);
// Initialize both pins of motor B to output mode
pinMode (EN3, OUTPUT);
pinMode (EN4, OUTPUT);
}
void loop () {
if (BTSerial.available ()) {
  char command = BTSerial.read (); // Save command received in Bluetooth to command
  if (command == 'F' || command == 'f') {
    // function call to advance RC car when receiving F or f as input
    moving_forward ();
  }
  else if (command == 'B' || command == 'b') {
    // function call to reverse RC car when receiving B or b as input
    moving_backward ();
  }
  else if (command == 'L' || command == 'l') {
    // function call that rotates RC car left when receiving L or l as input
    moving_left ();
  }
  else if (command == 'R' || command == 'r') {
    // function call that rotates RC car right when receiving R or r as input
    moving_right ();
  }
  else if (command == 'S' || command == 's') {
    // Function call to stop RC car when receiving S or s as input
    stop_moving ();
  }
  else {
    // Function call to stop RC car when not recognizing command
    stop_moving ();
  }
}
// Time delay
delay (100);
}
void moving_forward () {
// Rotate motor A forward
digitalWrite (EN1, HIGH);
digitalWrite (EN2, LOW);
// Rotate motor B forward
digitalWrite (EN3, HIGH);
digitalWrite (EN4, LOW);
}
void moving_backward () {
// Rotate motor A in the reverse direction
digitalWrite (EN1, LOW);
digitalWrite (EN2, HIGH);
// Rotate motor B in the reverse direction
digitalWrite (EN3, LOW);
digitalWrite (EN4, HIGH);
}
void moving_left () {
// Rotate motor A forward
digitalWrite (EN1, HIGH);
digitalWrite (EN2, LOW);
// Rotate motor B in the reverse direction
digitalWrite (EN3, LOW);
digitalWrite (EN4, HIGH);
}
void moving_right () {
// Rotate motor A in the reverse direction
digitalWrite (EN1, LOW);
digitalWrite (EN2, HIGH);
// Rotate motor B forward
digitalWrite (EN3, HIGH);
digitalWrite (EN4, LOW);
}
void stop_moving () {
digitalWrite (EN1, LOW);
digitalWrite (EN2, LOW);
digitalWrite (EN3, LOW);
digitalWrite (EN4, LOW);
}

Credits

Choi HyunBeen

Choi HyunBeen

5 projects • 4 followers
gledel

gledel

100 projects • 115 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"

Comments