Skip to content

Instantly share code, notes, and snippets.

@Sarverott
Last active September 5, 2023 09:36
Show Gist options
  • Save Sarverott/3b352c6c3fe1c3d13f3faf642cc3b23c to your computer and use it in GitHub Desktop.
Save Sarverott/3b352c6c3fe1c3d13f3faf642cc3b23c to your computer and use it in GitHub Desktop.
Simple dimmer controlled with push buttons, using Digispark ATtiny85 and IRFZ44VPbF Power MOSFET for 12v LEDs

DIY simple dimmer, using Arduino IDE and cheap components


Introduction

this guide should help you to build button-controlled light power steering. Project is not complicated, so it should be begginers-friendly


Sheme

circuit sheme

FULL SIZE IMAGE

Ingredients list

  • digispark board with ATtiny85
  • push buttons *2 ( can be replaced with single tristate momentary switch )
  • Power MOSFET ( IRFZ44VPbF by InternationalRectifier or similar supplemet )
  • 8.2KOhm resistor *2 (both can be replaced with 10KOhm)
  • 12v power supply
  • 12v powered LED stripe
  • some wires and prototype board

...from this place this gist is =="in progress"==, but so far it should be mostly enought to build it

but it will be prittier and better written next time when i will have free time... i hope TODO: circuit sheme, usefull knowledge references, user experience test, more text

after all

First prototype

photo of prototype

FULL SIZE IMAGE

/*
Simple dimmer controlled with buttons
Sarverott @ 2023
https://gist.github.com/Sarverott/3b352c6c3fe1c3d13f3faf642cc3b23c
this project ingredients:
- digispark board {
ATtiny85 :: [ Flash memory = 8kb ; frequency = 16MHz ]
Board operational voltage = 5V
( microUSB B version )
}
- push buttons *2 (can be replaced with single tristate momentary switch)
- Power MOSFET [ IRFZ44VPbF by InternationalRectifier ] (or similar supplemet)
- 8.2KOhm resistor *2 (both can be replaced with 10KOhm)
- 12v power supply <IN>
- 12v powered LED stripe <OUT>
- some wires and prototype board
NOTE:
In both cases, whether soldering or using a contact plate,
I recommend using goldpin connectors:
- between the power supply and dimmer
- between dimmer and the led strip
*/
const int pwmPin = 1; // output to controll MOSFET with PWM signal
const int lightButton = 2; // LEDs brighter button
const int darkButton = 0; // LEDs dimmer button
byte lightVolume = 255; // current light power (scale 0-255)
void setup() { // this is preparation
pinMode(pwmPin, OUTPUT); // set output pin for MOSFET
pinMode(lightButton, INPUT); // set input pin for button
pinMode(darkButton, INPUT); // set input pin for button
} // start routine
void loop() { // this is routine
analogWrite(pwmPin, lightVolume); // update current brightness
int lightButtonState = digitalRead(lightButton); // read light increse button
int darkButtonState = digitalRead(darkButton); // read light decrese button
if(lightButtonState == HIGH && lightVolume < 255) // if increse button pressed and light level below maximum
lightVolume++; // light level +1
else if(darkButtonState == HIGH && lightVolume > 0) // if decrese button pressed and light level above minimum
lightVolume--; // light level -1
delay(10); // wait 0.01 seconds
} // repeat routine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment