Header Ads Widget

How to Make Esp32 Bluetooth car | Esp32 project

 in this section, we discuss how to make an Esp32 Bluetooth car 

This article will explain how to make a Bluetooth car with ESP32.

The Espresso ESP32 is a low-cost Wi-Fi and Bluetooth-enabled microcontroller that targets the Internet of Things (IoT) market. It is based on a Tensilica Tensa LX6 microprocessor, clocked at 160 MHz, and features an integrated Wi-Fi 802.11 b/g/n and Bluetooth Classic/LE co-processor.

The Esp32 Bluetooth car is a car that a Bluetooth can control enabled device. The device can be any phone or computer with Bluetooth capability.

The Esp32 Bluetooth car has an Arduino microcontroller, which is the circuit's brain and controls the motor's speed. It also has a servo, which controls the steering wheel, and a DC motor, which powers the wheels.

This project requires some soldering skills, but it's easy and many people have built it.

How to Make Esp32 Bluetooth car circuit:


How to Make Esp32 Bluetooth car code:


#include "BluetoothSerial.h"


#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run
`make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

char receivedChar;

const int MR1 = 12; //ESP32 pins (MR=Right Motor) (ML=Left Motor) (1=Forward) (2=Backward)
const int MR2 = 14; 
const int ML1 = 27;
const int ML2 = 26;
int enable1Pin = 25;
int enable2Pin = 32;

const int freq = 30000;
const int pwmChannel = 0;
const int resolution = 8;

int dutyCycle = 180; // change motor speed what you want 



void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32_BT"); //You can change your Bluetooth device name
  
  pinMode(MR1, OUTPUT); 
  pinMode(MR2, OUTPUT);
  pinMode(ML1, OUTPUT);
  pinMode(ML2, OUTPUT);
  pinMode(enable1Pin, OUTPUT);
  pinMode(enable2Pin, OUTPUT);
  
  ledcSetup(pwmChannel, freq, resolution);
  ledcAttachPin(enable1Pin, pwmChannel);
  ledcAttachPin(enable2Pin, pwmChannel);
}

void Forward(){
      digitalWrite(MR1,HIGH);//MOVE FRONT
      digitalWrite(MR2,LOW); //MOVE BACK
      digitalWrite(ML1,LOW);//MOVE BACK
      digitalWrite(ML2,HIGH);//MOVE FRONT
      
}
void Backward(){
      digitalWrite(MR1,LOW);
      digitalWrite(MR2,HIGH);
      digitalWrite(ML1,HIGH);
      digitalWrite(ML2,LOW);
}
void Left(){
      digitalWrite(MR1,HIGH);
      digitalWrite(MR2,LOW);
      digitalWrite(ML1,HIGH);
      digitalWrite(ML2,LOW);
}
void Right(){
      digitalWrite(MR1,LOW);
      digitalWrite(MR2,HIGH);
      digitalWrite(ML1,LOW);
      digitalWrite(ML2,HIGH);
}
void Stop(){
      digitalWrite(MR1,LOW); 
      digitalWrite(MR2,LOW);
      digitalWrite(ML1,LOW); 
      digitalWrite(ML2,LOW); 
}
void loop() {
   ledcWrite(pwmChannel, dutyCycle);
   ledcWrite(pwmChannel, dutyCycle);

   if (SerialBT.available()) {
   receivedChar = SerialBT.read();
     Serial.println(receivedChar);
  
  }
      
    
    if(receivedChar == 'F')
    {
      Forward();
       
    }
    if(receivedChar == 'B')
    {
 
      Backward(); 
    }         
     if(receivedChar == 'L')
    {

      Left();
    }        
    if(receivedChar == 'R')
    {

      Right(); 
    }
    if(receivedChar == 'S')
    {
      Stop();
    }
    delay(20);
  }
  

Post a Comment

0 Comments