lucas_fernando_maker
Published © GPL3+

Use remote control to turn on and off Christmas lights

I will show you how to set up an infrared transmiter and reciever on Arduino UNO and use it to control the way your Christmas lights blink.

BeginnerFull instructions provided943
Use remote control to turn on and off Christmas lights

Things used in this project

Hardware components

5 mm LED: Red
5 mm LED: Red
×6
5 mm LED: Yellow
5 mm LED: Yellow
×6
5 mm LED: Green
5 mm LED: Green
×6
Jumper wires (generic)
Jumper wires (generic)
×1
Infrared receptor
×1
Infrared remote control
×1
Breadboard (generic)
Breadboard (generic)
×1
Arduino UNO
Arduino UNO
×1

Hand tools and fabrication machines

Scissor, Electrician
Scissor, Electrician
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Tape, Electrical
Tape, Electrical

Story

Read more

Schematics

Schematics of Natal tree with remote control

I highly recommend you to use a receiver module because its built-in components make the project easier.

Code

Code

C/C++
Don't forget to install IRremote library.
#include <IRremote.hpp>

int IRreceptor = 4;
int blueLeds = 5;
int yellowLeds = 6;
int redLeds = 7;

int counter = 1;
int delayTime = 300;
int delayShortTime = 50; 
void setup() {
  Serial.begin(9600);
  IrReceiver.begin(IRreceptor);
  pinMode(redLeds, OUTPUT);
  pinMode(blueLeds, OUTPUT);
  pinMode(yellowLeds, OUTPUT);
  pinMode(IRreceptor, INPUT);
}

void loop() {  
  turnOffLeds();
  if (counter == 1) {
    turnOffLeds();
    while (counter == 1) {
      IrReader();
      digitalWrite(redLeds, HIGH);
      delay(delayTime);
      digitalWrite(redLeds, LOW);
      digitalWrite(blueLeds, HIGH);
      delay(delayTime);
      digitalWrite(blueLeds, LOW);
      digitalWrite(yellowLeds, HIGH);
      delay(delayTime);
      digitalWrite(yellowLeds, LOW);  
    }
  } else if (counter == 2) {
    turnOffLeds();
    while (counter == 2) {
      IrReader();
      for (int i = 0; i < 4; i++) {
        digitalWrite(redLeds, HIGH);
        delay(delayShortTime);
        digitalWrite(redLeds, LOW);
        delay(delayShortTime);  
      }

      IrReader();
      for (int i = 0; i < 4; i++) {
        digitalWrite(blueLeds, HIGH);
        delay(delayShortTime);
        digitalWrite(blueLeds, LOW);
        delay(delayShortTime);  
      }

      IrReader();
      for (int i = 0; i < 4; i++) {
        digitalWrite(yellowLeds, HIGH);
        delay(delayShortTime);
        digitalWrite(yellowLeds, LOW);
        delay(delayShortTime);  
      }
    }
  } else if (counter == 3) {
    turnOffLeds();
    while (counter == 3) {
      digitalWrite(redLeds, HIGH);
      digitalWrite(blueLeds, HIGH);
      digitalWrite(yellowLeds, HIGH);
      IrReader();  
    }  
  } else if (counter == 4) {
    turnOffLeds();
    while (counter == 4) {
      IrReader();
      for (int i = 0; i < 3; i++) {
        digitalWrite(redLeds, HIGH);
        digitalWrite(blueLeds, HIGH);
        delay(delayTime);
        digitalWrite(redLeds, LOW);
        digitalWrite(blueLeds, LOW);
        digitalWrite(yellowLeds, HIGH);
        delay(delayTime);
        digitalWrite(yellowLeds, LOW);
        IrReader();
      }

      IrReader();
      for (int i = 0; i < 9; i++) {
        digitalWrite(redLeds, HIGH);
        delay(delayShortTime);
        digitalWrite(redLeds, LOW);
        digitalWrite(blueLeds, HIGH);
        delay(delayShortTime);
        digitalWrite(blueLeds, LOW);
        digitalWrite(yellowLeds, HIGH);
        delay(delayShortTime);
        digitalWrite(yellowLeds, LOW);
        delay(delayShortTime);
        IrReader();
      }
    }  
  }
}

void turnOffLeds() {
  digitalWrite(redLeds, LOW);
  digitalWrite(blueLeds, LOW);
  digitalWrite(yellowLeds, LOW);  
}

void IrReader() {
  if (IrReceiver.decode()) {
    Serial.print("Button: ");
    Serial.println(IrReceiver.decodedIRData.command);
    if (IrReceiver.decodedIRData.command == 22) {
      counter = 1;  
    } else if (IrReceiver.decodedIRData.command == 25) {
      counter = 2;
    } else if (IrReceiver.decodedIRData.command == 13) {
      counter = 3;     
    } else if (IrReceiver.decodedIRData.command == 12) {
      counter = 4;  
    }
  }
  IrReceiver.resume();
}

Credits

lucas_fernando_maker
3 projects • 3 followers

Comments