Setting Arduino R3 as primary and communicate with ESP32 Dev Board

I am currently working on Arduino Uno R3 and ESP 32 Dev Board. The intention was to set Arduino as primary and ESP32 as secondary. Meaning to say, the Arduino will command ESP32 to do certain things such as turning on an LED light. However, I encounter errors where the LED on ESP32 won't do what it is supposed to do. SOS needed, please. Thank you.

/////////////////////////////////////// Arduino Code (Master)////////////////////////////////////////

void setup()
pinMode(4, INPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);

void loop()

while ((digitalRead(4) == HIGH)){

while ((digitalRead(4) == LOW)){

/////////////////////////////////////////// ESP32 Code (Slave)//////////////////////////////////////////

#define RXD2 16
#define TXD2 17

String readString;

void setup() {
// put your setup code here, to run once:
pinMode(25, OUTPUT);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);

void loop() {
// put your main code here, to run repeatedly:
Serial.print("Data Received\n");

if ((digitalRead(Serial2.available()) == HIGH)){


else if ((digitalRead(Serial2.available()) == LOW)){



Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Could you post an image of your project?

Could you please describe what you are doing to shift the levels of the 5V Uno to the 3.3V, non 5V tolerant, ESP32?

The way I have used the ESP32 serial ports:

#include <HardwareSerial.h>

HardwareSerial GPSSerial ( 1 );
// pin 2=RX, pin 15=TX
HardwareSerial LIDARSerial ( 2 );
// pin 26=RX, pin 25=TX
void setup()
 LIDARSerial.begin ( SerialDataBits, SERIAL_8N1, 26, 25 );
  GPSSerial.begin ( GPS_DataBits, SERIAL_8N1, 2, 15 ); // begin GPS hardware serial

void fReceiveSerial_LIDAR( void * parameters  )
  bool BeginSentence = false;
  char OneChar;
  char *str;
  str = (char *)ps_calloc(300, sizeof(char) ); // put str buffer into PSRAM
  // log_i("Free PSRAM before String: %d", ESP.getFreePsram());
  for ( ;; )
    EventBits_t xbit = xEventGroupWaitBits (eg, evtReceiveSerial_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY);
    if ( LIDARSerial.available() >= 1 )
      while ( LIDARSerial.available() )
        OneChar =;
        if ( BeginSentence )
          if ( OneChar == '>')
            if ( xSemaphoreTake( sema_ParseLIDAR_ReceivedSerial, xSemaphoreTicksToWait10 ) == pdTRUE )
               xQueueOverwrite( xQ_LIDAR_Display_INFO, ( void * ) &str );
              xEventGroupSetBits( eg, evtParseLIDAR_ReceivedSerial );
            BeginSentence = false;
          strncat( str, &OneChar, 1 );
          if ( OneChar == '<' )
            strcpy( str, ""); // clear string buffer
            BeginSentence = true; // found beginning of sentence
      } //  while ( LIDARSerial.available() )
    } //if ( LIDARSerial.available() >= 1 )
    xSemaphoreGive( sema_ReceiveSerial_LIDAR );
    //        log_i( "fReceiveSerial_LIDAR " );
    //        log_i(uxTaskGetStackHighWaterMark( NULL ));
  vTaskDelete( NULL );
} //void fParseSerial( void * parameters  )

I do not see any level shifters. The ESP32 is NOT 5V tolerant.

Oh, what is the Arduino Uno doing that the ESP32 cannot do?

BTW: most likely the ESP32 GPIO pins that received 5V are poo.

So basically i could make the Arduino and ESP32 to communicate . Meaning to say that i sent value 1 or 0 from Arduino to ESP32 when toggle switch is HIGH or LOW accordingly. And the ESP32 does recieve data from Arduino. Just that i wanted to off and on the LED light connected to ESP32 when ESP32 recieve data 1 (to switch on LED) and 0 (to switch off LED). And it does not work. Is it the condition i set on the ESP32 wrong?

The esp32's onboard led is on gpio 2.

But I am using external LED light which is attached to pin 25 of ESP32

Ic, where is the current limiting resistor?

No level shifters, no current limiting resistor to run the LED's, and no common between the Uno and the ESP32.

If they are running from the same PC, then the common is through the USB cable grounds. That would make it work, but isn't good for various reasons.

Another thing, the switch is obviously wired wrong, It's connected between a GPIO and 5V with no pull down resistor. To run with no resistor, it has to switch to ground and use the INPUT_PULLUP port config option. With that configuration, the software has to recognize a LOW as a switch closure.

I thought hard and long before asking that question. Yes, the current common ground is through the USB connectors but like you wrote, "but isn't good for various reasons". So I asked.

So far.

No common ground, no level shifters, no LED resistors, and the switch is wired incorrectly.

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