CONTROL BRIGHTNESS LED VIA IR REMOTE

LED brigness IR

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/LED%20REMOTE.zip

#include <IRremote.h>
int RECV_PIN = 3;
//int OUTPUT_PIN = 4;
IRrecv irrecv(RECV_PIN);
decode_results results;
int pinLED = 5; //don’t use pin D11
int brighness = 0;
void setup()
{
Serial.begin(9600);
//pinMode(OUTPUT_PIN, OUTPUT);
pinMode(13, OUTPUT);
pinMode(pinLED, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}

int on = 0;
unsigned long last = millis();
void loop() {
brighness = constrain(brighness, 0, 255);
analogWrite(pinLED, brighness);
Serial.println(brighness);
delay(20);
if (irrecv.decode(&results)) {
if (results.value == 0xEF1020DF) { //enter you remote code
brighness++;
}
else if (results.value == 0xEF10A05F) { //enter you remote code
brighness–;
}
irrecv.resume(); // Receive the next value
}
}

OR WE CAN SAVE SETTING IN EEPROM

#include <IRremote.h>
#include <EEPROM.h>
int RECV_PIN = 3;
IRrecv irrecv(RECV_PIN);
decode_results results;
int pinLED = 5; //don’t use pin D11
int brighness = 0;
void setup()
{
Serial.begin(9600);
pinMode(pinLED, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
}

int on = 0;
unsigned long last = millis();
void loop() {
brighness = constrain(brighness, 0, 255);
if (irrecv.decode(&results)) {
if (results.value == 0xEF1020DF) {
brighness++;
EEPROM.write(1, brighness);
}
else if (results.value == 0xEF10A05F) {
brighness–;
EEPROM.write(1, brighness);
}
irrecv.resume(); // Receive the next value
}
brighness = EEPROM.read(1);
analogWrite(pinLED, brighness);
Serial.println(brighness);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s