Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
ayanfeoluwaadekanye1
Published © GPL3+

Controlling LED brightness with IR

Increase and decrease the brightness of 2 leds using an IR remote and sensor

BeginnerFull instructions provided3,849
Controlling LED brightness with IR

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LED (generic)
LED (generic)
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Infrared Receiver, 38 kHz
Infrared Receiver, 38 kHz
×1
Adafruit Mini Remote control
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

The Circuit

Code

The Code

Arduino
#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int ledPin = 10;
int brightness=0;
unsigned long key_value = 0;


void setup(){
  irrecv.enableIRIn();
  irrecv.blink13(true);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  
  if (irrecv.decode(&results)){
    
    if (results.value == 0XFFFFFFFF)
         results.value = key_value;

    if(results.value==0xF076C13B){
      brightness-=5;
     
      if (brightness<0){brightness=0;}
      
    }
    else if(results.value==0xA3C8EDDB){
      brightness+=5;
   
      if (brightness>255){brightness=255;}
     }
    
     key_value = results.value;
     irrecv.resume();
  }
brightnessControl(brightness);
}

void brightnessControl(int value){
  analogWrite(ledPin,value);
  }

Credits

ayanfeoluwaadekanye1
0 projects • 8 followers
Contact

Comments

Please log in or sign up to comment.