# Driving 5V relay with ESP-01

**URL:** <https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874>\
**Category:** General Guidance\
**Created:** [February 19, 2021, 4:14pm UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874 "2021-02-19T16:14:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![matrixall](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@matrixall](https://forum.arduino.cc/u/matrixall)\
**Post date:** [February 19, 2021, 4:14pm UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/1 "2021-02-19T16:14:09Z")

</div>

I'm trying to drive a 5V relay with 3.3V ESP-01 with schematic below. I programmed the ESP to start a portal through which I can derive the relay by triggering GPIO-0 & GPIO-2. However when I power on the circuit I encounter the following scenarios:  
1- if wire is plugged in to GPIO-2:

- ESP blue led turned on forever
- Relay started buzzing sound forever
- No WIFI network appears thus not working

2- if wire is plugged in to GPIO-0:

- No WIFI network appears and thus no working

if I only plug the wire after powering on the circuit then it works just fine as intended.

Would you please explain what is happening and how to fix it

 ![](https://europe1.discourse-cdn.com/arduino/original/4X/1/4/3/14364f8158169450dcbbab725ba0edd409de5a5b.jpeg)

---

<div class="post-metadata">

**Author:** ![wvmarle](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wvmarle/32/1013044_2.png) [@wvmarle](https://forum.arduino.cc/u/wvmarle)\
**Post date:** [February 19, 2021, 4:17pm UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/2 "2021-02-19T16:17:04Z")

</div>

GPIO0 and GPIO2 take part in the boot process. Beware of what you attach to those.

---

<div class="post-metadata">

**Author:** ![matrixall](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@matrixall](https://forum.arduino.cc/u/matrixall)\
**Post date:** [February 19, 2021, 4:37pm UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/3 "2021-02-19T16:37:03Z")

</div>

> wvmarle:  
> GPIO0 and GPIO2 take part in the boot process. Beware of what you attach to those.

So what is the point of having ESP-01 if I can't use those GPIO's?

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [February 19, 2021, 5:02pm UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/4 "2021-02-19T17:02:57Z")

</div>

I have found that there is little point to the ESP8266-01, period. If you want to use a ESP8266, get a NodeMCU, Wemos D1 mini ESP8266 or one of the other 8266 dev boards.

You are not using serial so you could use the RX pin (pin 3) for the relay.

Doesn't the relay module have a driver transistor on it?

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [February 19, 2021, 5:06pm UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/5 "2021-02-19T17:06:42Z")

</div>

Or an ESP32 developer board.

---

<div class="post-metadata">

**Author:** ![wvmarle](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wvmarle/32/1013044_2.png) [@wvmarle](https://forum.arduino.cc/u/wvmarle)\
**Post date:** [February 19, 2021, 5:37pm UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/6 "2021-02-19T17:37:38Z")

</div>

> matrixall:  
> So what is the point of having ESP-01 if I can't use those GPIO's?

I never said you can't use them. In fact, they are perfectly usable. Just beware of what you attach to it, as there are some limitations. GPIO2 must be high (or left floating) for boot; GPIO0 pulled high (for normal boot) or low (to enter program mode) so it has an external pull-up fixed to it. The moment the ESP is running you're free to do whatever with those pins.  
The same accounts for GPIO 1 and 3 (the Serial connection). Perfectly usable GPIO pins. Just don't connect anything to it that interferes with them being used as programming interface, unless you don't need to program it while installed in the project.

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [February 19, 2021, 8:48pm UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/7 "2021-02-19T20:48:47Z")

</div>

> groundFungus:  
> I have found that there is little point to the ESP8266-01, period. If you want to use a ESP8266, get a NodeMCU, Wemos D1 mini ESP8266 or one of the other 8266 dev boards.

Rubbish! 😲

The ESP-01 is **very** practical. It has four available GPIO pins but you have to know **how** to use them, particularly ensuring GPIO 0 and 2 are pulled up at boot.

You need a relay module specified as "low level trigger" which you need to connect directly to the ESP-01. If you use an opto-isolated version with the following circuit, you connect "Vcc" to 5 V, **not** 3.3 V. the voltage drops in the LEDs ensure the ESP will not be subjected to more than 3.3V.  
[![](https://europe1.discourse-cdn.com/arduino/original/4X/6/c/4/6c42e495a070773ae4c6d5ac168ef597131fcac4.jpeg)](https://i.stack.imgur.com/lMYtu.jpg)  
If you use a non-isolated version where the PNP transistor does not have a LED in series with its base, you still operate it from 5 V but add a diode in series with the control line to reduce the voltage the ESP sees.

[![](https://europe1.discourse-cdn.com/arduino/original/4X/0/0/c/00cb992864106dcf56972b8c6f839af0425653b1.jpeg)](https://i.stack.imgur.com/PoEHl.jpg)

---

<div class="post-metadata">

**Author:** ![matrixall](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@matrixall](https://forum.arduino.cc/u/matrixall)\
**Post date:** [February 20, 2021, 2:45am UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/8 "2021-02-20T02:45:25Z")

</div>

> Paul\_\_B:  
> The ESP-01 is **very** practical. It has four available GPIO pins but you have to know **how** to use them, particularly ensuring GPIO 0 and 2 are pulled up at boot.

This is what I'm looking for, How can I use them (GPIO-0& 2)? is it something in the code I have to modify or what exactly 🙂

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [February 20, 2021, 7:00am UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/9 "2021-02-20T07:00:13Z")

</div>

No, nothing special.

Given that the pin is connected to a "low level trigger" relay module which pulls it high at startup, in setup() you first write the pin HIGH and then set it to OUTPUT. You do it in this order to avoid the relay briefly actuating.

When you **want** to actuate the relay, you write it LOW and then HIGH again to turn off.

---

<div class="post-metadata">

**Author:** ![matrixall](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@matrixall](https://forum.arduino.cc/u/matrixall)\
**Post date:** [February 20, 2021, 10:18pm UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/10 "2021-02-20T22:18:17Z")

</div>

> Paul\_\_B:  
> Given that the pin is connected to a "low level trigger" relay module which pulls it high at startup, in setup() you first write the pin HIGH and then set it to OUTPUT.

I tried your recommendation but didn't work. I believe the transistor pulling it low regardless.

---

<div class="post-metadata">

**Author:** ![Paul\_B](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_b/32/216376_2.png) [@Paul\_B](https://forum.arduino.cc/u/Paul_B)\
**Post date:** [February 21, 2021, 12:47am UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/11 "2021-02-21T00:47:46Z")

</div>

> matrixall:  
> I tried your recommendation but didn't work. I believe the transistor pulling it low regardless.

Which means you do not have a "low level trigger" relay. 😲

You need to implement your original circuit but with a PNP transistor (with its emitter) connected to the 3.3 V supply instead.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 21, 2021, 12:47am UTC](https://forum.arduino.cc/t/driving-5v-relay-with-esp-01/696874/12 "2021-06-21T00:47:57Z")

</div>

Closed on June 21, 2021, 12:47am UTC

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