How to connect ESP32 to Arduino UNO via serial connection

Hello there,

A friend and I are working on a project that involved using W-A-S-D keys on a computer transmitted through an ESP32 wifi module to an Arduino UNO and FunduMoto Keyes L298P motor shield that in turn control two LEGO servo motors to pilot a LEGO rover. We have been able to create a web server via HTML that transmits succesfully from the computer to the ESP32 via WiFi. However, we have trouble when it comes to ESP32 to Arduino Motor Shield transmission. We connected ESP TX to Arduino RX and ESP RX to Arduino TX, along with GND to GND. Power is being supplied by a 9V battery with adapter connected to the motor shield. However, while we are receiving indication of signal sent on the ESP, the lights indicating motor signals arent indicating any response on the Arduino motor shield. Some help would be appreciated if possible.
The code below is for the Arduino. Our original program (which I won't send here because it contains WiFi and IP information) sends info to the ESP directing it to release a serial signal of a letter that should be picked up by the motor shield.
Arduino code below:

#include <SoftwareSerial.h>

const int LMotorPwr = 10;
const int LMotorDir = 12;
const int RMotorPwr = 11;
const int RMotorDir = 13;

SoftwareSerial espSerial(2, 3); // RX, TX

void setup() {
  pinMode(LMotorPwr, OUTPUT);
  pinMode(LMotorDir, OUTPUT);
  pinMode(RMotorPwr, OUTPUT);
  pinMode(RMotorDir, OUTPUT);

  Serial.begin(9600); // initialize serial communication with computer
  espSerial.begin(9600); // initialize serial communication with ESP32
}

void loop() {
  if (espSerial.available() > 0) { // if there is incoming data from ESP32
    char command = espSerial.read(); // read the incoming command
    if (command == 'f') { // if the command is 'f', move motors forward
      digitalWrite(LMotorPwr, HIGH);
      digitalWrite(RMotorPwr, HIGH);
      digitalWrite(LMotorDir, HIGH);
      digitalWrite(RMotorDir, LOW);
    }
    else if (command == 's') { // if the command is 's', stop motors
      digitalWrite(LMotorPwr, LOW);
      digitalWrite(LMotorDir, LOW);
      digitalWrite(RMotorPwr, LOW);
      digitalWrite(RMotorDir, LOW);
    }
    else if (command == 'b') { // if the command is 'b', move motors backward
      digitalWrite(LMotorPwr, HIGH);
      digitalWrite(RMotorPwr, HIGH);
      digitalWrite(LMotorDir, LOW);
      digitalWrite(RMotorDir, HIGH);
    }
  }

  if (Serial.available() > 0) { // if there is incoming data from computer
    char command = Serial.read(); // read the incoming command
    espSerial.write(command); // send the command to ESP32
  }
}

Is it a PP3 battery? If so put it back to its fire alarm or remote, and use a proper power supply. There's no way a Wifi transmitter will get the current it needs from that battery.

Could You grab pen and paper and draw a logic block diagram of the system? The Shakespeare type of descriptions does not belong to engineering.
Combining a 5 volt UNO with a 3.3 volt ESP calls for level converting. For You to be safe I recommend You posting real schematics, not the Fritzing colour palette type.
Pen and paper often works well enough. Mind pin designation, power sup etc..

Via a 1k/2k voltage divider, I hope. Also, you don't mention where the ESP32 3.3v power comes from. Don't expect to use Uno's 3.3v pin and don't expect any joy at all if your 9v is a PP3.

any particular reason for using a UNO?
the ESP32 has plenty of IO to support sensors, buttons, LEDs, controllers, etc
discard the UNO and move the project to the ESP32

I totally agree with @horace's advice

In addition ESP32 has 3 hardware serial (let's say 2 because Serial1 can only write for debug purpose)...
you have no real reason to use a limited software serial.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.