When programming an ESP-01 with Arduino IDE, how can I make the Tx and Rx into a generic I/O pins reliably? I think there's a command to swap the Tx and Tx with other pins. I tried serial.swap() but it didn't work. So how to get done with Arduino IDE or is it even possible?. I am using an ESP-01, which means there will be four GPIO pins once this question in answered.

I want to achieve same as in the video, How to add more GPIOs to ESP8266 (ESP-01), but without soldering wire.

5 Answers 5


Add this to your code at the beginning of set void setup():

//********** CHANGE PIN FUNCTION  TO GPIO **********
//GPIO 1 (TX) swap the pin to a GPIO.
pinMode(1, FUNCTION_3); 
//GPIO 3 (RX) swap the pin to a GPIO.
pinMode(3, FUNCTION_3); 

You will no longer be able to use the Serial Monitor as TX will now be a GPIO pin and not transmit Serial data. You can still Flash your device as when you boot the device in flash mode it converts GPIO1 and GPIO3 back to TX/RX. Once you reboot into regular running mode GPIO1 and GPIO3 will go back to being GPIO pins.

To change GPIO1 and GPIO3 back to being TX/RX for regular Serial Monitor use add this to your code at the beginning of set void setup():

//********** CHANGE PIN FUNCTION  TO TX/RX **********
//GPIO 1 (TX) swap the pin to a TX.
pinMode(1, FUNCTION_0); 
//GPIO 3 (RX) swap the pin to a RX.
pinMode(3, FUNCTION_0); 

If I understand the ESP-01 correctly the pins CANNOT be both TX/RX and GPIO pins at the same time.


Tx = GPIO 1

Rx = GPIO 3

Should work but be careful cause if they burn, you won't be able to program or even talk to the ESP anymore.

  • Im not sure I understood your answer- so with your arduino code in your answer will it swap the tx, rx pins with others that cant be accessed (except without soldering wire) so that the previously unaccessible pins , which you refer to as gpio 3 and gpio 1 can be used like the gpio 0 and gpio 2 as input or output pins
    – vzxc
    Commented Oct 7, 2016 at 2:09
  • I mean that if you want to use the Tx pin as a OUTPUT / INPUT, declare it and consider it as GPIO 1. Same applies for the Rx pin.
    – Dat Ha
    Commented Oct 7, 2016 at 2:11
  • So it will work like the video I referenced in the question?-except without soldering of course. and it would mean the serial pins tx and rx cant be used for serial communication-which is ok
    – vzxc
    Commented Oct 7, 2016 at 2:14
  • 2
    true, just remember to be CAREFUL to not short those 2 pins
    – Dat Ha
    Commented Oct 7, 2016 at 2:17

To work TX RX as GPIO Serial.begin() must be deleted from code.

  • Just removing the Serial.begin() is enough, worked like a charm. Thanks! Commented Oct 2, 2021 at 18:18

Maybe a little late but it might helps someone else.

ESP-01 GPIO pins (1&3)

  • 10
    Don't just link to an external page, especially when the answer is buried in it somewhere. (External pages change and disappear.) Instead, write an answer here that directly answers the question, using information from that page (and still linking to it with a mention that that's where you got the information).
    – cjs
    Commented Apr 10, 2017 at 13:23
  • Quite lengthy and interesting article, hard to summarize here... I'm leaving a mirror in case the original disappears.
    – brasofilo
    Commented Jun 9, 2019 at 5:56

One thing I noticed is that if you're trying to use the Tx/Rx pins for the main serial comm (1 & 3) as a GPIO then you must not use any Serial commands in your code, such as Serial.begin.

I was having my GPIO digital reads randomly read high (they had their mode set as INPUT_PULLUP) while I had a source pulling them low (I verified that input was indeed pulled low while the ESP8266 digitalRead was reading high)

Removing all Serial commands (begin, print and println) fixed that for me.

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