I am trying to connect an ESP-01 with an ArduinoMega through the serial port of both, as they use different voltage levels I would need a voltage divider between the TX pin of the Mega (pin 1) and the pin RX of the ESP-01 (pin 4) , it is not difficult to do, but I just need to "send data" from ESP-01 to Mega, then I have a question and it is as follows:

If I just need to send data from one device to the other, could I just connect the TX pin of the ESP-01 to the RX of the Mega? If I do so, will I receive data in the Mega?


  • Did you try it?
    – gre_gor
    Feb 21 '18 at 17:20
  • I tried using an FTDItoUSB for the ESP-01, it didn't work for me...the answer that give me back (Arduino IDE and PuTTY) is: "Unable to open PORT4. PORT4 is in use".
    – k.Cyborg
    Feb 21 '18 at 17:23
  • 1
    OS reporting that the port in use, has nothing to do with what is actually connected to RX and TX pins.
    – gre_gor
    Feb 21 '18 at 17:26
  • 1
    A PC operating system complaint that a port is in use would have nothing to do with the question you posted, but merely be an incidental problem in the course of usage. Try closing any programs that might use serial communication, including the arduino IDE, serial monitor, tools like putty, defunct instances of avrdude, etc. Feb 21 '18 at 17:26
  • I tried restarting the PC (in this scenarios I use Windows) for any rare program, then I tried again using the same configuration, the same result.
    – k.Cyborg
    Feb 21 '18 at 17:50


You can connect only the the line with which the ESP-01 transmits to the Arduino's receiver, and accomplish one-way data transfer.

However, the ESP will have to be willing to transmit without prompting, and you will not be able to use the Arduino to setup or configure it. Further, you will not be able to use any in-band signalling to ask the ESP to refrain from sending, so you will have to be sure that your Arduino sketch is generally ready to claim any input which may arrive, and that if there are periods when it is not, the behind-the-scenes serial buffer is large enough.

There's also the question if it is safe to connect the ESP transmit pin directly to the Arduino receive. In the intended direction of operation, it is. But should you ever load code on the Arduino which uses that pin as a GPIO output, there is some risk of damage to the ESP. It's up to you to decide if careful usage will be enough to prevent that; if not, you may want to try something like a 1K series resistor and a schottky diode to clamp the line to the ESP's 3.3v supply, in a way that diverts the current from any accidental 5v output around any internal protection diode that may have more limited power handling.

  • Thanks for the quick answer and for the recommendations! You just give the tips that I was looking for! I just want to connect my phone to the ESP, open any browser and send some data (a color code, wich is just hexadecimal codes), the ESP recieve that data and send to the Mega, the Mega then will select from the hexa-code the color to set to some leds (50 leds from WS2812B led strip). Do you think the serial buffer from the Mega can hold this? And all this for don't put just to resistences!!! :-)
    – k.Cyborg
    Feb 21 '18 at 17:33
  • If you don't hammer it with constant requests, yes. Do note that receiving multi-character strings can take a little care - you might consider adding a terminating newline as a definitive end marker, and then using line-oriented input. Feb 21 '18 at 17:35
  • Sorry for for the unknow but: what do you mean when you say: "terminating newline" and "line-oriented input".
    – k.Cyborg
    Feb 21 '18 at 17:52
  • Essentially it means typing a value and then hitting the return key, or having a program do so. This is more deterministic than sending a value and having the Arduino merely wait until it decides you are not going to type any more digits. You could rig this up with Serial.readBytesUntil() and atoi() but it will require some work. Unfortunately, the built-in turnkey methods like Serial.parseInt() use the less reliable timeout approach. Still many seem to manage using those. You can also see if sending a newline helps parseInt() finish more promptly. Feb 21 '18 at 19:59
  • Ok, I got what you say...is like have the Mega waiting for the character "\n", meaning a new line, and then download all you have in the bus of the serial to a variable. Is that what you want to say? Another question come to me: can I use RegularExpresions (regex) in the Mega?
    – k.Cyborg
    Feb 21 '18 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.