Close

- Amplifiers
- Interface
- Non-Isolated DC/DC
- Voltage References
- Audio
- Linear Regulator (LDO)
- Power Management
- Webench
- Battery Management
- Logic
- Power Management IC (PMIC)
- TI Designs
- Clock and Timing
- MOSFET and IGBT Gate Drivers
- Power Modules
- TI Store
- Data Converters
- Motor Drivers
- Sensors
- MyTI Registration

visit ti.com
Login

Advertisement

#### Home » Arduino » Arduino Multiple Lights Dimmer

# Arduino Multiple Lights Dimmer

P. Marian

- light dimmers

### Share this:

- Tweet
- More

- Share on Tumblr
- WhatsApp
- Telegram
- Share

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

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

AdChoices
ADVERTISING

Arduino Lights Dimmer Sketch

    // source: https://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.

### Share this:

- Tweet
- More

- Share on Tumblr
- WhatsApp
- Telegram
- Share

No related posts.

Previous
Arduino Self Timer
Next
Arduino Icicle Lights with LEDs

## Related Tutorials

No related posts.

## Recent posts

- Little LiFePO4 Battery/Power Pack Build – Part 1
- Brushed ESCs
- FSR Sensor- A Refined Primer
- PWM to Voltage Converter Module
- Haptic or Vibration motors – A Quick Look

## 8 Comments

###

## Join the conversation!

Cancel reply
Error! Please fill all fields.

You must be logged in to post a comment.

- Mohannad Rawashdeh

  if you looking to better tools working with 110V/220 As well with easy and safe to connect and simple to program i recommend you to see this

  http://www.instructables.com/id/Control-AC-Dimmer-Lamp-Using-Arduino/

  this device allowing you to control AC voltage “on off or even as dimmer ” simply by sending PWM rather than right a complex code which allow you to integrate it with more advance project.

  http://www.sugarworld.net/

  Posted on January 13th 2017 | 5:50 pm
  Log in to Reply
- umurritiscali-it

  Thank you for this good idea. Please note that you have called “optocoupler” the couple of components “Light Emitter” and “Light Dependent Resistor”, as if they are inside the same package. This can be true, but there are few manufactors of these kind of component that could be very expensive.

  Anyone must pay attention that the input of this “optocoupler” works in AC current and can not be substitute with a conventional Optocoupler (where the input works only in DC current).

  Posted on December 03rd 2016 | 5:15 pm
  Log in to Reply
- 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

  Posted on May 24th 2015 | 1:30 pm
  Log in to Reply
- 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..

  Posted on February 19th 2014 | 6:55 pm
  Log in to Reply
  - P. Marian

    Do you want us to write the code for this or have you already done that?

    Posted on February 19th 2014 | 7:46 pm
- 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”…

  Posted on December 17th 2013 | 5:55 pm
  Log in to Reply
- 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

  Posted on December 14th 2013 | 2:25 pm
  Log in to Reply
  - Popescu Marian

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

    Posted on December 14th 2013 | 4:02 pm

Advertisement

All contents are Copyright © 2022 by AspenCore, Inc. All Rights Reserved.
Contact Us About Us Privacy Policy Terms of Use Site Map
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie Settings Accept All
Manage consent

#### Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the ...
Necessary
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Functional
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.