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

User avatar
By markbee
#7301 I'm trying to drive an optocoupler which drives a relay for 230V. To drive the optocoupler I need about 10mA (absoulute minimum would be 6mA) at 5V (could go lower to 4V but that doesn't matter imho).

Normally when driving loads from uC-Pins I use MOSFETs and do ground Gate and Source with a high value resistor to get a clear LOW signal on startup, whatever happens at this time with the microcontroller output pin.

It looks like this doesn't work with at least ESP-01 (did not try the other module types). A transistor connected with a base resistor pulls GPIO2 low, even if I use a high value resistor or go for a Darlington. The MOSFET has the same problem - although I didn't try one with a very high impedance at the gate. I will try the proposal with the capacitor (although a C is an immediate short to the circuit while getting loaded) or maybe even a RC circuit.

Easiest way will be using a different module I think.

markbee

peteben wrote:That really depends on your application. What are you trying to switch?
GPIO2 will be set as an input while the chip boots, and needs to remain pulled up to run user code. After user code starts, you can do whatever you want, though.
Since you're talking 5V and the chip runs at 3.3V, it's clear you're going to need atransistor or a FET to switch your load.
If you are just driving a LED, a short (20ms) flash at bootup is probably not critical. You can write your own firmware in 'C' or modify the 'AT' firmware to ensure GPIO2 goes low as soon as execution starts.
If it is but timing on your output is not critical, you could add a capacitor that would 'eat' that 20ms pulse.
If you can't do anything else, a pair of transistors will probably be necessary to invert the output and drive the load.

Pete
User avatar
By Mehrius
#7492 Hey,

I've been trying to switch on a relay with the esp8266 too.

I installed the nodeMCU software on it and also a http server app from this forum to switch the state of the relay from http. I've been having the same problem as you with the pin turning on and off a few times and then staying on.

From the nodeMCU github I got that you can use the RX/TX pins as gpios and has pretty good results with turning the rx pin to a gpio through http. (it's just as easy to do it for the tx pin but that has the blue led attached to it and I didn't like that).

I am turning the relay on with the rx (gpio9 - nodeMCU pin3) pin being low and it works great.(no boot time turning on and off - it just stays off like it's supposed to)

My problem is this also has some problems booting(it boots ok about 50%-60% of times).
Should the rx pin be pulled high or low during boot?
Will you test this and tell me if you are able to boot ok? (to rule out power supply issues)

Thanks
User avatar
By Sherin Mathew
#38829 Regarding the initial high during powering up of ESP8266, I have found a work around. Please refer to this article - [url][http://arduino.stackexchange.com/questions/16878/esp8266-stops-responding-when-isolated-relay-is-connected-to-ac-tubelight/19582#19582]

Basically I've used resistors and an LED to stop the inital flow of current from triggering the relay. I'm not from electronics background, hence the approach may sound foolish. But it works. I'm using this circuit for the past 2 months without a single reset or unexpected behaviour.