Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By dev67
#42995 Hey all!
So there are plenty of guides online describing how to hook up a relay to the ESP when the relay is hooked up to a board. However I haven't been able to find anything on hooking up bare relays. And since I'm really cheap and was planning on making an entire battalion of these things, opted to buy the bare relays off of amazon for way cheaper. Definitely paying for it now since I'm struggling so much with this circuit though :cry: .

Here is what I've done so far, plus a few variations with mixed results. Including having the solder melt off of my 3.3 volt regulator on the voltage out pin :o

Can any more experienced users give me a clue as to how clueless I am?

Thanks for looking! This community rocks!!!

Image
User avatar
By martinayotte
#43011 You need to have pullups on both GPIO0/GPIO2 for proper boot process.
Having the base of 2N2222 with low resistor connected to GPIO0 or GPIO2 has the effect of pulldown, preventing proper boot.

I strongly suggest to use MOSFET instead, such 2N7000 !

Also, beware that since the GPIO0/GPIO2 need to be HIGH at PowerUp, the relay will be ON during that period.
If you don't want that behavior, you will need 2 stages of MOSFET and therefore the relay state will be inverted, it will be ON only when GPIO is LOW, software should be written according to that.

BTW, you also need a backward diode to the relay for letting the coil been discharge when turned OFF.
User avatar
By piersfinlayson
#43012 Are you really able to build this for more than a few pennies cheaper than just buying a WeMos D1 mini + relay shield? The d1 mini (which includes esp8266, 4MB flash, 5v-3.3v power, USB-TTY, and more GPIOs broken out than the ESP-01) is $4 and the relay shield (so it fits snugly) is $1.90.
User avatar
By sixbacon
#43127 I would remove the 1 k resistor as this is dropping volatge across it and not needed. Try 10 k for the base resistor and as mentioned by others pull CH-PD, GPIO0 and RST with 10 k resistors up to +3.3V. I have something similar running like this.

Just noticed how you wired the relay coil. Do it like this, connect the negative input of the relay to the collector of the transistor and the poistive input to the +5 V . Not like you have. Remove the resistir as above. In this way when the output from the ESP01 goes high, the transistor is switched on and the collector is effectively connected to the emitter which is at 0V. The relay then has almost 5V across it and will close the contacts.