This post is about DIY light effect with Arduino
This is the DIY project we are gonna make
COMPONENTS
- Arduino and Parts for Arduino
- 9 light bulbs with low power consumption(i used low power LED)
- some wires
the circuit will be much easy if we use a diode,
I will upload another post on that.
- Connect the pins as shown in the circuit diagram
- use an external power supply for Arduino (since the USB is not enough for 9 bulbs)
//this is the Arduino code
//the code is simple and it is easy to understand
void setup()// the setup function runs once when you press reset or power the board
{
// initialize digital pins as an output.
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void one()//since the code is huge seperate functions are used which is later called in loop function
{
digitalWrite(4,HIGH);
delay(90);
digitalWrite(5,HIGH);
digitalWrite(3,HIGH);
delay(90);
digitalWrite(10,HIGH);
digitalWrite(6,HIGH);
digitalWrite(2,HIGH);
delay(90);
digitalWrite(9,HIGH);
digitalWrite(7,HIGH);
delay(90);
digitalWrite(8,HIGH);
delay(150);
digitalWrite(4,LOW);
delay(90);
digitalWrite(5,LOW);
digitalWrite(3,LOW);
delay(90);
digitalWrite(10,LOW);
digitalWrite(6,LOW);
digitalWrite(2,LOW);
delay(90);
digitalWrite(9,LOW);
digitalWrite(7,LOW);
delay(90);
digitalWrite(8,LOW);
delay(150);
}
void six()//since the code is huge seperate functions are used which is later called in loop function
{
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(2, HIGH);
delay(90);
digitalWrite(9, HIGH);
digitalWrite(6, HIGH);
digitalWrite(3, HIGH);
delay(90);
digitalWrite(10, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
delay(90);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(2, LOW);
delay(90);
digitalWrite(9, LOW);
digitalWrite(6, LOW);
digitalWrite(3, LOW);
delay(90);
digitalWrite(10, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(150);
}
void two()
{
digitalWrite(10, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
delay(90);
digitalWrite(9, HIGH);
digitalWrite(6, HIGH);
digitalWrite(3, HIGH);
delay(90);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(2, HIGH);
delay(90);
digitalWrite(10, LOW);
digitalWrite(5, LOW);
digitalWrite(4, LOW);
delay(90);
digitalWrite(9, LOW);
digitalWrite(6, LOW);
digitalWrite(3, LOW);
delay(90);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(2, LOW);
delay(150);
}
void three()//since the code is huge seperate functions are used which is later called in loop function
{
digitalWrite(10,HIGH);
delay(90);
digitalWrite(5,HIGH);
digitalWrite(9,HIGH);
delay(90);
digitalWrite(4,HIGH);
digitalWrite(6,HIGH);
digitalWrite(8,HIGH);
delay(90);
digitalWrite(3,HIGH);
digitalWrite(7,HIGH);
delay(90);
digitalWrite(2,HIGH);
delay(150);
digitalWrite(10,LOW);
delay(90);
digitalWrite(5,LOW);
digitalWrite(9,LOW);
delay(90);
digitalWrite(4,LOW);
digitalWrite(6,LOW);
digitalWrite(8,LOW);
delay(90);
digitalWrite(3,LOW);
digitalWrite(7,LOW);
delay(90);
digitalWrite(2,LOW);
delay(150);
}
void four()//since the code is huge seperate functions are used which is later called in loop function
{
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
delay(90);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
delay(90);
digitalWrite(4, HIGH);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
delay(90);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
digitalWrite(8, LOW);
delay(90);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(90);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
delay(150);
}
void five()//since the code is huge seperate functions are used which is later called in loop function
{
digitalWrite(8,HIGH);
delay(90);
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
delay(90);
digitalWrite(10,HIGH);
digitalWrite(6,HIGH);
digitalWrite(2,HIGH);
delay(90);
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
delay(90);
digitalWrite(4,HIGH);
delay(150);
digitalWrite(8,LOW);
delay(90);
digitalWrite(7,LOW);
digitalWrite(9,LOW);
delay(90);
digitalWrite(10,LOW);
digitalWrite(6,LOW);
digitalWrite(2,LOW);
delay(90);
digitalWrite(3,LOW);
digitalWrite(5,LOW);
delay(90);
digitalWrite(4,LOW);
delay(150);
}
void seven()//since the code is huge seperate functions are used which is later called in loop function
{
digitalWrite(2,HIGH);
delay(90);
digitalWrite(7,HIGH);
digitalWrite(3,HIGH);
delay(90);
digitalWrite(8,HIGH);
digitalWrite(6,HIGH);
digitalWrite(4,HIGH);
delay(90);
digitalWrite(9,HIGH);
digitalWrite(5,HIGH);
delay(90);
digitalWrite(10,HIGH);
delay(150);
digitalWrite(2,LOW);
delay(90);
digitalWrite(7,LOW);
digitalWrite(3,LOW);
delay(90);
digitalWrite(4,LOW);
digitalWrite(6,LOW);
digitalWrite(8,LOW);
delay(90);
digitalWrite(9,LOW);
digitalWrite(5,LOW);
delay(90);
digitalWrite(10,LOW);
delay(150);
}
void eight()//since the code is huge seperate functions are used which is later called in loop function
{
digitalWrite(4,HIGH);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
delay(90);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
delay(90);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
delay(90);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
delay(90);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(90);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(150);
}
void loop()// the loop function runs over and over again forever
{
one();//functions are called here
two();
three();
four();
five();
six();
seven();
eight();
}
//enjoy the light effects
//i will upload several other Arduino codes i have written for light effects.
No comments:
Post a Comment