Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Make sure you include IR Remote Library
- //https://github.com/z3t0/Arduino-IRremote
- #include <IRremote.h>
- //Connect IR SENSOR in PIN 2
- const int RECV_PIN = 2;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- //LED PINS
- int ledPin8 = 8;
- int ledPin9 = 9;
- int ledpin10 = 10;
- //Dictate if Led is ON or OFF
- int state[] = {0,0,0};
- void setup(){
- Serial.begin(9600);
- irrecv.enableIRIn();
- irrecv.blink13(true);
- pinMode(ledPin8, OUTPUT);
- pinMode(ledPin9, OUTPUT);
- pinMode(ledpin10, OUTPUT);
- }
- void loop(){
- if (irrecv.decode(&results)){
- long value = results.value;
- //Print IR Value in DEC, Check your serial monitor and change the numbers ... *16738455
- Serial.println(value);
- switch(value){
- case 16738455:
- //Turn all LED Lights OFF
- digitalWrite(ledPin8, LOW);
- digitalWrite(ledPin9, LOW);
- digitalWrite(ledpin10, LOW);
- break;
- case 16750695:
- //Turn all LED Lights ON
- digitalWrite(ledPin8, HIGH);
- digitalWrite(ledPin9, HIGH);
- digitalWrite(ledpin10, HIGH);
- break;
- case 16724175:
- if(state[0] == 0){ //Check if LED is OFF
- digitalWrite(ledPin8, HIGH); //Turn it ON
- state[0] = 1; //Set State to 1 or ON
- }else{
- digitalWrite(ledPin8, LOW); //Turn it OFF
- state[0] = 0; //Set State to 0 or OFF
- }
- break;
- case 16718055:
- if(state[1] == 0){
- digitalWrite(ledPin9, HIGH);
- state[1] = 1;
- }else{
- digitalWrite(ledPin9, LOW);
- state[1] = 0;
- }
- break;
- case 16743045:
- if(state[2] == 0){
- digitalWrite(ledpin10, HIGH);
- state[2] = 1;
- }else{
- digitalWrite(ledpin10, LOW);
- state[2] = 0;
- }
- break;
- }
- irrecv.resume();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement