But when the power goes out and the ESP01 restarts, the gate opens by itself. That is, GPIO0 would need to be HIGH when ESP01 is starting to prevent this from happening. How can I resolve this?
Hello everyone, I hope you are doing well.
I have an IOT project where an ESP01 is connected to a relay module (as in the image). ESP01 will check the state of a field in my Firebase, and open a gate.
Before you start soldering, maybe describe exactly the circumstance that you get this unwanted relay trigger.
Does it happen (1)when you press "Reset" or (2)by a power fail restart or (3) when your load a program on the the ESP-01 ?
When it happens, does it do so before the ESP-01 has connected to a network (usually this takes a few seconds) ?
Also, when it happens is the relay only triggered for a very short time (a few ms) or the full 800ms which is specified in the code ?
In the first question, this happens when a power failure happens, or even when I unplug and plug the ESP power supply.
In the second, yes. The relay is activated before the ESP connects to the network.
Finally, the relay is activated for a very short period, it does not reach 800ms, but it is enough for my gate to stay open.
I did a test, loading an empty sketch, with only the setup and loop functions (no variables, no declarations, just the empty functions), the relay continued to be activated by the ESP when it is connected to the power, even without any code definitions
It looks like it could be this: MOSFET Self-Turn-On Phenomenon. To investigate properly you'd need a scope to see if the optocoupler led is being energized momentarily at power up. The solution maybe, in this case, to put a capacitor, say 100nF, between the mosfet gate and source. This is going to mean some fine soldering on that board. If the schematic is the same as that in the link I posted, then easiest would probably be between pin 1 on the voltage regulator and pin 3 on the optocoupler rather than on the mosfet itself.
The cause of this is that during boot some of the ESP's GPIO pins go HIGH momentarily, this is described here, unfortunately the only pins that are exposed on an ESP-01 are experiencing this. When dealing with this issue myself for a Relay board (not of the shelf, but designed PCB) i ended up adding an Attiny13a into the circuit that would add a 100ms debounce on the output pin. All other ideas to tackle this problem were more complex and required more parts (for me, that is, if you've never programmed an Attiny13 before it may be a bit more tricky)
One other possible solution may be to put a RC network ( say 10K and 10uF ) in the path between the optocoupler and mosfet gate but after the gate pull down resistor. That would have a time constant of 100ms. If that works, it may than be necessary to prolong the trigger time in the code.
This must then be a very well known problem with those ESP-01 relay shields. Maybe there are more elegant solutions available. But the idea of using an Attiny13a or other microprocessor is also interesting.
Well known i am not sure, but i have seen a thread come through within the last year, and this was before i started on my own board, The issue is compounded by the fact that GPIO 0, 1 & 2 can not be pulled LOW at boot for the correct boot-mode to be selected, which makes the creation of an RC circuit more complex (only GPIO 3 (RX) is ok to Pull LOW at boot) since you need both a slow charge and discharge of the capacitor.
I use them quite a lot and at less than E1,- the price is not an issue, they will run at 3.3v just fine, so actually no extra components required, once the bootloader is burned and the sketch uploaded.
the sketch i use
Note my relay is active HIGH, i don't use an opto-coupler after the Attiny, but just an NPN transistor
Of course best practice is to test everything on the breadboard first, which is also easy enough to program the Attiny.
I'm currently trying to understand a circuit for an ESP8266 relay board. As you can see in the schematics below, an optocoupler is used to drive the relay mosfet. I do not understand, why they are using an optocoupler for the control signal.
My guess is that the optocoupler was left in for compatibility. The FET could be driven by GPIO0 directly, but then the signal would have to be high to activate the relay. The optocoupler acts as inverter, pulling the FET Gate high when GPIO0 is low.
The schematic is badly laid out. The earth symbol is upside down, current is flowing from bottom to top and there is an unnecessary break in the RELAY net. (By mirroring the MOSFET and R2 the opto-transistor emitter could be directly connected to the gate.)
Many of those common hobby relay boards feature jumpers which allow the board to use one supply for everything (as shown) or the 3.3 V supply for the opto-LED only and a separate supply for the opto-transistor, FET and relay.
Although this is about an ESP8266 as found on a WeMos D1 Mini board, I think the question is more about being able to read a schematic. You two presented the WeMos schematic on another thread: _static/files/sch_d1_mini_v4.0.0.pdf
I've got a project that appears to be very simple hardware-wise. It would be powered by a typical cell-phone AC USB adapter. I would like to take advantage of the connector on the WeMos so I don't have to cut up USB cables if that is possible.
The reason "I think" this might work... the 18650 battery shield shown above says it'll handle 4 amps at 5V. I can see the PCB traces coming out of the converter and going to the 5V pins... the trace doesn't look very substantial to be carrying 4 amps. If the WeMos is using similar traces and goes directly from the USB cable 5V wire to the 5V pin, then I would think I'd be OK. If, however, it goes through some other circuitry, I'd feel certain, it'd fry that circuitry.
The note I made on my wemos ESP8266 pinout diagram states output from ether the 3v3 or 5v pins is 500mA. The USB 5v is, I believe, directly connected to the 5v pin. The 5v pin can also be used as an input pin of 4-6 volts that will go to the voltage regulator. So, assuming my note is correct then 500mA is the max you should draw from the 5v pin (or any pin for that matter).
@zander, @byron - I wasn't trying to use a logic pin. Maybe my comments in the Preface distracted from what I am trying to do. My only point was I'm aware that all pins except the 5V pin are very low amperage. I'm just unclear about the 5V pin. I was just hoping the 5V from the USB cable was a strait pass through to the 5V pin on the WeMos and hoped that the Schematic would enlighten someone. The schematic didn't help me squat.
In general, none of the Arduino, R-Pi and so on small, general purpose processor boards that I have looked at have pins designed for 'multiple amps' ... it isn't what they are designed to do ... large currents need lots of copper, as well as devices capable of handling that current. This copper costs money, space, weight and so on - it would not be sensible to 'weigh down' low current processors with all of the overheads. I would very carefully check any pin being asked to carry more than 1A, and 'carefully' check any exceeding 100mA. GPIO pins are in 10s of milliAmps at the most.
Of course, you can get 'expansion boards and units, known by assorted names such as 'shields', that do carry higher currents .. and the reputable products are built to a 'heavier' standard to accommodate the high current demands.
USB plugs and sockets also have current limitations, albeit often 'applied' with 'flexible boundaries'. Personally, I think micro USB is best kept to a max of about 1A, although you can probably push to 1.5-1.8A on a 'good day'. Beware, not all cables will transmit that much without loosing more voltage than you might expect.
The later R-Pi s use USB-C which is rated at higher current (3A) than the preceding mini- and micro- variants. USB-C also has more complex tricks in which the voltage can increased above 5V, but I haven't seen any of the processor boards being 'upgraded to cope.
In addition to the current rating aspects, there are very good reasons to keep high and low current paths separate ... high current demands from things like motors can easily generate voltage spikes which can disrupt and even damage the 'more delicate' low current circuits.
The 5V input from the USB socket passes through a 0.5A 'fuse' and a diode, before being distributed as a 5V supply, for both the power input to the 5V-to-3.3V regulator and the 5V 'board output' pin 9.
So the fuse will limit the incoming current to to 0.5A, and some of that current must be 'reserved ' for the processor. Personally, I would think carefully about exceeding 100mA draw from the board output pin.
The version 4 board, with USB socket connects 'straight through', but passing a high current can be expected to give problems ranging from unreliable operation through to a burnt board, depending on how 'high' the current flow is.
For ye old wemos di mini ESP8266 the max current draw on the 5v pin appears to be 500mA, but, no doubt due to the circuitry that @davee pointed out I note that when using the 5v pin as an output the volts out drops a bit to 4.8. I should have been more careful when I put in brackets 'any other pin' as looking again at my notes I see its a max of 12mA with 6mA as recommended, so I'm glad you did not rely on my advice for those pins. I'm going to leave all this sort of advice for daveE in future and I like the info on the new boards with usb C connectors that was given. Sometime I will have to do another roundup of all these new boards that are available with their salient points such as the boards max mA and the per pin mA and their sleeping mA consumption as this is often not readily to hand when perusing the boards info on the sales sites.