X
arduino lights dimmer

Arduino Multiple Lights Dimmer

This Arduino lights dimmer project is based on Doug Hitchcock’s comment:
“I need to have a lamp dimmer that can “cascade” from one lamp to the next (up to 4 lamps). Basically, when you close a switch, the first lamp begins to light from dim to 100%. Once lamp #1 reaches 100%, then that triggers dimmer circuit #2 and lamp #2 begins to go from dim to bright. This is repeated up to four lights. How to cascade dimmer circuits?Obviously, when the switch is opened, dimmer #4 goes to zero, then dimmer #3 ramps down to zero, then #2, and finally #1 circuit. Help please.”

I only had the Arduino UNO board and a couple of LEDs so this project was not tested completly using the LDR optocouplers and the light bulbs, but is should work accordingly to this automatic lamp dimmer circuit.

Schematic of the Arduino Lights Dimmer Circuit

arduino lights dimmer

You must have 4 identical circuits for each lamp that are connected to pins 3, 5, 6 and 9 on the Arduino UNO Board. Also be aware that this project is very dangerous because it is connected to 220V and this voltage is available on all the components except the Arduino board (that is why we used the optocoupler).

Video presentation of the working projects with LEDs

Arduino Lights Dimmer Sketch

// source: http://www.electroschematics.com/9368/arduino-multiple-lights-dimmer/
int LampsPin[] = {3,5,6,9}; // the pins where the lamps are connected
int Lamps = sizeof(LampsPin)/2;
int SwPin = 2; // the pin where the switch is connected
int dimm = 20; // increase for longer dimming interval
int state = 0;

void setup () {
  for(int thisLamp = 0; thisLamp < Lamps; thisLamp++) {
     pinMode(LampsPin[thisLamp], OUTPUT);
  }
  pinMode(SwPin, INPUT);
}

void loop() {
  int SwState = digitalRead(SwPin); // read the switch state
  if(SwState == HIGH && state == 0) { // if the button is pressed
      for(int thisLamp = 0; thisLamp < Lamps; thisLamp++) {
        for(int i = 0; i < 255; i++) {
          analogWrite(LampsPin[thisLamp], i);
          delay(dimm);
        }
      }
      state = 1;      
   } 
   if(state == 1 && SwState == LOW)  {
       for(int thisLamp = Lamps - 1; thisLamp >= 0; thisLamp--) {
          for(int i = 255; i >= 0; i--) {           
             analogWrite(LampsPin[thisLamp], i); 
             delay(dimm);
          }
       }
       state = 0;
   }   
}

Remember you can use only the pins marked with tilda sign (3, 5, 6, 9, 10 and 11) on Arduino UNO board. Also the R value depends on the type of optocoupler that you choose to use. It must be an optocoupler with photoresistor or LDR output.

6 Comments

Join the conversation!

Error! Please fill all fields.
  • Zaid Haymoor

    Thank you , it’s a great and useful article, but please if you can tell me how the dimmer circuit works or give me a link so I can understand it.
    thank you again

  • Erik

    I have a use for a circuit with arduino with two lights or bright large LEDs and one led starts of dim and cycle to full brightness.. Just when it reaches full brightness a second LED switches on at full brightness and cycles down to minimum or of. At the moment light . Led 2 comes on at full brightness .. Led 1 must switches of ..this sequence from light 1 on..dim to bright.. Light 2 on full brightness to dim and of must reapeat every time one enables the process via a switch or some other way.. Want to also have a way to control the rate at which each light goes brightr or dimmer.. No electronic skills but think the arduino is a great starting point..

  • Doug Hitchcock

    Hi Popescu,
    Well, I have to say “merci” as this is a cool circuit. I had not thought of basing it on the Arduino, but that now makes perfect sense.

    I had contemplated something similar to the “attack” and “sustain” of an electronic piano. I want to use this as an interactive lighting tool. The longer you press the button input the lights grow brighter and brighter in cascade sequence and then when you let off the button, the sequence is reversed.

    My next step is to think about replacing the switch input with a load cell that can really dynamically change the value of “dimm” parameter such that if you hit the switch “hard” the lights come up faster than if you hit the switch input “softer”…

  • T.K.Hareendran

    Nice one! I think we can use a home-made optocoupler (LED+LDR) here.
    Datasheet of a commercial product:
    http://www.farnell.com/datasheets/102616.pdf

    • Popescu Marian

      I am not sure if it will work with that one, my guess is that it needs to have variable resistance.

  Search 4 million + Products
Browse Products