Arduino ESP32 Bluetooth Remote

In the previous lesson, we built an Arduino Bluetooth RC car. In this lesson, we will create an RC remote or transmitter to control the RC car using an ESP32 development board, without the need for an external Bluetooth module.



In this project, we will use 4 push buttons to control forward, backward, left, and right movements, along with a potentiometer to control the speed. Additionally, we’ll include an LED to indicate the pairing status between the RC car and the transmitter.

Required Components:

  • ESP32 development board
  • 4 push buttons (for forward, backward, left, and right control)
  • Potentiometer (for speed control)
  • LED (for pairing indication)
  • Breadboard
  • Jumper wires
  • Resistors (for  LED)


making circuit 

In this lesson, we will make the RC transmitter in a simple way. It won’t be a full joystick, but it will demonstrate the basic functionality. You can 3D print it or shape it however you like to resemble a joystick. This lesson will help you understand how an RC transmitter works.




We'll use a breadboard to assemble the circuit, which makes it simple to build. The circuit diagram is provided for guidance. Assemble the push buttons, potentiometer, and LED as shown in the diagram.



As shown in the image, assemble the circuit and power it up using a fully charged 3.7V battery. Note that if the battery voltage drops below 3.9V, the ESP32 will not power on, as it requires 5V to operate. So, ensure you're using a fully charged 3.7V battery. 



After assembling the circuit, connect the ESP32 to your PC via USB to upload the code and establish the connection.

Arduino code

#include <BluetoothSerial.h>

String slaveName = "RC-CAR"; // Change this to the real name
const char *pin = "1234"; 

BluetoothSerial SerialBT;

// Define pin connections
#define FORWARD_BUTTON_PIN   32
#define BACKWARD_BUTTON_PIN  27
#define LEFT_BUTTON_PIN      26
#define RIGHT_BUTTON_PIN     17
#define SPEED_POT_PIN        15
#define CONNECT_LED_PIN      2   

char prespeedCommand = 5;

void setup() {
  bool connected;
  Serial.begin(115200);
  SerialBT.begin("RC-Remote", true);  // Set the Bluetooth name for the remote

  // Set button pins as inputs
  pinMode(FORWARD_BUTTON_PIN, INPUT_PULLUP);
  pinMode(BACKWARD_BUTTON_PIN, INPUT_PULLUP);
  pinMode(LEFT_BUTTON_PIN, INPUT_PULLUP);
  pinMode(RIGHT_BUTTON_PIN, INPUT_PULLUP);

  // Set LED pin as output
  pinMode(CONNECT_LED_PIN, OUTPUT);
  digitalWrite(CONNECT_LED_PIN, LOW);  // Turn off LED initially

  // Try connecting to the car
  Serial.println("Scanning for RC-CAR...");
  SerialBT.setPin(pin);
  connected = SerialBT.connect(slaveName);

  if (connected) {
    Serial.println("Connected Successfully!");
  } else {
    while (!SerialBT.connected(10000)) {
      Serial.println("Failed to connect. Make sure remote device is available and in range");
    }
  }

}

void loop() {
  // Read the potentiometer for speed control
  int potValue = analogRead(SPEED_POT_PIN);

  // Send the speed command if connected
  if (SerialBT.connected()) {
    digitalWrite(CONNECT_LED_PIN, HIGH);  // Keep LED ON if connected

    // Send speed value mapped to characters '0' to 'q'
    char speedCommand = map(potValue, 0, 4096, '0', '9');

    if (prespeedCommand != speedCommand) {
      SerialBT.write(speedCommand);
      prespeedCommand = speedCommand;
    }

    // Check each button for movement commands
    if (digitalRead(FORWARD_BUTTON_PIN) == LOW) {
      SerialBT.write('F');  // Move Forward
      delay(100);
    } else if (digitalRead(BACKWARD_BUTTON_PIN) == LOW) {
      SerialBT.write('B');  // Move Backward
      delay(100);
    } else if (digitalRead(LEFT_BUTTON_PIN) == LOW) {
      SerialBT.write('L');  // Turn Left
      delay(100);
    } else if (digitalRead(RIGHT_BUTTON_PIN) == LOW) {
      SerialBT.write('R');  // Turn Right
      delay(100);
    } else {
      SerialBT.write('S');  // Stop if no button is pressed
    }
  } else {
    digitalWrite(CONNECT_LED_PIN, LOW);  // Turn OFF LED if disconnected
    // Serial.println("Attempting to reconnect...");

    // Attempt to reconnect if disconnected
    if (SerialBT.connect("RC-CAR")) {
      Serial.println("Reconnected to RC-CAR!");
      digitalWrite(CONNECT_LED_PIN, HIGH);  // Turn on LED if reconnected
    }
  }

  delay(50);  // Adjust delay for smoother control
}

Working 






Youtube video










Post a Comment

Previous Post Next Post