Introduction: Safe and Simple AC PWM Dimmer for Arduino / Raspberry Pi

Dimmer With  MOSFET

This circuit shows that dimmers intended for use at mains voltage do not always have to contain a triac.
Here, a MOSFET (BUZ41A, 500 V/4.5A) in a diode bridge is used to control the voltage across an incandescent bulb with pulse-width modulation (PWM). The power supply voltage for driving the gate is supplied by the voltage across the MOSFET.



add on board:raspberry pi diy add-on board

Step 1: Circuit Diagram and Description

The power supply voltage for driving the gate is supplied by the voltage across the MOSFET. D6, R5 and C2 form a rectifier. R5 limits the current pulses through D6 to about 1.5 A (as a consequence it is no longer a pure peak rectifier). The voltage across C2 is regulated to a maximum value of 10 V by R3, R4, C1 and D1. An optocoupler and resistor (R2) are used for driving the gate.

R1 is intended as protection for the LED in the optocoupler. R1 also functions as a normal current limiting device so that a ‘hard’ voltage can be applied safely. The optocoupler is anold acquaintance, the CNY65, which provides class-II isolation. This ensures the safety of the regulator. The transistor in the optocoupler is connected to the positive power supply so that T1 can be brought into conduction as quickly as possible. In order to reduce switching spikes as a consequence of parasitic inductance, the value of R2 has been selected to be not too low: 22 kΩ is a compromise between inductive voltages and switching loss when going into and out of conduction.



An additional effect is that T1 will conduct a little longer than what may be expected from the PWM signal only. When the voltage across T1 reduces, the voltage across D1 remains equal to 10 V up to a duty cycle of 88 %. A higher duty cycle results in a lower voltage. At 94 % the voltage of 4.8 V proved to be just enough to cause T1 to conduct sufficiently. This value may be considered the maximum duty cycle. At this value the transistor is just about 100 % in conduction. At 230 V mains voltage, the voltage across the lamp is only 2.5 V lower, measured with a 100-W lamp. Just to be clear, note that this circuit cannot be used to control inductive loads. T1 is switched asynchronously with the mains frequency and this can cause DC current to flow.

Electronic lamps, such as the PL types, cannot be dimmed with this circuit either. These lamps use a rectifier and internally they actually operate off DC.A few remarks about the size of R3 and R4. This is a compromise between the lowest possible current consumption (when the lamp is off) and the highest possible duty cycle that is allowed. When the duty cycle is zero, the voltage across the resistors is at maximum, around 128 V with a mains voltage of 230 V. Because (depending on the actual resistor) the voltage rating of the resistor may be less than 300 V, two resistors are connected in series. The power that each resistor dissipates amounts to a maximum of 0.5 W. With an eye on the life expectancy, it would be wise to use two 1-W rated resistors here.


Author: Ton Giesberts - Copyright: Elektor Electronics
Circuit description source: http://www.learningelectronics.net/circuits/dimmer-with-mosfet.html

Step 2: Assembling Steps

Step 3: AC PWM Dimmer With Arduino

Step 4: Arduino Script

/*
Fading

This example shows how to fade an LED using the analogWrite() function.

The circuit:
* LED attached from digital pin 9 to ground.

Created 1 Nov 2008
By David A. Mellis
modified 30 Aug 2011
By Tom Igoe

http://arduino.cc/en/Tutorial/Fading

This example code is in the public domain.

*/


int ledPin = 3;    // LED connected to digital pin 9

void setup()  {
  // nothing happens in setup
}

void loop() 
{
 
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=1) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);        
    // wait for 30 milliseconds to see the dimming effect   
    delay(50);                           
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1)
  {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);        
    // wait for 30 milliseconds to see the dimming effect   
    delay(50);                           
  }

// analogWrite(ledPin, 25);       
 
}

Step 5: AC PWM Dimmer With Raspberry Pi

Step 6: Raspberry Pi Gpio Setup

step 1   install wiringPi GPIO library

http://wiringpi.com/download-and-install/

step 2:  GPIO setup

open lxterminal/ root terminal   program
type

sudo su                        # for super user privilege

gpio readall                 #display the gpio status  

gpio mode 1 PWM     # set the gpio -18 [wiringPi gpio-1]  mode to PWM

gpio readall                 # check the new status of  wiringpi pin1/gpio -18 mode

gpio mode 1 0         #off

gpio mode 1 1        #pwm level 1

gpio mode 1 5       #pwm level 5


step 3: how to create and run a script file in raspberry pi

step1: open lxterminal/rootterminal

step 2: sudo su                        # for super user privilege

step 3:sudo nano PWM_test.sh   #open an editor with file name PWM_test.sh

step 4: type the program,save and exit from editor [ ctrl+X  and y  for save and exit ]

step 5: bash PWM_test.sh    #run the script

step 6: ctrl+z /   ctrl+c      #exit from the program



Step 7: Video - Arduino

Step 8: Video Raspberry Pi

light dimming using bash script



light dimming using terminal commands



 

Step 9: Downloads



Step 10: Reference

Comments

author
elelek made it! (author)2017-04-01

PWM Dimmer for Arduino And Raspberry PI

https://goo.gl/aESBve

0000029_pwm-ac-light-dimmer-module-50hz-60hz-for-arduino-raspberry-led-smart-home_550[1].jpeg
author
ManishkumarB made it! (author)2017-01-24

the MOSFET is over heating . I m using table fan as output

author
Sugar Device made it! (author)2017-01-13

This is more safe and way better than this
https://www.instructables.com/id/Control-AC-Dimmer-...

author
sonuk14 made it! (author)2016-12-22

It's not working the lamp is always high..

author
zarneelr made it! (author)2016-10-06

plz kindly tell me the circuit diagram for AC pwm dimmer

author
pradeepk17 made it! (author)2016-10-03

Please specify all components which is used to design...??

author
MaximillianT1 made it! (author)2016-09-26

sdg

author
MaximillianT1 made it! (author)2016-09-26

zsdf

author
CaledM1 made it! (author)2016-09-14

Hola, me pueden ayudar, no me funciona el circuito, no se si sera porque estoy utilizando un IRF740 en ves del IRF830, el voltaje de entrada AC es el mismo al de salida AC ayuda

author
AbhijithC2 made it! (author)2016-09-01

Hello there.. Can anyone help me to make this circuit respond to high frequency? I got it working okay till 3kHz. I need it to work with a 32kHz frequency. Which component should be swapped for making work at such a frequency?

IMG_20160901_184745_345.jpg
author
BelaalE made it! (author)2016-06-18

Hey
I'd ask about the full power capacity of this circuit ?
How many Watts ?

author
AbhijithC2 made it! (author)AbhijithC22016-08-31

It depends on the current carrying capacity of the bridge and the mosfet. For example, if you need to control a 1000W load, the Mosfet and diodes in the bridge should carry atleast 5 Amps (1000W divided by 230V) of current. You can upgrade the circuit with higher current diodes and MOSFETs to achieve this.

author
MikhailaE made it! (author)2016-07-14

hi i'm a college student and i'm planning on using this for my project can you please send me the source code for this thanks here is my email add mikhaila1597@gmail.com

author
Pivato made it! (author)2016-07-13

I used it as part of my Capstone project in Engineering.

WhatsApp-Image-20160713 (5).jpegWhatsApp-Image-20160713 (6).jpeg
author
Pivato made it! (author)2016-06-25

Just used this as part of my capstone project. It worked great!

author
madaputrasp made it! (author)2016-06-23

Hey, I'd ask about the switched in this circuit. can i put "switched"? thanks

author
satyencareer made it! (author)2016-06-13

hi,

I really tried multiple times but I am not getting success and being disappointed every time. I want to build this circuit can anyone send this pre-build circuit so that I can understand this where I am going wrong. I can pay for it :(

author
ythomas made it! (author)2016-04-18

how many light bulbs can I connect with this circuit?

author
FrancescoP32 made it! (author)2016-01-23

Thanks a lot for this instructable, I made it with an IRF830 and it works great!

IMG_2853.jpg
author
RahardiK made it! (author)RahardiK2016-04-18

hello can you post component list above ? thanks

author
FrancescoP32 made it! (author)FrancescoP322016-04-18

Hi, I've used the exact same parts listed in the project except for the mosfet that in my case is an IRF830.

author
LaxmikantS made it! (author)LaxmikantS2016-04-03

hey plz can send me the component lists which you have used for this circuit it will b helpfull..

author
FrancescoP32 made it! (author)FrancescoP322016-04-18

I'm so sorry for the delay, I've used the same parts listed in the project, execpt the mosfet that is an IRF830.

author
BelaalE made it! (author)2015-12-05

Hey !
first of all , good job.

i'm asking if this circuit could used for the LED dimming??

author
diy_bloke made it! (author)diy_bloke2016-02-23

Most dimmable leds are designed to work with edge cutting dimmers. This is a pwm dimmer, so the reply is 'no'

author
eduSD made it! (author)eduSD2015-12-07

I tried it on a dimmable led bulb but it didn´t work. The bulb stayed on 100%.

author
PavelI1 made it! (author)2015-12-08

Hello. Perfect job!

I have tested this circuit too.

It was with IRF830. Works very well with an incandescent bulb 60W.

But I saw with peripheral vision the small flicker effect (in case of the light should be stable).

I think this is depends on the frequency 50 Hz.

And was other flicker effect (in case of the light have to fade out slow). This is depends on the PWM signal.

Of course I made small modification:

C1 => 100 mF 50V (no more flicker effect),

C2 => 470 nF 275V (i hadn't other),

R3, R4 and R5 => 2-W resistors (temperature ca. 40C degrees),

R2 => 1-W resistors,

IRF830 => with radiator!

I don't know why the same problem with a dimmabled led bulb but it wouldn't dimm (100% on always).

The bulb was OSRAM LED Parathoom Pro 12W 650lm (dimmable).

And the questions - what you can recommend for circuit modification (PWM entrance)?

How to minimize depending on the PWM signal?

IMAG0056.jpg
author
diy_bloke made it! (author)diy_bloke2016-02-23

not surprising the dimmable led doesnt work. Most dimmable leds and definitely the Parathoom are designed to work with edge cutting dimmers. This is a pwm dimmer

author
eduSD made it! (author)eduSD2015-12-08

I also switched to 2W resistors. Have you measured the temperature with no PWM (light off)? That's when the resistors are going to dissipate at peak current. Even though mine are 2W they're reaching about 80 C. Are you running on 230V?

author
PavelI1 made it! (author)PavelI12015-12-08

Hello eduSD.

- ... running on 230 V? => yes

- ... at peak current. => the fact is that the PWM signal duration in my case only 5 minutes (switch off 220V) and check temperature (test finger). It is 40-45 degrees maximum not more.

- ... no PWM (light off)? => may be 23-25 degrees.

80C hmm... good question... I have to check the temperature within a long period.

author
osama500 made it! (author)2016-02-20

i just made it and it work fine but the transistor get overheating so fast how can i fix that plz

author
integra386 made it! (author)2014-05-22

Hi, the circuit works properly !

Thank you so much for sharing it ... my bearded dragons thank you!

IMG_20140522_095529.jpgIMG_20140522_095541.jpg
author
BarryV made it! (author)BarryV2016-02-09

Hello

Can you help me with this product as i am trying to build one. not winning! :-/

Please can you send me the part list and schematic plus the pcb layout?

Thank you..

B-)

author
gary.buynary made it! (author)gary.buynary2014-10-27

Does your LED lamp dim all the way to an 'off' state? What MOSFET did you use?

author
maniacse made it! (author)maniacse2015-05-05

Doesnt look like LED at all mate..

author
diy_bloke made it! (author)diy_bloke2015-07-07

indeed, more like a halogen lamp

author
diy_bloke made it! (author)diy_bloke2015-07-07

that is a very decent PCB

author
LivingFlame made it! (author)2016-01-26

module does not want to work the first time.((

a lamp is turned on and there is no reaction more

Безимени-1.png
author
chinmya made it! (author)2016-01-18

Can i use thuthis circuit for controlling speed of ceiling fan? Because it is inductive load.

author
mirceaC made it! (author)2015-12-29

I made this circuit and work well, i use a buz91, and for pwm a clasic circuit with 555...

Take care about work frequency because if is to high the MOSFET are getting hot !

20151229_203018.jpg
author
boylah made it! (author)2015-12-19

Hello!

Thanks for your great tutorial!

Can I use this dimmer with 200W LED driver?

https://www.meanwell-web.com/en/product_info.php?p...

author
eduSD made it! (author)2015-12-07

I made it with an IRF840 as well. Works very well with an incandescent bulb. I had a flicker before but it was caused by my PWM source, once I worked that out it worked flawlessly. Tried with a dimmabled led bulb but it wouldn't dimm (100% on always).

dimmer1.jpgdimmer2.jpg
author
NatenB made it! (author)2015-08-02

I used the IRF840 mosfet as the BUZ41A is not available were I am. I also added a 100uh inductor to eliminate flicker. Worked well with 1000 Watts with two 500W Halogens hence the large heatsink.

150802_dsc_0355.jpg150802_dsc_0354.jpg150802_dsc_0353.jpg
author
mirceaC made it! (author)mirceaC2015-11-30

Can you post the diagram? I want to see where you put the inductor. Thank you !

author
NatenB made it! (author)NatenB2015-12-04

Hello micrceac, Pls see the schematic.

Light Dimmer.png
author
replaysMike made it! (author)replaysMike2015-09-10

Can you post a parts list for yours? I too can't get the BUZ41A and will go with an IRF840 from digikey, but I can't figure out where to get the caps (C2). Are both the yellow and red components caps in your photos?

author
NatenB made it! (author)NatenB2015-09-12

Hello Mike.
I have attached the pics of the yellow and maroon caps. Yellow is 220n (C2) and maroon one is 2.2uf (C1). Mind you getting these are often tricky because as you can see the labels on them need some interpretation for capacitance readings. Please note my circuit is for 1000 Watts load hence the large heat-sinks, although I will be adding larger ones later.


  1. 1k
  2. 22k
  3. 33k x2
  4. 220 E
  5. 10v 0.4 w Zener
  6. IN4007
  7. 2.2u 250 V
  8. 220n 275 V
  9. Bridge 10A, 5A
  10. CNY65
  11. Inductor 100uH
  12. Mosfet (NTE2398 or IRF840)
cap_0.22uf_275V_0.80$.jpgcap_2.2uf_250V_0.60$.jpg
author
replaysMike made it! (author)replaysMike2015-09-12

Ty NatenB! I'm going to put this together, with the choke and see how it performs. I don't know if the original circuit will dim led's (might need the zero cross method to do that).

author
vksgaikwad made it! (author)vksgaikwad2015-08-09

Hi NatenB, Nice tutorial I have design the Light dimmer using IRF840 but my mosfet gets heated as connect load of <= 100W. Could you please share your schematic as you are able to connect load upto 1000W. I want to build and test the results.

author
NatenB made it! (author)NatenB2015-08-12

Hello :)
There is really no change other than the 100uH induction in the output path and the IRF840. Please note: provide a sufficiently large heatsink and forced cooling with a fan if you want to make it work with 1000W. Also keep the enclosure large in size to allow unhindered airflow.
I cannot seem to upload images for some reason.

About This Instructable

224,746views

210favorites

License:

Bio: embedded system enthusiast ...
More by Jestin_Cubetech:Wireless Robo-car  using  360°  servo motorRaspberry Pi - Revision 2  DIY Add-On Boardwater tank automation - prototype
Add instructable to: