B4R Question Build a smart switch with ESP8266

aeric

Expert
Licensed User
Longtime User
I learn that there are some WiFi smart switches in the market like Shelly, Tuya and Sonoff. It is build in with ESP8266 and relay in a small form factor.

What if I want to build something similar?

I can say all of the projects on the Internet show that the ESP is powered by USB.

My question is why not use a 220v AC to 3.3v/5v DC converter that get the power from Main electric source so I don't need to get messy with another charger?

 
Last edited:

hatzisn

Expert
Licensed User
Longtime User
I though of doing this either but in the danger of hurting myself or setting by mistake the house on fire, I reconsidered. We have a basic knowledge to do it, but the problem is exactly this: We have a basic knowledge to do it.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Why not a "ACDC 5 and 12 voltage regulator" ?
5 for ESP, 12 for relays.
I guess that 12V relays are cheaper than 5V (lower current, thinner copper coils...).


upd.: aaah, do you mean control signal from ESP to relay ?
Yes, anyway a transistor amplifying cascade is needed: relay needs the higher than 3.3V control voltage and also the current that is to be much higher than any MCU regular pin can provide.
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
What if I want to build something similar?

I was thinking you'd be better off just buying some generic BLE or wifi remote switches via ebay or AliExpress, started looking to see what was available, and this made me laugh because Family Sharing Control Fun sounds like the opposite of what would actually happen in most situations:

 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
I can say all of the projects on the Internet show that the ESP is powered by USB.
The projects you see around the web that use USB on ESP are for debugging only. Once the project is finished it depends on where it will be positioned and you decide which power supply to use. For example, the Shelly modules have a reduced esp and on-board power supply, because they are designed for that specific function. We instead use esp8266/32 with many pins for I2C, Uart..etc... so the circuit is very large. We can do it too but we need to know how to use a soldering iron and understand how voltage regulators work, and then create a printed circuit for this purpose.
(sry googl. trad)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I just want to understand why no project suggest to use the converter which is actually cheap.

Just put the photo of how the final project will look like. I just think a project should be simple, less wires, less "moving parts".

The final size of the project is not a concern here but showing just a usb connection is hiding the real thing. It is connected to another adapter which requires a power socket/source.

I know, we may also choose to use 2x 1.5V AA or LiPo battery for production.

The logic is since the thing is using main power why not utilise it?

This can help us to understand how the smart switch in the market works.

Of course, I think the ESP8266 can also be replaced by other smaller version of ESP such as 01 or 32.
 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
I just want to understand why no project suggest to use the converter which is actually cheap.
I understand what you mean. The part that has to power a circuit like the ESP is never explained because there are hundreds of power sources, maybe we already find something at home that we can use. The important thing is to power a circuit in the right way, whether it requires 5 volts or 3.3 volts etc. The tutorials on the internet explain the basis for making a project work, then it is up to the user to improve it by respecting the connections and voltages so as not to damage it. Then in my opinion explaining the 220volt high voltage part in the tutorials is a big responsibility if you are not familiar with voltages that could damage those who use them, so it is better to avoid it.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Use the Sonoff.
You get power, relay and packaging.
It is really easy to flash it with new software that you write in B4R

I agree completely. Thumbs up! A good option also for firmware is Tasmota which you can use from your mobile apps with mqtt or web...
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User

I suppose your answer regarding the mains is because this power can be lethal and no one wants to take the blame.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
... my opinion explaining the 220volt high voltage part in the tutorials is a big responsibility if you are not familiar with voltages that could damage those who use them, so it is better to avoid it.

I totally agree with this...
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Upvote 0

pappicio

Active Member
Licensed User
Longtime User
if you use relay module, they iet have all needed, transistor, diode, led, 3 pin: source (5v), in (3.3v from ESP8266) and GND (from ESP8266)
I use that modules from long time, with tasmota firmware (but also with web server and all b4r and inline c code on some ESP8266), and work well!
and... from photo you posted, that is one of modules I use, and have iet all, transistor to pilote relay with 5V source, in (3.3v from esp8266).......
 
Upvote 0

KiloBravo

Active Member
Licensed User
I always save USB chargers for cell phones or whatever. Then use them to power my ESP projects. I have a box of them. If I want a small package I just take them out of the plastic housing.

You also need to be careful some of the cheap USB switch mode power supplies have a very high voltage when you first plug them in and can blow up your esp32/8266.
Also, I agree 220v can be lethal and no one wants to post how to connect to it directly.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I suppose your answer regarding the mains is because this power can be lethal and no one wants to take the blame.
This is bad. I think electric and electronic guys are bad in explaining this kind of stuff and left people who is looking for answer, puzzled. My opinion is, people is/must aware the risk and danger of high voltage when he decided to build such project. Second, because we have lack of knowledge then only we look for example projects to learn from. Information should not be hidden especially that is the most important part.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User

I believe it is the play safe rule. Even if they tell you how to do everything you may touch by mistake something in the buck converter that would cause an electric sock at you and harm you. The only thing that might save you is the muscle memory: "Perform all the steps with no current and extreme precautions thinking of it in the beggining, do it again and again, and gradually get it to be a habbit". When you get this to be a habbit then the muscle memory will guide you. I do not have this so I thought every step even if I was not exposed to AC circuits when I tried to install a fixed plug for the dishwasher by getting a line from an other external plug to avoid using the expansion cable. I shut down the circuit from the switch in the mains tableaut, I wore plastic gloves and i have put some wood boards on the ground to step on them. If the current was able to manage to electrocute me with such precautions then it had to be Macgyver... Possibly the youngest generations may not have a clue about what Macgyver TV series were... I took all this precautions because I am afraid of mains.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
I am sure I will switch off the fuse box when installing/connecting the wires.
I mean most of the project sharing on the Internet, not about the answers on this forum. I hope I will see more clearer explanations in the future. Thanks guys.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…