Christmas lighting using Arduino Mega

Christmas is fun and like others I love to decorate my home with attractive lighting. So for that purpose I have built this simple project using Arduino Mega and I would like to share it with you all. This is a simple project pretty well suited for beginners or those who have zero experience in Arduino or with Electronics before. 

MATERIALS REQUIRED: 

  1. Arduino Mega
  2. 17 LED’s ( Red, Green, Blue, White, Orange )
  3. Connecting wires
  4. Resistors

SCHEMATIC DIAGRAM OF CHRISTMAS LIGHTING PROJECT USING ARDUINO:

Arduino Mega being the brain behind this project controls the 17 LED’s connected to this project. Resistors of value 100 to 220 ohms should be added with each LED’s to limit the current flow through it. Use variations in the LED arrangement to make the lighting effect more attractive. Use a voltage source that can supply current  of at least 500mA to your circuit.

CODE: 

//Animation de 17 LEDS...
void setup() {
  for(int x = 22; x < 39; x++) {
    pinMode(x, OUTPUT);
  }
}

void loop() {
  Anim1();  Anim2();  Anim3();  Anim4();  Anim5();  Anim6();  Anim7();   Anim8();  
  Anim9();  Anim10(); Anim11(); Anim12(); Anim13(); Anim14(); Anim15(); Anim16(); Anim17(); 
}
void Anim1() {
  for(int x = 22; x < 39; x++) {
   digitalWrite(x, HIGH); delay(90);
   digitalWrite(x, LOW); delay(90);
  }
}
void Anim2() {
  for(int x = 38; x > 21; x--) {
   digitalWrite(x, HIGH); delay(90);
   digitalWrite(x, LOW); delay(90);
  }
}
void Anim3() {
  for(int x = 22; x < 39; x++) {
   digitalWrite(x, HIGH); delay(90);
  }
  for(int x = 38; x > 21; x--) {
   digitalWrite(x, LOW); delay(90);
  }
}
void Anim4() {
  for(int i = 0; i < 3; i++) {
    for(int x = 38; x > 21; x--) {
     digitalWrite(x, HIGH); delay(35);
    }
    for(int x = 22; x < 39; x++) {
     digitalWrite(x, LOW); delay(35);
    }
  }
}
void Anim5() {
  for(int x = 38; x > 21; x--) {
   digitalWrite(x, HIGH); delay(75);
  }
  for(int x = 22; x < 39; x++) {
   digitalWrite(x, LOW); delay(50);
  }
}
void Anim6() {
  for(int i = 0; i < 3; i++) {
    for(int x = 22; x < 39; x++) {
     digitalWrite(x, HIGH); delay(30);
    }
    for(int x = 38; x > 21; x--) {
     digitalWrite(x, LOW); delay(30);
    }
  } 
}
void Anim7() {
  for(int x = 22; x < 39; x+=2) {
   digitalWrite(x, HIGH); delay(90); 
   digitalWrite(x, LOW);
  }
}
void Anim8() {
  for(int x = 37; x > 22; x-=2) {
   digitalWrite(x, HIGH); delay(90);
   digitalWrite(x, LOW);
  }
}
void Anim9() {
  for(int i = 0; i < 17; i++) {
   int a, b, c, d, e, f, g;
   a = random(22, 39); b = random(22, 39); c = random(22, 39); d = random(22, 39);
   e = random(22, 39); f = random(22, 39); g = random(22, 39);
   digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH);
   digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH);
   delay(90); 
   digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, LOW);
   digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW);
   delay(90);
  }
}
void Anim10() {
  for(int i = 0; i < 7; i++) {
    for(int x = 22; x < 39; x++) {
     digitalWrite(x, HIGH);
    }delay(150);
     
    for(int x = 22; x < 39; x++) {
     digitalWrite(x, LOW);
    }delay(150); 
  }
}
void Anim11() {
  for(int i = 0; i < 3; i++) {
    for(int x = 22; x < 31; x++) {
     digitalWrite(x, HIGH); delay(50);
    }
    for(int x = 22; x < 31; x++) {
     digitalWrite(x, LOW); delay(50);
    }
    for(int x = 38; x > 29; x--) {
    digitalWrite(x, HIGH); delay(50); 
    }
    for(int x = 38; x > 29; x--) { 
     digitalWrite(x, LOW); delay(50);
    }
  }
}
void Anim12() {
  for(int i = 0; i < 3; i++) {
    for(int i = 0; i < 3; i++) {
      for(int x = 22; x < 31; x++) {
       digitalWrite(x, HIGH);
      }delay(150);
      for(int x = 22; x < 31; x++) {
       digitalWrite(x, LOW);
      }delay(150); 
    }
  for(int i = 0; i < 3; i++) {
    for(int x = 30; x < 39; x++) {
     digitalWrite(x, HIGH);
    }delay(150);
    for(int x = 30; x < 39; x++) {
     digitalWrite(x, LOW);
    }delay(150); 
  }  
  }
}
void Anim13() {
  for(int i = 0; i < 17; i++) {
    for(int x = 37; x > 22; x-=2) { 
     digitalWrite(x, HIGH); delay(50);
    } 
    for(int x = 22; x < 39; x+=2) {
     digitalWrite(x, HIGH); delay(50);
    }
    for(int x = 37; x > 22; x-=2) { 
     digitalWrite(x, LOW); delay(50);
    }
    for(int x = 22; x < 39; x+=2) {
     digitalWrite(x, LOW); delay(50);
    }
  }
}
void Anim14() {
  for(int i = 0; i < 17; i++) {
    for(int x = 37; x > 22; x-=2) { 
     digitalWrite(x, HIGH); 
    }delay(90);
    for(int x = 22; x < 39; x+=2) {
     digitalWrite(x, HIGH); 
    }delay(90);
    for(int x = 37; x > 22; x-=2) { 
     digitalWrite(x, LOW); 
    }delay(90);
    for(int x = 22; x < 39; x+=2) {
     digitalWrite(x, LOW); 
    }delay(90);
 }
}
void Anim15() {
  for(int i = 0; i < 17; i++) {
    for(int x = 22, y = 39; x < 39, y > 22; x+=2, y-=2) {
     digitalWrite(x, HIGH); delay(30); 
     digitalWrite(y, HIGH); delay(30);
    }
    for(int x = 22, y = 39; x < 39, y > 22; x+=2, y-=2) {
      digitalWrite(x, LOW); delay(30); 
      digitalWrite(y, LOW); delay(30);
    }
  }
}
void Anim16() {
  for(int i = 0; i < 10; i++) {
    for(int x = 22; x < 39; x++) {
     digitalWrite(x, HIGH); delay(20);
    }
    for(int x = 22; x < 39; x++) {
     digitalWrite(x, LOW); delay(20);
    }
    for(int x = 38; x > 21; x--) {
     digitalWrite(x, HIGH); delay(20);
    }
    for(int x = 38; x > 21; x--) {
     digitalWrite(x, LOW); delay(20);
    }
  }
}
void Anim17() {
  for(int i = 0; i < 17; i++) {
    for(int x = 22; x < 39; x+=2) {
     digitalWrite(x, HIGH);  
    }delay(90);
    for(int x = 22; x < 39; x+=2) {
     digitalWrite(x, LOW);  
    }delay(90);
    for(int x = 37; x > 22; x-=2) {
     digitalWrite(x, HIGH);
    }delay(90);
    for(int x = 37; x > 22; x-=2) {
     digitalWrite(x, LOW);
    }delay(90);
  }
}

In the above code there were totally 17 animation sequence which each one being slightly different from each other. These 17 animation effects continue to repeat itself once the power is ON and produces a beautiful lighting effect.

TIPS AND IMPROVEMENTS: 

  • You can set up the LED’s over Christmas tree or over the walls but make sure to insulate and wire the LED’s properly to the Arduino board.
  • Use transistors as a switch with the pins of Arduino if you intend to add more LED’s. This way allows you to power up more LED’s and expand this project on the whole.
  • Feel free to play around with the code and try out your hand in creating your own set of animations for this lighting project.
  • You can also explore the possibility of using RGB LED’s in this project. By doing so you will be able to produce any color of your desire which will be damn cool.
  • You can also use other variants of Arduino boards like Uno, Nano etc.

Leave a Comment

Your email address will not be published. Required fields are marked *