ESP32: Port to dimming via PWM?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
M*I*B
Normal user
Posts: 379
Joined: 22 Jan 2018, 15:47
Location: Germany
Contact:

ESP32: Port to dimming via PWM?

#1 Post by M*I*B » 18 Jun 2023, 20:52

Hello hobbyists,

In addition to another project, I'm currently thinking about how to best dim 230V with an ESP (dimmable LED lamps).
Of course, there is the usual option of trailing edge control. But what if, for example, you use PWM to dim an IGBT on a bridge rectifier that is connected in series with the lamps?

Has anyone tried this before?
Attachments
img-2023-06-18-20-51-48.png
img-2023-06-18-20-51-48.png (18.33 KiB) Viewed 4045 times
DLzG
Micha

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32: Port to dimming via PWM?

#2 Post by TD-er » 18 Jun 2023, 21:35

What do you try to dim here?
If it is a traditional Tungsten light bulb, then it will probably work.
But modern LEDs will very likely not like this.


I'm not 100% sure what will happen if you connect an inductive or capacitive load to this circuit.
Also what will happen if you have a duty-cycle of 0?

And as always ( ;) ) keep an eye on isolation from mains :)

Edit:
Found this, which is using an optocoupler :)

https://www.learningelectronics.net/cir ... osfet.html

User avatar
M*I*B
Normal user
Posts: 379
Joined: 22 Jan 2018, 15:47
Location: Germany
Contact:

Re: ESP32: Port to dimming via PWM?

#3 Post by M*I*B » 18 Jun 2023, 22:39

At the moment I don't know how dimmable LEDs react when they get an AC voltage PWM instead of a phase section. But since the dimmable LEDs, at least the ones I have here, also work with DC voltage and regulate their LED current based on the applied voltage, it should actually work with PWM as well.
But if no one has tried this yet, I'll test it to see if it works...

And in terms of isolation and security: You know me well enough already, don't you :lol: 8-)
Ultimately there are two possibilities:
Either you switch the gate directly from the port (via gate driver) and then have to accommodate the ESP and peripherals in a touch-proof manner (which also makes an external antenna impossible), or you control the IGBT via optocouplers. The latter option is the better choice because of the antenna and the galvanic isolation...
I mean, I've also seen an IGBT with built-in gate driver and optocoupler somewhere; that would be ideal...

EDIT:
TD-er wrote: 18 Jun 2023, 21:35 Found this, which is using an optocoupler :)
https://www.learningelectronics.net/cir ... osfet.html
Yep... This way... To bad that someone have the same idea before me :roll:

EDIT 2:
https://www.vishay.com/docs/83469/vom1271.pdf
Perfect thing for that. Don't need a power source. Two of them and two FET or IGBT anti parallel and you also don't need a bridge rectifier. Just some C's and maybe a toroid to prevent high frequency interference and that's it. Can be that's possible to dim also a ceiling fan with it... The only NoGo can be that the ceiling fan works as speeker and you can hear the switching frequency...
If I'm ready with my watering thingy I think I will check that out....
DLzG
Micha

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: ESP32: Port to dimming via PWM?

#4 Post by chromo23 » 19 Jun 2023, 18:22

I used this for an semi-intelligent sewing machine:
https://de.aliexpress.com/item/32802025086.html. (the option with the integrated power supply)
it works really well....

Edit: but for ESPeasy you´ll need to put another microcontroller in between that can handle the zero crossing.....

User avatar
M*I*B
Normal user
Posts: 379
Joined: 22 Jan 2018, 15:47
Location: Germany
Contact:

Re: ESP32: Port to dimming via PWM?

#5 Post by M*I*B » 19 Jun 2023, 19:28

... yes, that's true, but for PWM you don't need ZeroCrossingDetection. You split an full wave in i.e. 1000 pieces so anyone hit near the Zero. :D
DLzG
Micha

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: ESP32: Port to dimming via PWM?

#6 Post by chromo23 » 19 Jun 2023, 21:37

My first try of making my sewing machine smart was 13 years ago with very little knowledge of programming and electricity.
I also used a rectifier and a pwm signal but never got it to work because i almost killed myself before i could finish the project. :o
So i decided to use more ready made circuits when working with high voltage. :) (not that this prevented me from making some stupid mistakes regarding high voltage afterwards :roll: some people have a more shallow learning curve than others)

Happy tinkering and stay safe...

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32: Port to dimming via PWM?

#7 Post by TD-er » 19 Jun 2023, 23:15

Hmm with sewing machines, there are less shocking ways to learn what not to do...
I have learned the hard way at the age of 4 that needles are sharp and playing with an old sewing machine with mechanical footpedal probably isn't a good idea as you can achieve quite high speeds and such a heavy flywheel does have quite a lot of inertia.

Think of a vintage 1930's Singer footpedal sewing machine.
Exactly like one of these: https://www.2dehands.be/v/antiek-en-kun ... ine-singer

Learned quit a lot of physics by experience back then.

User avatar
M*I*B
Normal user
Posts: 379
Joined: 22 Jan 2018, 15:47
Location: Germany
Contact:

Re: ESP32: Port to dimming via PWM?

#8 Post by M*I*B » 20 Jun 2023, 08:03

... my wife and I collect such old things, restore them and when the space is over (have learned that the space of our house is not endless... what a shame^^), we will sell something again.
We currently have 4 of these old sewing machines, all (again) fully functional and absolutely original. From our point of view, building an engine on it is an atrocity...
These machines also fascinated me in my early childhood. And after I used my grandmother's sewing machine to sew through my finger, my grandmother was kind enough to teach me how to use it. I was the only first grader far and wide who could sew with a machine... I can still do it today ([look around carefully] ... better than my wife 8-) ).
It was the same with the electronics. "Steam radios" also fascinated me as a kid; the warm sound, the warmth, the glow... When my mother wanted to go shopping and there was nobody to look after me, she would simply put an old chassis in front of me, which captivated me long after she got home to disassemble it neatly without tools.
Nowadays, of course, I do it the other way around. At the moment there are probably around 50 tube radios, most of which have been fully restored (quite apart from the tape machines, turntables, gramophones, transmitters and other historical devices).
That was actually my path to electronics, but more in analog technology. Of course at some point also with computers (Z80, Ti994A, VC20, C64, Apple IIe, ...) and later on an IBM 8088-neat even a Fido hub under TELIX (pre-internet time).
But analog technology, especially audio and broadcast technology, is still at the top for me... When I'm gone, there will certainly be a glowing tube on my tombstone :D
BTW: If you've ever had an encounter with 800V anode voltage or something like that, then you definitely know that DC hurts a lot more than AC... Trust me :lol:
DLzG
Micha

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: ESP32: Port to dimming via PWM?

#9 Post by chromo23 » 22 Jun 2023, 12:24

TD-er wrote: 19 Jun 2023, 23:15 such a heavy flywheel does have quite a lot of inertia.
I can tell you from experience (i was also 4 or 5) that getting with the finger between the belt and the flywheel make you feel physics in a very physical way. I still have this litte reminder when looking at my middle finger...
M*I*B wrote: 20 Jun 2023, 08:03 BTW: If you've ever had an encounter with 800V anode voltage or something like that, then you definitely know that DC hurts a lot more than AC... Trust me
I am happy that you can still tell us about it ;)

User avatar
M*I*B
Normal user
Posts: 379
Joined: 22 Jan 2018, 15:47
Location: Germany
Contact:

Re: ESP32: Port to dimming via PWM?

#10 Post by M*I*B » 22 Jun 2023, 12:41

chromo23 wrote: 22 Jun 2023, 12:24 I am happy that you can still tell us about it ;)
Shure and thx; I'm too :D

But now I'm convinced that I'm much more immune to it than the "normal person". 230V doesn't bother me anymore and if I don't have a phase tester at hand, I sometimes use my finger.
But when I was younger I had something that could have killed me. I repaired a 30" CAD tube monitor. The tube screens, especially CAD, require about 24kV of anode voltage.
I had unplugged the HV and cathode connector and also the ground lead; the screens are covered with a layer of graphite on the back, on which a spring-loaded wire is connected to ground. This ensures that the back does not become statically charged.
After repairing the chassis I only connected HV and cathode for testing. After everything went well, I wanted to put it back together and I have the chassis in my hand and I wanted to support myself on the tube with the other hand.
I only remember a bright flash in front of my inner eye. I then woke up again after 30 minutes or so with a laceration on the back of my head because it must have hit me against the wall...

Note: First of all, connect the high-voltage lead and check it three times!
DLzG
Micha

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: ESP32: Port to dimming via PWM?

#11 Post by dr.zorg82 » 29 Nov 2023, 09:34

chromo23 wrote: 19 Jun 2023, 18:22 but for ESPeasy you´ll need to put another microcontroller in between that can handle the zero crossing.
Good afternoon. can you help with this? I need to regulate the rotation speed of an asynchronous motor using a PWM, but for this I need to control the zero crossing. can you give me a diagram?

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: ESP32: Port to dimming via PWM?

#12 Post by chromo23 » 29 Nov 2023, 10:25

In general asynchronous motors don´t like to be phase controlled. The proper way to do it would be by frequency control.
But depending on you application it is possible to a certain degree. (but you´ll loose a lot of torque) I am doing it with a blower fan from the gas heating of my caravan. It works well but you have to be careful not to go to low otherwise it will stall and overheat!

I use a module for controlling motors (for making sewing machines semi"smart")
This:
Bildschirmfoto 2023-11-29 um 10.22.07.png
Bildschirmfoto 2023-11-29 um 10.22.07.png (236.07 KiB) Viewed 3133 times
https://de.aliexpress.com/item/32802025086.html

In one option it has already a power supply for the microcontroller and it works really well.
They also have a GitHub repo with the necessary code.
https://github.com/RobotDynOfficial/RBDDimmer

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: ESP32: Port to dimming via PWM?

#13 Post by dr.zorg82 » 29 Nov 2023, 12:48

chromo23 wrote: 29 Nov 2023, 10:25 They also have a GitHub repo with the necessary code
thanks, but I need more in-depth help :oops: I use esp32 and espesy. how to synchronize ESP32 and this module in the rules?

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: ESP32: Port to dimming via PWM?

#14 Post by chromo23 » 29 Nov 2023, 13:35

dr.zorg82 wrote: 29 Nov 2023, 12:48 thanks, but I need more in-depth help
This is what i would try(but it is untested so not sure if it will work as expected)

1. upload this sketch to your favorite arduino: https://github.com/RobotDynOfficial/RBD ... ometer.ino
2. connect any PWM pin of your ESP to the analog input of the arduino (in the Sketch its A0) and connect both grounds. Put a small capacitor (1uF?) in parallel (A0 to GND)
3. Adjust your values:
- change this in the sketch "USE_SERIAL.println(outVal);" to "USE_SERIAL.println(analogRead(0));"
- open a serial monitor and look at the values from the analog input
- on the ESP issue the pwm command once with 100% duty cycle and once with 0%
- note what value is shown in the serial monitor when pwm is 100% and when it is at 0%
- change the values in this line: "outVal = map(analogRead(0), 1, 1024, 100, 0);" to "outVal = map(analogRead(0), <minvalue>, <maxvalue>, 100, 0);" where <minvalue> & <maxvalue> are the values you wrote down

edit:
4. please don´t kill yourself while trying. :)

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: ESP32: Port to dimming via PWM?

#15 Post by dr.zorg82 » 29 Nov 2023, 14:02

chromo23 wrote: 29 Nov 2023, 13:35 please don´t kill yourself while trying
:) Oh thank you! now i need to think about it, gather my courage and try to do it :D

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP32: Port to dimming via PWM?

#16 Post by TD-er » 29 Nov 2023, 14:10

How isolated is that board?
So if you connect your ESP to it, is it actually being connected to either N or L of your mains power?

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: ESP32: Port to dimming via PWM?

#17 Post by chromo23 » 29 Nov 2023, 14:35

TD-er wrote: 29 Nov 2023, 14:10 How isolated is that board?
It has a transformer so relatively safe (but everything is crammed in a small space so high voltage is never far away)
An optocoupler between the ESP (with an extra power supply) and the Arduino would add an extra layer of security of course... (which would make step 3 unnecessary)

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests