Zis64
Published © GPL3+

Multifunctional Work Light

A workplace lighting with useful features. Changeable LED attachments -LED display, rechargeable. Dimmable in different modes.

IntermediateFull instructions provided1 hour991
Multifunctional Work Light

Things used in this project

Hardware components

ATtiny85
Microchip ATtiny85
Single MCU
×1
MT3608 DC DC Step Up Adjustable Converter Booster Power Supply Module Output 2A
×1
2S Lithium ion Battery Charger Module
×1
2x Lithium Battery 18650
×1
JST Plug (Optional)
×1
Micro USB plug female
×1
Various electronic components: resistors, capacitors, transistors, MOSFET, optocouplers, pushbuttons, IC socket 8 DIP, raw PCB, wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Various tools: drill, grinder, saw

Story

Read more

Schematics

Eagle Files: Multifunctional Working lighting LED_v3.1b.sch

Schematic
Block Diagram
Board layout

Code

Arduino Scatch: Multifunktional_working_LED_Light_v1.4_Final_ATtiny85.ino

Arduino
Is everything in the description
/*+-------------------------------------------------------------------------------------------------------------------------------+
  |                                             Multifunctional working LED-lamp                                                  |
  +-------------------------------------------------------------------------------------------------------------------------------+
  |       Description                                                                                                             |
  |       ===========                                                                                                             |
  |   This is a small scatch for a high power LED. The brightness is controlled with the help of the One Button-Lib.              |
  |   The following functions are available to make the LED brighter with "SW_H" or darker with "SW_L":                           |
  |   Simple click, double-click, long click.                                                                                     |
  |                                                                                                                               |
  |   The second function "Display_ON" with an additional key "SW_D" switches on an output for a                                  |
  |   multifunctional display for 30 seconds.                                                                                     |
  |   Testet on a ATtiny85 @ 1 MHz (internal) with bootloader. The Sketch uses 2380 bytes (29%) flash space.                      |
  |   The Serial communication monitoring is only for debugging on a other devices and it do not work with the tiny85             |
  |   It musst be disabled bevore you upload the Code!                                                                            |
  |                                                                                                                               |
  +-------------------------------------------------------------------------------------------------------------------------------+
  |       THE FUNCTIONS:                                                                                                          |
  |       ==============                                                                                                          |
  |    .attachClick:           SW_H / SW_L      gradually lighter or darker.                                                      |
  |    .attachDoubleClick:     SW_H / SW_L      very light or dark.                                                               |
  |    .attachDuringLongPress: SW_H / SW_L      dimming via PWM.                                                                  |
  |    Display_ON:             SW_D             for 30 seconds.                                                                   |
  |                                                                                                                               |
  +-------------------------------------------------------------------------------------------------------------------------------+
  |       WIRING:                                                                                                                 |
  |       =======                                                                                                                 |
  |                               ATtiny85                                                                                        |
  |                                __  __                                                                                         |
  |                        RST   -|1 \/ 8|-  vcc                                                                                  |
  |                        SW_L  -|2    7|-  SW_D                                                                                 |
  |                        SW_H  -|3    6|-  DISPLAY                                                                              |
  |                        GND   -|4____5|-  LED                                                                                  |
  |                                                                                                                               |
  +-------------------------------------------------------------------------------------------------------------------------------+
  |       SOFTWARE INFO                                                                                                           |
  |       =============                                                                                                           |
  |   Version:          1.4_Final                                                                                                 |
  |   Writen Date:      16-05.2018                                                                                                |
  |   Autor:            Zislaw Kromski   kromski@gmx.ch                                                                           |
  |   Software Info:    Arduino IDE_v_1.8.5 https://www.arduino.cc/en/Main/Software                                               |
  |                     OneButton.h_v_1.2.0 http://www.mathertel.de/Arduino/OneButtonLibrary.aspx                                 |
  |                                                                                                                               |
  +-------------------------------------------------------------------------------------------------------------------------------+
 */

#include "OneButton.h"

#define LED 0                                          // Dimmable High power LED over MOSFET driver "attach to a PWM Pin".
#define DISPLAY 1                                      // Output-ON signal for the "Multifunktional Time Display" enabled with SW_D for 30 seconds.
#define AMOUNT 51                                      // Stepped (255/51 = 5 steps) increment/decrement brightness.
#define AMOUNTDIMM 10                                  // Running (255/10 = +/-25 steps)increment/decrement brightness.
#define SW_D 2                                         // Button for Display.
byte brightness = 0;                                   // Variable brightness Set to 0.
unsigned long currentMillis;                           // current time stamp.
unsigned long lastTime =0;                             // Preview time stamp.
const long onTime = 30000;                             // On time for Display Output "30sec".
bool SW_D_state;                                       // Flag for the button status.
bool displayOn = false;                                // Flag for the display status.

OneButton SW_H(4, true);                               // Setup a new OneButton Object for (SW1)true=internal PullUp Resistor.
OneButton SW_L(3, true);                               // Setup a new OneButton Object for (SW2)true=internal PullUp Resistor.


void setup() {

  //Serial.begin(9600);                                // Serial monitoring for debugging only.
  //Serial.println("Start");                           // ...

  pinMode(SW_D, INPUT_PULLUP);                         // Display_ON button as INPUT enable PULLUP.
  pinMode(DISPLAY, OUTPUT);                            // Display output as OUTPUT.
  digitalWrite(DISPLAY, LOW);                          // Set Display output to HIGH.
    
  SW_H.attachClick(click_SW_H);                        // link the button "SW_H" to the funktion (amount_high)PWM +AMOUNT.
  //SW_H.setClickTicks(300);                           // Set millisec after single click is assumed (For customization only).
  //setDebounceTicks(100)                              // Set millisec after safe click is assumed (For customization only).
  SW_H.attachDoubleClick(doubleclick_SW_H);            // link the button "SW_H" to the funktion (Full) PWM =255.
  SW_H.attachDuringLongPress(dimm_SW_H);               // link the button "SW_H" to the funktion (amount_dimm_high)PWM +AMOUNTDIMM.
  //SW_H.setPressTicks(100);                           // Set millisec after press is assumed (For customization only).

  SW_L.attachClick(click_SW_L);                        // link the button "SW_L" to the funktion (amount_low)PWM -AMOUNT.
  SW_L.attachDoubleClick(doubleclick_SW_L);            // link the button "SW_L" to the funktion (Off)/PWM =0.
  SW_L.attachDuringLongPress(dimm_SW_L);               // link the button "SW_L" to the funktion (amount_dimm_low)PWM -AMOUNTDIMM.
  
  analogWrite(0, 50);                                  // Whenn Device ON, turn LED on.
  }

void loop() {
//----------Funktions for Display_ON---------//
  SW_D_state = digitalRead(SW_D);                      // Status variable for SW_D.
  currentMillis = millis();                            // Variable current time takes timestamp.
  if(!displayOn && SW_D_state == LOW){                 // Query: If SW_D is pressed and display is not on.
    lastTime = currentMillis;                          // Last time update.
    displayOn = true;                                  // Change display status to on.
    digitalWrite (DISPLAY, HIGH);                      // Turn Display on.
    //Serial.print("Display ON   ");                   // ...
    //Serial.println(millis());                        // ...
    }        
  if(displayOn && currentMillis -lastTime >onTime){    // Only if display is on and past time greater than onTime.
        displayOn = false;                             // Change display status to off.
        digitalWrite(DISPLAY, LOW);                    // Turn Display off.
        //Serial.print("Diaplay OFF   ");              // ...
        //Serial.println(currentMillis);               // ...
        }          
 
  SW_H.tick();                                         // keep watching the push buttons.
  SW_L.tick();                                         // keep watching the push buttons.
  delay(10);                                           // Short break is recommended by the OneButton lib.
}

//----------Funktions for brighter-----------//

void click_SW_H(){                                     // Function one click  for big steps.
  if(brightness >204){                                 // Query the variable for balancing so that LED gets very light in the last step (fifth click).
    brightness =255;                                   // Updating the variable 
    analogWrite(LED, brightness);                      // Analog write the PWM values.
    //Serial.print("click_SW_H  PWM = ");              // ...
    //Serial.println(brightness);                      // ...
    }
  
  if(brightness <=204){                                // Query the variable if PWM less than 204.
    brightness = brightness +AMOUNT;                   // If yes, then Updating the variable and increase in big steps (+ AMOUNT).
    analogWrite(LED, brightness);                      // Analog write the PWM values.
    //Serial.print("click_SW_H PWM = ");               // ...
    //Serial.println(brightness);                      // ...
    delay(400);                                        // Waiting time.
    }
}
void doubleclick_SW_H(){                               // Function double-click for very bright.
    analogWrite(LED, 255);                             // Analog write the PWM values.
    brightness = 255;                                  // Updating the variable.
    //Serial.print("doubleclick_SW_H  PWM = ");        // ...
    //Serial.println("255");                           // ...
}
void dimm_SW_H(){                                      // Function Keep button for slow dimming.
  if(brightness >245){                                 // Query the variable for balancing so that LED gets very light in the last step (25th click).
    brightness = 255;                                  // Updating the variable.
    analogWrite(LED, brightness);                      // Analog write the PWM values.
    //Serial.print("dimm_SW_H  PWM = ");               // ...
    //Serial.println(brightness);                      // ...
    }
  
  if(brightness <=245){                                // Query the variable if PWM less than 245.
    brightness = brightness +AMOUNTDIMM;               // If yes, then Updating the variable and increase in small steps (+ AMOUNTDIMM).
    analogWrite(LED, brightness);                      // Analog write the PWM values.
    //Serial.print("dimm_SW_H  PWM = ");               // ...
    //Serial.println(brightness);                      // ...
    delay(400);                                        // Waiting time for the speed of dimming.
    }
}

//----------Funktions for darker-----------//

void click_SW_L(){                                     // Function one click  for big steps.
   if(brightness <51){                                 // Query the variable for balancing so that LED gets very dark in the last step (fifth click).
    brightness = 0;                                    // Updating the variable
    analogWrite(LED, brightness);                      // Analog write the PWM values.
    //Serial.print("click_SW_L  PWM = ");              // ...
    //Serial.println(brightness);                      // ...
    }
  
  if(brightness >=51){                                 // Query the variable if PWM greater than 204.
    brightness = brightness -AMOUNT;                   // If yes, then Updating the variable and decrease in big steps (- AMOUNT).
    analogWrite(LED, brightness);                      // Analog write the PWM values.
    //Serial.print("click_SW_L  PWM = ");              // ...
    //Serial.println(brightness);                      // ...
    delay(400);                                        // Waiting time.
    }
}

void doubleclick_SW_L(){                               // Function double-click for very dark.
    analogWrite(LED, 0);                               // Analog write the PWM values.
    brightness = 0;                                    // Updating the variable.
    //Serial.print("doubleclick_SW_L  PWM = ");        // ...
    //Serial.println("0");                             // ...
}
void dimm_SW_L(){                                      // Function Keep button for slow dimming.
  if(brightness <10){                                  // Query the variable for balancing so that LED gets very dark in the last step (25th click).
    brightness = 0;                                    // Updating the variable.
    analogWrite(LED, brightness);                      // Analog write the PWM values.
    //Serial.print("dimm_SW_L  PWM = ");               // ...
    //Serial.println("0");                             // ...
    }
  
  if(brightness >=10){                                 // Query the variable if PWM greater than 10.
    brightness = brightness -AMOUNTDIMM;               // If yes, then Updating the variable and decrease in small steps (- AMOUNTDIMM).
    analogWrite(LED, brightness);                      // Analog write the PWM values.
    //Serial.print("dimm_SW_L  PWM = ");               // ...
    //Serial.println(brightness);                      // ...
    delay(400);                                        // Waiting time for the speed of dimming.
    }
}

// END SKETCH

Credits

Zis64

Zis64

2 projects • 2 followers

Comments