Magicbit
Published

Bluetooth Control Car Using Magicbit (ESP32)

In this tutorial we will learn about how to make Bluetooth control remote car using only Magicbit

BeginnerProtip1,909
Bluetooth Control Car Using Magicbit (ESP32)

Things used in this project

Hardware components

Magicbit
×1
gear motors 3V-6V DC and wheels
×1
18650 Li-ion battery 3.7V
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Bluetooth car app

Story

Read more

Custom parts and enclosures

chassy design

Schematics

Schematic

Code

Arduino code of bluetooth car

Arduino
read and understand the code
#include "BluetoothSerial.h" //Header File for Serial Bluetooth
BluetoothSerial ESP_BT; //Object for Bluetooth
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4

Adafruit_SSD1306 display(128, 64);
String incoming;// varible store received data
int M1A = 17; // motor pins
int M1B = 16;
int M2A = 27;
int M2B = 18;

void setup() {
  Serial.begin(9600);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(1000);
  display.clearDisplay();

  Serial.begin(9600); //Start Serial monitor in 9600
  ESP_BT.begin("ESP32_Blutooth_car"); //Name of your Bluetooth Signal
  Serial.println("Bluetooth Device is Ready to Pair");
  pinMode(M1A, OUTPUT); // configure outputs
  pinMode(M1B, OUTPUT);
  pinMode(M2A, OUTPUT);
  pinMode(M2B, OUTPUT);

}

void loop() {

  if (ESP_BT.available()) //Check if we receive anything from Bluetooth
  {
    incoming = char(ESP_BT.read()); //Read what we received
  }
  Serial.println(incoming);
  if (incoming == "F") { // forward
    Serial.println("Forward");
    Display("Forward");
    Forward();
  }
  else if (incoming == "B") { // reverse
    Serial.println("Reverse");
    Display("Reverse");
    Backward();
  }
  else if (incoming == "R") { //turn right
    Serial.println("Right");
    Display("Right");
    Right();
  }
  else if (incoming == "L") { // turn left
    Serial.println("Left");
    Display("Left");
    Left();
  }



  else {
    Stop();

    Display("Stop");
  }
  delay(20);
}

void Forward() {

  digitalWrite(M1A, HIGH);
  digitalWrite(M1B, LOW);
  digitalWrite(M2A, HIGH);
  digitalWrite(M2B, LOW);

}

void Backward() {

  digitalWrite(M1B, HIGH);
  digitalWrite(M1A, LOW);
  digitalWrite(M2B, HIGH);
  digitalWrite(M2A, LOW);

}
void Right() {

  digitalWrite(M1A, HIGH);
  digitalWrite(M1B, LOW);
  digitalWrite(M2B, HIGH);
  digitalWrite(M2A, LOW);

}
void Left() {

  digitalWrite(M1B, HIGH);
  digitalWrite(M1A, LOW);
  digitalWrite(M2A, HIGH);
  digitalWrite(M2B, LOW);

}

void Stop() {
  digitalWrite(M1B, LOW);
  digitalWrite(M1A, LOW);
  digitalWrite(M2A, LOW);
  digitalWrite(M2B, LOW);

}


void Display(String commond) { // display data
  display.clearDisplay();

  display.setTextSize(3);             // Normal 1:1 pixel scale
  display.setTextColor(WHITE);        // Draw white text
  display.setCursor(0, 20);            // Start at top-left corner
  display.println(commond);
  display.display();

}

Credits

Magicbit
57 projects • 35 followers
Magicbit is an integrated development platform based on ESP32 for learning, prototyping, coding, electronics, robotics, IoT and more.
Contact

Comments

Please log in or sign up to comment.