Documente Academic
Documente Profesional
Documente Cultură
by adachsoft
In this tutorial I will show you how to make LED This article can also see here:
control using Arduino with PWM. For dimming control
I will use an encoder. So it will also be a tutorial on Arduino PWM LED dimmer - 6x10W LED
how to use the encoder in Arduino projects. In the
project I use 6 LEDs each 10W, as a power source I Diy LED lights panel for 5$ - Cheap and Easy 6 x
will use a 14.4V battery from a cordless drill. In this 10W
guide will use my previous project DIY mega head
flashlight with 6x10W LEDs.
Step 1: Components
Arduino UNO
LM2596 - step down converter
BC547
BC557
IRF540
2 x 10K ohm
2 x 1K ohm
Encoder
Mega head flashlight
Step 4: Software
This is a piece of code responsible for handling the button encoder.If the button is pressed and the PWM is 100%,
then turn off the LEDs. If the button is pressed and the PWM is not 100% then set the PWM to 100%.
This code fragment is responsible for handling encoder. It recognizes whether the encoder is rotated left or right. If
left, reduce the PWM value. If right it increases the PWM value.
Arduino PWM LED Dimmer - 6x10W LED: Page 2
if( current_time - loop_time >= 5 ){
encoder_A = digitalRead(EN_PIN_A); //Read encoder pin A
encoder_B = digitalRead(EN_PIN_B); //Read encoder pin B
#define EN_PIN_A 12
#define EN_PIN_B 8
#define BTN_PIN 4
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(EN_PIN_A, INPUT_PULLUP);
pinMode(EN_PIN_B, INPUT_PULLUP);
pinMode(BTN_PIN, INPUT_PULLUP);
analogWrite(LED_PWM_PIN, 0);
Serial.begin( 115200 );
Serial.println( "START" );
}
void loop() {
long current_time = millis(); //millis() - Returns the number of milliseconds since the Arduino board began running the current program.
analogWrite(LED_PWM_PIN, led_power);
}
last_encoder_A = encoder_A;
last_encoder_B = encoder_B;
loop_time = current_time;
}
}
After assembling all parts together and uploading the software, it's time to test.
https://www.youtube.com/embed/Rj4yPcnYHvY?ecver=1&autoplay=0