Arduino Lamp Dimmer : The Best PWM Dimmer Tutorial

From : Nibodha Technologies

Arduino lamp dimmer - The best PWM dimmer tutorial

Arduino lamp dimmer – The best PWM dimmer tutorial

Ever wondered about how exciting the use of an Arduino board can be in your daily life? We present to you a very basic and a wonderful experiment. We often adjust the display brightness of our mobile phones to suit to our need. Haven’t you felt the same need for your bedside lamps or any other lighting at home? Here 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 need. And start building one of the best arduino projects.

What are the stuff required to do this?

  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 are providing 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 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 by the voltage across the Metal Oxide Semiconductor Field-Effect Transistor (MOSFET).

To know more about MOSFET – click here.

Step 1: Circuit for Arduino Lamp Dimmer

Arduino lamp dimmer - The best pwm dimmer tutorial

Lamp Dimmer Circuit

The figure clearly 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 reference when you solder your board.

To start with, 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.

Optocouplerhttp://en.wikipedia.org/wiki/Opto-isolator

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. Optocoupler, the CNY65, provides class-II isolation. (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 so as 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. Now 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%

Where, 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: We should note that this circuit should not be used to control inductive loads. MOSFET is switched asynchronously and this can cause the DC current to flow.

Now some tips regarding the whole arduino project. Starting off with, we must know that the electronic lamps, such as the 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 more the duty cycle the less is the voltage. So, we look at a case where the duty cycle is 0%. This results in 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.

Step 2 : 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 now upload this code to program your Arduino lamp dimmer and start building one of the coolest arduino projects:


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

void loop ()
{
if (Serial.available()) {
char ser = Serial.read(); //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);
break;

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

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

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

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

}
}
}

And now check out the working video for one of the best arduino projects:

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

Arduino lamp dimmer - The best pwm dimmer tutorial

Nibodha Technologies

 

– Nibodha Technologies

Nibodha is a Preferred Vacation Rentals Technology Partner. At Nibodha labs, we are actively involved in R&D to solve some of the challenges in Vacation Rental industry using IoT.

We are also the organizers of the Kochi IoT Meetup which is India’s 7th largest IoT meetup group

 

Recommended Posts
Showing 22 comments
  • diyarduino
    Reply

    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
    Reply

    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
    Reply

    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,
    John

  • Vikas Ambav
    Reply

    Where is LDR in the circuit? :/

  • Prashant Kartikeya
    Reply

    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
    Reply

    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
    Reply

    can we run ceiling fan with this circuit??

  • Akshay
    Reply

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

  • nidhi
    Reply

    how do you power the Arduino ?

  • hugo
    Reply

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

  • Bill Loney
    Reply

    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
    Reply

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

  • anthony
    Reply

    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
    Reply

    It is an old Elektor design from Ton Giesberts and has some drawbacks https://arduinodiy.wordpress.com/2015/07/25/1498/

  • akekec
    Reply

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

  • Francesco
    Reply

    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
      Reply

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

  • Lucas
    Reply

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

  • js2002
    Reply

    Hi man,

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

    Best regrads,

    Jiri

  • Bruno
    Reply

    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

95 − 94 =

Start typing and press Enter to search