Hi, so I searched through the categories and didn't find anything related to the ESP01s module. So I'm posting it here. (treating as if it's a general electronic component. I guess that's not entirely inaccurate. )
Few Words Summary
Here's the "schematic" and summary if you can't understand. I guess in the Arduino forum when you ask in few words, you're asked to explain, and when you explain, you're asked a summary right? So here's both.
I should fry the ESP 01s and waste money right? There are 101 better ways to do this right? None works for me, and this works perfectly. I want to know why. If you like, read the long version below.
I'm a total novice into MCU programming, so after ordering a UNO board, few additional components, I looked up a few tutorials, and got to work on a small project. Since this is one of my very first, there's nothing fancy. Just using a ESP-01s module to switch a relay module on off.
As far as the code goes, it's simple enough. Just using the Blynk app and its library to generate a GPIO PWM through WiFi, and running a relay module from there. Extremely simple and just works. This actually doesn't use the UNO, and the ESP 01s runs all by itself. It has only 8 pins and says it runs on 3.3V.
I got everything working, but not the power supply issue. After using a UART USB TTL with 3.3V to upload the code and it started running, I removed all the extra jumpers and plugged it into a powerbank, and checked if just providing 3.3V and GND to the ESP 01s works. This is because it was the easiest way for me to get 3.3V. ESP 01s works, the GPIO2 pin puts out a PWM when I press the button on the Blynk app.
Getting that PWM to run a relay was the biggest hassle I faced. I have the really basic 2 channel 5V relay module, and since it runs on a different voltage, I tried racking my brain how to provide the power.
I first used the 5V pin and GND on the USB TTL itself. (plugged to a powerbank, so only to get power) It does send power to the relay, (since I can see the IN1 LED light up), but for some reason, the relay doesn't activate. I thought maybe this is because USB TTL can't provide enough power to energize the EM coils. Oh well.
Then I tried as I might to attach a separate cable with it's microUSB plugged to a small component that gives out easy access to the pins. Plugged this to the other USB port (has 2 USB As) of my powerbank and got the 5V and GND attached to the relay. For some reason, this didn't work either. Relay simply does not turn on. (maybe something wrong with it, the USB cable or the component, let's say)
Then I attached both the USB cable and USB TTL to different ports of my laptop. Then, everything works. However, when I removed the USB TTL, and plugged it to the Powerbank, and just plugged the relay to a laptop USB, it doesn't turn on the relay for some reason. ESP 01s works fine with when USB TTL is attached to the powerbank. (To reiterate, I plugged the USB TTL to powerbank just to get 3.3V for the ESP 01s)
The only reason I can think here is that somehow the relay and ESP 01s has to be on the same power circuit. (Since plugging both to laptop USBs work and they are commonly powered, and the powerbank USB ports are powered separately) So the only solution seemed to be to somehow get a 3.3V from the micro USB component.
After racking my brain for a lot, I was simply fed up so just connected the ESP 01s to the same micro USB thinking devil may care. I got the ESP 01s dirt cheap after all. So as you can see from the photo, a USB cable comes to the Micro USB component, and it outs 5V and GND from two holes. I have put two male jumpers through it, attached female jumpers from the other side. What this does is just gives out 4 leads with two 5Vs and two GNDs, I have plugged one set to the relay, and one set to the ESP 01s. A single jumper runs from the ESP 01s's GPIO2 to IN1 of the relay.
According to everything I read, this should simply smoke the ESP 01s chip. However, plugging the relevant USB cable to anything simply works perfectly!! The chip powers up and connects to WiFi, the relay is charged, and the PWM switch works. It doesn't matter whether this is any USB port of my laptop, or any USB port of my powerbank.
This also renders moot whether my previous issue was if the USB cable, micro USB component or any port of the powerbank is defective. Everything is okay. (I know the laptop and USB TTL are not defective because I used them to upload the code successfully) I'm just saying out loud the debugging steps that go through my head here. Please let me know if I'm wrong.
So how the heck does this work and previous versions doesn't? I'm clearly not supposed to power the ESP 01s with 5V, because it is said to fry the chip. But that should happen immediately right? Somehow that doesn't. The relay needs 5V, and if somehow the USB cable and micro USB component is somehow so bad that the resistance drops the 5V voltage to 3.3V (I know right ), that shouldn't power the relay. However, it seems that this setup is giving perfect amount of power to both the relay and the ESP 01s.
I ask anyone knowledgeable how the heck is the possible? As far as I can understand, there's only three extremely unlikely explanations for this.
- I have found a set of magic 10cm jumper cables that takes 5V and outs 3.3V to the ESP 01s
- ESP 01s is 5V tolerant, and every forum I read on the internet is wrong. It does not cause any harm to the MCU, and everyone is just running around trying to power it with 3.3V only.
- I have found a magical ESP 01s that IS 5V tolerant, even though is clearly says not.
- USB cable and micro USB component has such a bad construction that it somehow drops 5V to 3.3, AND I have found a magical 5V relay that can be powered by 3.3V.
So which is it? Can someone explain? Here are the photos. See and answer me.