How to Make an Arduino Powered Lamp Dimmer

By Nibodha Technologies

Arduino lamp dimmer - The best PWM dimmer tutorial

Our Arduino lamp dimmer 

Ever wondered how to bring an Arduino board into your daily life? We often adjust the display brightness of our mobile phones to suit to our need. With this project, you can do that for your bedside lamps or any other lighting at home. We are going to teach you how to make an Arduino lamp dimmer. Using this project, you can control the brightness of your table lamp according to your needs and start building one!

Required Materials

  1. Arduino
  2. Resistors: 330ohm(1No.s), 33k(2no.s), 22k(1No.s), 220ohm(1No.s)
  3. Optocoupler: 4N35(1No.s)
  4. Diode: 1N4508(4No.s), 1N4007(1No.s), Zener 10V.4W(1No.s)
  5. Capacitor 2.2uF/63V(1No.s), 220nF/275V(1No.s)
  6. MOSFET: IRF830A
  7. Lamp: 100W
  8. 230V Supply
  9. Socket
  10. Solder dot board and Soldering kit

How Does it Work?

In this project, we are going to adjust the brightness of the lamp connected to the circuit by serial port. The brightness can be changed according to the commands we provide to the serial port. We will be using these particular commands in this Arduino project:

  • ‘0’ to TURN OFF.
  • ‘1’ for 25% brightness.
  • ‘2’ for 50% brightness.
  • ‘3’ for 75% brightness.
  • ‘4’ for 100% brightness.

We will design a Pulse Wave Modulated (PWM) dimmer circuit which will use an IRF830A in a diode bridge which is used to control the voltage across the bulb with pulse wave modulation (PWM). The power supply voltage for driving the gate is supplied with the voltage across the Metal Oxide Semiconductor Field-Effect Transistor (MOSFET).

Circuit for the Arduino Lamp Dimmer


Arduino lamp dimmer - The best pwm dimmer tutorial

Lamp Dimmer Circuit


The figure above explains the positioning of the different electrical components in the circuit. Follow the circuit diagram to solder your dot board.


Arduino Lamp Dimmer Soldering best pwm dimmer tutorial

Arduino Lamp Dimmer Soldering

You can use this picture as a reference when you solder your board.

To start, we have the diode D6, the load resistor R5, and the capacitor C2 connected. This forms our rectifier. Also, in the circuit, the positioning of the resistor R5 is such that it limits the current pulses through D6 to about 1.5A. This shows that the rectifier is not a pure peak rectifier.

Talking about the capacitor C2, the voltage across it is regulated to a maximum value of 10V by the resistors R3 and R4, capacitor C1, and diode D1.

The optocoupler and the remaining resistor R2 are used for driving the gate.

The function of R1 is to protect the LED in the optocoupler. Like R5, R1 also limits the current so that a ‘hard’ voltage can be applied safely. The optocoupler, CNY65, provides class-II isolation. (A class-II or double insulated electrical appliance is the one which has been designed in such a way that it does not require a safety connection to electrical earth). This is good enough to ensure safety to the regulator.

Now we need the conduction in the MOSFET as quickly as possible. For this, we connect the transistor in the optocoupler to the positive power supply. We have to make a compromise between the switching loss and the inductive voltages as we keep the rating of R2 a bit high, i.e., 22 K-ohm. This is done to reduce the switching spikes as a consequence of parasitic inductances.

One additional advantage of the MOSFET is that it helps in the conduction. It conducts for a longer duration than a PWM would do single headedly. Some interesting information is that when the voltage across the MOSFET reduces, the voltage across D1 remains equal to 10V upon a duty cycle of 88%.

A duty cycle is the percentage of one period up to which a signal is active. A period is the time it takes to complete an on-and-off cycle. The expression for the duty cycle is:


D = (T/P)*100%


D is the duty cycle.

T is the time the signal is active.

P is the total period of the signal.

A higher duty cycle results in lowering of the voltage. For an instance, at 94% duty cycle, the voltage of 4.8A proved to be just enough to cause the MOSFET to conduct sufficiently. This value is therefore considered as the maximum duty cycle. Also, at this value, the transistor conducts just about cent percent. Measuring with a 100W bulb, the voltage across a 230V mains supply is just 2.5V lower.

Note: This circuit should not be used to control inductive loads. The MOSFET is switched asynchronously and this can cause the DC current to flow.

Some tips regarding the whole Arduino project. Starting off with, we must know that electronic lamps, such as PL types, cannot be dimmed with this circuit. This is because these lamps use a rectifier and internally, they operate off DC. A few remarks about the value of R3 and R4. This is a compromise between the lowest possible current we consume (when the lamp is off) and the highest possible duty cycle that is allowed. Now as mentioned earlier, the higher the duty cycle, the less is the voltage. So, we look at a case where the duty cycle is 0%. This results in a maximum voltage across the resistors around 128V across a supply of 230V. 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.

Uploading the Code to Arduino

Here you can see a few more pictures of the finished product.


Arduino lamp dimmer - The best pwm dimmer tutorial

Arduino lamp dimmer

Arduino Script

You can upload this code to program your Arduino lamp dimmer:

intledPin = 3;
void setup()
Serial.println(“Serial connection started, waiting for instructions…n0 = Offn1 = 25%n2 =50%n3 = 75%n4 = 100%”);

void loop ()
if (Serial.available()) {
char ser =; //read serial as a character

//NOTE because the serial is read as “char” and not “int”, the read value must be compared to character numbers
//hence the quotes around the numbers in the case statement

switch (ser)
case ‘0’:
analogWrite(ledPin, 0);

case ‘1’:
analogWrite(ledPin, 64);

case ‘2’:
analogWrite(ledPin, 128);

case ‘3’:
analogWrite(ledPin, 192);

case ‘4’:
analogWrite(ledPin, 255);
Serial.println(“Invalid entry”);



Check out the working video for the project!



Go ahead and make your own Arduino lamp dimmer and get started at domestic electronics.

Recommended Posts
Showing 35 comments
  • Carlos

    Thank you, I’m doing a project of a wireless dimmer with the arduino and with an ethernet shield and when I put them together, it was wonderful, now I have a wireless dimmer. thank you very much really!

  • Dimitris

    Hello, I constructed the above circuit ( and it works fine by using an incandescent bulb. But when I replaced it with a dimming led it doesn’t work correctly. It is becoming full bright and in the intermediate position it is flashing. What am I doing wrong?


    Hi, I have made the circuit and tested but why does the lamp burns even with zero pwm signal and when the Arduino is turned off.

  • steven

    Hey i would like to know if the led works on DC or AC and will the circuit work if i give it less voltage? like instead of 230V AC i give it like 24V AC or 110V AC?

  • Alper


    How much output power does this circuit support. I mean can we use this circuit to dim e.g. three 100W bulbs (total of 300W)?


  • Arduino Developer

    Just little searched I found this only. Price looks good.

  • Dipendrasinh D. Bhati

    Can I use inductive load in place of resistive load

    • Anon


  • ahmed abdeljelil

    Could any one help me with isis simulation for this circuit??

  • [email protected]

    who can help me with isis simulation in order to realize the electonic circuit ?

  • Diegohap

    What is the part number of the Zener?. The Zener is 4W or 0.4W?

  • na

    ​Another link to find prebuilt ac dimmers for Arduino and Raspberry PI.

  • Rafael

    can i use it on 60hz 120v?

  • diyarduino

    it teach how to fishing. There are some ready circuits online. if you go amazon and search “ac dimmer arduino” you will find great devices. I used one of them in work.

  • Denis

    Hi. I have built the board but I have a problem. The lamp is always at 100%. Maybe there is a mistake. Does someone suggest me where could be the problem?

  • John

    Hi colleagues,

    Thanks for the log. It is quite interesting. As the upper part seems to be a ac/dc converter, may I connect the 4N35’s pin 5 directly to my DC pin of the arduino and remove the rest of the upper-part components?

    Thanks in advance,

  • Vikas Ambav

    Where is LDR in the circuit? :/

  • Prashant Kartikeya

    The circuit works fine for incandescent Bulbs, but CFL bulbs flicker even when the DC side of Opto-coupler is open. Can you please tell me why and how to correct it?

  • Abhi

    Please put reference or a link to the source of this circuit. I think this circuit first appeared in elektor.

    There are some drawbacks and there are some methods to overcome those drawbacks. Please include them also.

  • Gautam

    can we run ceiling fan with this circuit??

  • Akshay

    Hi.. Can I use this circuit with raspberry pi?? anybody tried using rasp pi and controlled led light?

  • nidhi

    how do you power the Arduino ?

  • hugo

    what would i do if i don’t have the MOSFET: IRF830A?, what mosfet recommendme?

  • Bill Loney

    If I could understand what you’re trying to say that would be okay… I’m a term 5 electrical engineering student and I still don’t understand. I am a white male, 200 lbs, completely lucid. Thank you for your time.

  • Rudy

    man, please, can you show us the coding from the video please….

  • anthony

    Will this work with 10watt led? if so what modification will I do to dim 4 of them? 4 led will be in-synch

  • kees

    It is an old Elektor design from Ton Giesberts and has some drawbacks

  • akekec

    LDR is used in the video. But there is no LDR in software.
    Can I be wrong.

  • Francesco

    Hi, I’m a newbie, so I’m sorry if I’m not able to debug it by myself. I can’t get the circuit to work, can you please post more detailed photos so I can make sure that I’m doing everything correctly? Thanks a lot!

    • Rudy

      hi man, do you get the detailed picture yet? would you share it with me? thanks so much man…

  • Lucas

    Mine works but flickers once I set the duty cycle. Any advise?

  • js2002

    Hi man,

    I suggest to add simple LC or RC filter to reduce RF emitting.

    Best regrads,


  • Bruno

    Hello man, I’m using your circuit with a raspberry pi, and it works great, but I have a problem, when I set the maximum light intensity, the bulb and the IRF830 starts to burn, what can I do?

    Best Regards

Leave a Comment

− 7 = 1

Start typing and press Enter to search