In this project, I used the Arduino Uno as the main component to control the car. I utilized a control circuit and an ultrasonic sensor, and everything was working fine. The problem arose when I wanted to use the ESP32 to take advantage of Bluetooth for mobile control. I also wanted to equip it with a voice control system. However, when I connected the module to the Arduino and activated Bluetooth, I was able to control it via the mobile phone, but there was no response or signal from the car. What is the solution?
Welcome to the forum
We are going to need much more information in order to provide help
Start by posting the sketches used on each board, using code tags when you do, and a schematic of your project showing how the components are connected and powered. A ‘photo of a clear hand drawn circuit is good enough but ‘photos of your actual wiring usually are not
Incidentally, did you consider using the ESP32 as the only board rather than using two ?
Yes, I initially tried to use the ESP32, but the ports were not sufficient because I am using a multi-piece. I will clarify the connections here in a better message.
ESP32 Bluetooth with Arduino Uno
TX ESP32 RX Arduino
RX ESP32 TX Arduino
The Arduino controls all components .
Joystick
VCC 5V
GND GND
VRx A0
VRy A1
Ultrasonic Sensor HC-SR04
VCC 5V Arduino
GND Arduino
I used two sensors
Trig D4, Echo D7
TRIG D12, Echo D13
DC Motors with L298N
ENA D5
ENB D6
IN1 D8
IN2 D9
IN3 D10
IN4 D11
Common GND between Arduino and power source
Comprehensive ground connection
GND for everything connected together: Arduino, ESP32, sensors, L298N, battery.
I don’t understand what you mean by that
Doesn't open to me.. More than one piece, but what?
Here are the connections I made for the car with the components, and the ESP32 is connected to the TX and RX ports specific to the Arduino. I mean that the TX and RX ports found on the ESP were also connected to the same ports on the Arduino.
What I mean is that everything was working fine without the ESP and the Bluetooth feature, but when I connected the ESP to link the Bluetooth, there was no response from the Bluetooth control program.
And this is the code:
#include <Arduino.h>
int ENA = 5;
int ENB = 6;
int IN1 = 8;
int IN2 = 9;
int IN3 = 10;
int IN4 = 11;
int VRx = A0;
int VRy = A1;
int trigRight = 4;
int echoRight = 7;
int trigLeft = 12;
int echoLeft = 13;
char btCommand = 0;
unsigned long lastBTtime = 0;
const unsigned long BT_TIMEOUT = 3000; // 3
int motorSpeed = 200;
int safeDistance = 15;
void setup() {
Serial.begin(9600);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(INPUT_PULLUP);
pinMode(trigRight, OUTPUT);
pinMode(echoRight, INPUT);
pinMode(trigLeft, OUTPUT);
pinMode(echoLeft, INPUT);
Serial.println("System Ready!");
}
long readDistance(int trigPin, int echoPin) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
long distance = duration * 0.034 / 2;
return distance;
}
void stopMotors() {
analogWrite(ENA, 0);
analogWrite(ENB, 0);
digitalWrite(IN1, LOW); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, LOW);
}
void moveForward() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
}
void moveBackward() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
}
void turnLeft() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
}
void turnRight() {
analogWrite(ENA, motorSpeed);
analogWrite(ENB, motorSpeed);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
}
void readBluetooth() {
if (Serial.available()) {
btCommand = Serial.read();
lastBTtime = millis();
Serial.print("BT Command: ");
Serial.println(btCommand);
}
}
void readJoystick() {
int xVal = analogRead(VRx);
int yVal = analogRead(VRy);
int deadzone = 200;
if (yVal < 512 - deadzone) moveForward();
else if (yVal > 512 + deadzone) moveBackward();
else if (xVal < 512 - deadzone) turnLeft();
else if (xVal > 512 + deadzone) turnRight();
else stopMotors();
}
bool obstacleDetected() {
long dRight = readDistance(trigRight, echoRight);
long dLeft = readDistance(trigLeft, echoLeft);
if (dRight < safeDistance || dLeft < safeDistance) return true;
return false;
}
void loop() {
readBluetooth();
/
if (millis() - lastBTtime < BT_TIMEOUT && btCommand != 0) {
switch(btCommand) {
case 'F': if(!obstacleDetected()) moveForward(); else stopMotors(); break;
case 'B': if(!obstacleDetected()) moveBackward(); else stopMotors(); break;
case 'L': if(!obstacleDetected()) turnLeft(); else stopMotors(); break;
case 'R': if(!obstacleDetected()) turnRight(); else stopMotors(); break;
case 'S': stopMotors(); break;
}
} else {
readJoystick();
}
}
Have you connected Rx to Rx and Tx to Tx or have you done it correctly, ie Rx to Tx and vice versa ? Do you understand why I asked for a schematic ?
Yes, I did that correctly.
Tell us what you expect happening here.
And describe "multi-piece".
This function reads any command from Bluetooth,
stores the received character in btCommand,
records the last time the command was received,
and displays the command on the Serial Monitor for review.
What I mean is that there were many components, and the ESP32 ports were not enough for them, which is why I used the Arduino Uno.
It reads a command from whatever is connected to uart pins and sends it back to the same device.
What esp32 board you have? How you count ports?
ESP32 DevKit V1
30–34 available pins
after excluding the pins dedicated to Flash and programming UART
The subject is as follows: I will also equip the project with an LCD screen and buttons for controlling the materials, which is why I excluded the use of the ESP32.
Uno has more?
Esp32 can't handle buttons and LCD?
Look, I suggest you to start from clean table and to describe what you are after. Guys here can suggest you what's the best approach.
Addressing Your Issue:
You can spend weeks spinning your wheels, or you might get lucky and solve your problem quickly. To avoid unnecessary delays, it’s crucial to provide an annotated schematic of your circuit as you have it wired, showing all connections, including power, ground, and power supplies. I recommend it be in English, you can translate before posting if needed.
Why Detailed Information Matters:
Annotated Schematics: These are essential because they show exactly how your circuit is set up. Without them, it's difficult for anyone to understand what you’ve done, which makes troubleshooting nearly impossible. Fritzing diagrams or unclear pictures are not enough.
Technical Information: Many modules look similar and may even have the same name, but they can function differently. This is why we always ask for links to detailed technical information—not just sales pages like those on Amazon, which often lack the specifics we need.
Post your Software Without that we do not have a clue as to how it is expected to operate. Be sure to use code tags.
Show All Connections: It’s important to include every connection, especially power, ground and power sources in your schematic. Missing these details makes it hard to determine if a setup issue might be causing your problem.
My Process:
When I see a question, I spend a moment assessing it. If it’s missing critical information, I might ask for it. However, if it's repeatedly lacking important details, I may assume the questioner is not serious and move on to another query.
What You Need to Consider:
We don’t know your skill level or what resources you have available. If you’re missing key technical details or seem unprepared, it may indicate that you need to spend more time learning the basics before starting your project.
Providing the right information upfront will help you get the best possible assistance and avoid the frustration of running into dead ends. Let us help you by sharing what you have clearly and completely!
Were you using classic Bluetooth or Bluetooth Low Energy (BLE)?