Tinkers Projects

Imagine | Develop | Create

Bed Side LampMain
Bed Side Lamp0
Bed Side Lamp1
Bed Side Lamp2
Bed Side Lamp3
Bed Side Lamp4
Bed Side Lamp5
I have been wanting new lights beside the bed for a while now and had an idea of making my own. I wanted a light that can be turned on/off from any light connected to the power supply. For this project, I discided to go with an Arduino UNO (ATMEGA328P) to control the power and lighting. This controller will be connected to a PC ATX power supply unit. To save power and to make sure the power supply is not running constantly, the controller can turn the power on and off. the controller uses the PC ATX PSU standby 5V power to power itself and controls the PSU. The lights use a PWM signal from the microcontroller to fade the lights up and down. The Arduino uses a LED Fading library found here and it controls the value of the PWM for each light. The microcontroller uses a PNP transistor per light to power the light. Most of the parts were made on my CNC with some made on the 3D printer. Download Arduino LED Fading Library from:
  • https://github.com/tinkersprojects/LED_fade
  • The 3D models can be downloaded from:
  • https://www.thingiverse.com/thing:3888376
  • https://www.thingiverse.com/thing:3888447
  • Code for Project

    GNU General Public License v3.0
    #include <LED_fade.h>
    
    #define ActivePin 3
    #define allOffDelay 4000
    #define NumberOfLights 4
    
    struct Lights {
        LED_fade led;  
        int inputPin;
        boolean buttonState;
        boolean mode;
        unsigned long lastOn;
      } light[NumberOfLights] = {
          {LED_fade(6) ,19,false,false,0},
          {LED_fade(9) ,18,false,false,0},
          {LED_fade(10),17,false,false,0},
          {LED_fade(11),16,false,false,0},
        };
    
    void setup() 
    {
      pinMode(ActivePin,OUTPUT);
      digitalWrite(ActivePin,HIGH);
      
      for(int i = 0; i<NumberOfLights;i++)
      {
        pinMode(light[i].inputPin,INPUT);
      }
    }
    
    void loop() 
    {
      for(int i = 0; i<NumberOfLights;i++)
      {
        bool Read = digitalRead(light[i].inputPin);
        if(Read != light[i].buttonState)
        {
          if(Read == LOW)
          {
            light[i].lastOn = millis();
            light[i].mode = !light[i].mode;
            if(light[i].mode == true)
            {
              light[i].led.SetFade(255,800);
            }
            else
            {
              light[i].led.SetFade(0,800);
            }
          }
          light[i].buttonState = Read;
        }
        if(Read == HIGH && light[i].lastOn+allOffDelay < millis())
        {
          allOff();
        }
        setlight();
      }
      setlight();
    }
    
    
    void setlight()
    {
      bool powerOn = false;
      for(int i = 0; i<NumberOfLights;i++)
      {
        light[i].led.run();
        if(!light[i].led.isFinished() || light[i].mode == true)
        {
          powerOn = true;
        }
      }
    
      if(powerOn)
        digitalWrite(ActivePin,LOW);
      else
        digitalWrite(ActivePin,HIGH);
    }
    
    void allOff()
    {
      for(int i = 0; i<NumberOfLights;i++)
      {
        light[i].mode = false;
        light[i].led.SetFade(0,800);
      }
      setlight();
    
      while(1)
      {
        bool isActive = false;
        for(int i = 0; i<NumberOfLights;i++)
        {
          setlight();
          if(digitalRead(light[i].inputPin) == HIGH)
          {
            isActive = true;
            break;
          }
        }
        if(!isActive)
          break;
      }
    }
    I have been wanting new lights beside the bed for a while now and had an idea of making my own. I wanted a light that can be turned on/off from any light connected to the power supply. For this project, I discided to go with an Arduino UNO (ATMEGA328P) to control the power and lighting. This controller will be connected to a PC ATX power supply unit. To save power and to make sure the power supply is not running constantly, the controller can turn the power on and off. the controller uses the PC ATX PSU standby 5V power to power itself and controls the PSU. The lights use a PWM signal from the microcontroller to fade the lights up and down. The Arduino uses a LED Fading library found here and it controls the value of the PWM for each light. The microcontroller uses a PNP transistor per light to power the light. Most of the parts were made on my CNC with some made on the 3D printer. Download Arduino LED Fading Library from:
  • https://github.com/tinkersprojects/LED_fade
  • The 3D models can be downloaded from:
  • https://www.thingiverse.com/thing:3888376
  • https://www.thingiverse.com/thing:3888447
  • Related Projects