Another day, another sketch 🙂 This time I’ve made a sketch to dim a led with my IR remote control. I first tried to use the remote control to directly set the value of the analogue write variable. That way every time I pushed the remote control the value would go up or down. I was getting tired of pushing on the remote control.
So I used a switch case to set 5 steps to control the led. One button of the remote control dims the led up another button dims it down. This way it works much faster then setting the analogue write value between 0 and 255 in steps of 1.
Here is the sketch:
// http://www.bajdi.com // Dimming LED in 5 steps with IR remote control #include <IRremote.h> // use the library for IR const int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11 const int led = 9; int fadeValue; int lastCounter = 1; int counter; IRrecv irrecv(receiver); // create instance of 'irrecv' decode_results results; void setup() { pinMode(led, OUTPUT); irrecv.enableIRIn(); } void loop() { counter = lastCounter; if (irrecv.decode(&results)) { if (results.value == 0xFF30CF){ counter ++; } if (results.value == 0xFF10EF){ counter --; } irrecv.resume(); } if (counter > 5){ //maximum for counter = 5 counter = 5; } if (counter < 2){ //minimum for counter = 1 counter = 1; } switch (counter){ //depending on the counter the fadevalue is sent to the led case 1: fadeValue = 00; break; case 2: fadeValue = 50; break; case 3: fadeValue = 120; break; case 4: fadeValue = 185; break; case 5: fadeValue = 255; break; } analogWrite(led, fadeValue); //set led with PWM value lastCounter = counter; //reset counter }
Hi,
I have dimmable wall lamp am doing my diming via a pot meter conect to the buck IC, but I would like to do remote diming just like you have discribe. Can you please send me a schematic,part list and code on how I can install that to my current wall lamp for dimming. Thanks for your support
Have you figured out how you are going to replace the potentiometer with a signal from a micro controller? This is not so easy. If I were you I would try and solve that first. After that adding remote control is very easy.
Hello,
I’m wondering if you could help me with using the remote to blink an LED. I’d like to use one button to get the LED to blink and the same button to make it stop. Thanks for the help.
Just modify the above sketch. Also take a look at the “blink without delay” example in the Arduino IDE.
Where is the schematic diagram.
Hi please guide me how to add codes for dimming 3 LEDs