I have read the dire warnings about connecting ttl serial to a Sonoff device that is powered by the mains (US: 120V AC). This is because the AC is not isolated from the logic circuits. Take this warning to heart! It is most likely that you will destroy your device, the serial ttl device, your computer and, literally, kill you.
Some of my Sonoff devices (R2 and D1) were acting very odd and I felt I needed to have it powered by the mains to discern what was going. I invested in an opt-isolated USB to ttl serial adapter. I was wary because, A) it was from AliExpress, and B) VDD, according to the opto-isolators spec, needed to be 4.5-5.5V. The AliExpress page stated 3.3 or 5v.
I went ahead, particularly because the Sonoff device side and the USB side are physically well separated (5mm). GND to GND, RX to TX, TX to RX, 3V3 to VDD
Everything worked as expected, even the ability to flash the chip using the Tasmota Web Installer. (hold button (I/O 0) down, turn on, run installer)
The warnings are there so you don’t have your device connected to AC mains and at the same time connecting your serial adapter because most of the power supplies housed inside (mostly on the same PCB) don’t have an (fully) isolated DC side
Therfor it can be a bad idea adding some sensors that are exposed externally (internally connected to 3.3V) because they might be referenced to mains voltage
Today you even find dodgy USB power supplies that are not properly isolated and people actually been electrocuted holding on to their conductive phones
While the line is not bonded to logic gnd like in Shelly, t’s not isolated supply either.
For my curiosity, I measured with multimeter resistance 2.5M between L and logic gnd (Sonoff mini r2).
So even if weak path, it can’t be considered safe. At 325V the resistance can be different, multimeter uses typically ~1V.
Adding a sensor is a different challenge. In my Low Cost Energy Meter, My sensors, AC voltage and AC current, are isolated, 1:1 transformer and current transformer, respectively
I used a buck converter of a similar design to power the Arduino. In theory, the DC side of the buck converter is isolated by the transformer and the opto-isolated feedback of the switching power supply. In theory, the low voltage DC circuit is floating. But even if it is not, it is not connected to any other device. (I enclosed it in a PVC electrical box)
I agree, that if a sensor is powered by such a circuit it should be physically isolated.
(emphasis mine)
In the USA line should never be bonded to anything but the primary of a transformer. Neutral, in the USA, and earth ground are [often] connected at the panel (mains panel), but even then, at an outlet, there may be voltage enough between ground and neutral to give quite a surprise.
Ok, I know. In the aforementioned buck converter, line is connected to the AC side of a full wave rectifier. This works and is safe as long as the circuit is otherwise isolated and the AC spacing is sufficient. Note that in this buck converter, while the AC spacing is sufficient, it is not acceptable to most regulatory agencies! caveat emptor!
Another note on the aforementioned converter. While the specs on Aliexpress state 7. Input voltage range: AC50V-277V DC70V-390V, they do fail at the US 240VAC, though not immediately. Again, caveat emptor.
I’m not familiar with all USA requirements, but if you explain I will appreciate it for my learning.
Anyway, Shelly and many other devices bond L directly to logic gnd. Nothing wrong with that, enclosure is double insulated and logic contacts are not exposed for normal user. These tiny boxes don’t have space for isolation transformers and the advantage of having single input SW (Line) instead of “dry circuit” S1/S2 is huge.
Pretty much all small smart devices, not only shelly’s, are connected pretty much the same way (sonoff’s, tuya’s…) —> either live or neutral is usually on the GND, so NEVER connect uart to ANY device when it’s mains powered. That’s a golden rule! Always been! The reason is pretty simple: a.) cost, and b.) there’s simply no room inside for complicated power supply (try to squeeze big PSU inside shelly mini…)
As mentioned, there can be a risk of electric shock connecting external sensors to such devices. If you do it MAKE SURE that they are well and properly insulated!
Most housing in USA is split single phase 240VAC. Split phase means there 2 Lines, L1 and L2. There is a common Neutral (N). Each phase is180° out of phase from the other, meaning that each phase is 120VAC. The neutral is often connected to earth ground. This rarely causes problems and is considered increased safety.
So if you connect L (line) to GND of a device you could get a nasty shock, best case. It’s not so good to connect N (neutral) either, because an unbalanced load will put a voltage between the GND and earth ground.
The amount of isolation is dependent on the transformer T1 and the opto isolator. It doesn’t take much to get 1000V isolation. The very cheap and inexpensive power supplies from AliExpress provide this, though the AC spacing does not meet most codes and ripple and noise on the output power can be bad.
Pretty much all small smart devices have something like this. I have to assume that if the mains are connected at all, only the ground of the mains is connected to the GND of the logic circuit. Consider this, if one device has its plug into the wall flipped around compared to another, if you touch both devices, you’re going to get an unwelcomed surprise.
Well, not according to my experiences. But, then again, i have (pretty) old sonoffs, shellys (gen1 or 2) etc, perhaps this was changed lately. But most of mine are directly connected (tested with electro-shock )
But, either way, above recommendation stays: when flashing with UART use local low voltage power supply! Or, at least, use mains isolating transformer (which is good to have in any case if you play with such things).
I do have an isolation transformer (now where did I put it?) I found that the isolated serial device (see first post) also works well, provided that one takes good care not to touch any part of the circuit on the unit under test.
True, isolated uart will help, but, then, as you said: don’t touch anything!
I have isolation transformer in my workshop, it’s 300VA, connected via 2A fast automatic fuse. But i still rather connect my esp’s to my lab psu when doing that… better safe than sorry…
I have older and newer models from Shelly and Sonoff and non of them has isolation transformer. In case of Shelly it’s also part of the working principle of the device ( L directly bonded to logic GND). This way switch wiring can be left unmodified.
To summarise this thread, please don’t put mains voltage anywhere near your body, your computer USB port, your programmer, or near anything else where it wasn’t designed to go. Treat it with respekt.
Not knowing a lot about IEC AC power circuit wiring. I did some research. All of the pages I read agreed with the Wikipedia page in that “L” is Live
@Protoncek presents a picture of an “older Shelly” What I understand from @Karosm’s statement is that the resistance between the GND pin to the mains connection labeled “L” is zero Ohms (This is what I understand bonded to mean)