Arduino Dancing LEDs !!

Hey there!! Here is a beginner Arduino project to get started in, so with farther a dew here it is.

20161231_111913.jpg

Here’s the material you’ll need

Materials

  • Arduino UNO or any micro processing board of your choosing.
  • Usb cord.
  • 5 jumper wire.
  • 4 LED’s of different colors(if you would like).
  • 4 220 ohm resisters.
  • A breadboard.

Get to know Circuits

Before we jump in to the meat and potatoes of the project. Lets go over the basics or “101” of a circuit, since we are going to be working with circuits(it would only make since).A Circuit is a route, or movement that starts and finishes at the same place.All circuits need three necessary factors for it to be able to work a power supply, something to allow the power to pass through and, something to stop the power from moving. Frist off a circuit needs something called a voltage (remember that our power supply) and every power supply has a number of voltage that it supplies. For example a AAA battery has 1.5 volts.This is where circuit gets its power from. Along with voltage you will need something conductive for those volts to go through. Conductive or a Conductor is material where electricity can freely flow through.Just to name a few conductive materials are copper, metals or, some nonmetallic materials.Lastly, to have a complete working circuit there needs to be some where for it to stop the flow of energy, thats where ground comes in. To me why circuits have a ground is to main prevent people coming in contact with the dangerous voltages flowing through a circuit.To show you how it all work let me get you a visual below.

Web

Power comes out the (+) end and enters into the (+) end of the LED which creates light then exits out of the (-) which flows to the (-) of the battery.

Well now I gave you a small portion on circuits, now we can get started on making this awesome project. I’m no electrical engineer for theres a lot more to learn about this subject of matter, but its still good to have a general understanding on what you’re coding. For more information on all things electrical engineering check out SparkFun

  The Assembly

Establishing a Ground

20161231_111810
Take a jumper cable wire and connected it to the  ground rail on the breadboard (it  should be the one closes to you if there are no marking indicating a ground).
20161231_111801
Now take the other end of the of the same wire and connected to the ground on the broad.(It should say “GND”.

Placing our resistors

20161231_111744.jpg
Now pick up your 220 ohm resistors, take one end and connect it to the same rail we connected to ground.Then take the other end and connected somewhere on the breadboard, do the same for the rest like so.

Adding the LED’s in the mix

   Before we start!!

20161231_111727.jpg
If you look above you will see a light-emitting diode (LED). So we can get on the same page when I talk about (+) led and (-) led. The (+) is the longer end and the (-) end is the shorter end.

Connecting the LED’s

20161231_111710.jpg
Now take the negative leg of the LED and place it on the horizontal rail that your resistor is placed on. Then take the positive leg and place it to a different rail.

Connecting LED’s to Pins

20161231_111549.jpg
Lastly take rest of the wires you have left and connect them to (+) leg on the LED’s then on the Arduino take the other end of the wire to pins (13, 12, 11 and,10). Great now all there’s left is to connect your Arduino to your computer.

Now it time to code!!!

Alright now  that’s over lets get to the exciting part coding!!! Open up your Arduino  IDE and lets dig in.

screen-shot-2017-01-03-at-6-01-58-pm

When you open up your IDE you should have something like what is above. If not copy this onto your workspace.

void setup() {
 // put your setup code here, to run once:

}

void loop() {
 // put your main code here, to run repeatedly:

}

Creating our variables

First we have to tell our program what numbers we are using and that the values that we are storing into theses variables are integers enhance the “int” before we name your variable.

variable type|name|value
int light1 = 10;
int light2 = 11;
int light3 = 12;
int light4 = 13;

Working in our “setup()” Structure 

Now that we told our program that the values we stored in our variables are integers and named them. We have to tell our program that the values stored are actually  pins on our Arduino, because to the program they are just numbers.How we go about this is we have to use something called “pinMode();”. This function tells your program what pin to use and the behavior of the component the pin is connected too, there are three modes it could have INPUT, OUTPUT and, INPUT_PULLUP. Since all these pins are connected to LED’s (which by the way OUTPUTS light) we are going to use the mode OUTPUT.

void setup() {
 pinMode(light1, OUTPUT);
 pinMode(light2, OUTPUT);
 pinMode(light3, OUTPUT);
 pinMode(light4, OUTPUT);
}

Working in the “loop()” structure

           Last but not least the fun part, so if we think about this we want our four LED lights to turn on one-by-one then turn off one-by-one. So to enable to do that we first have to learn how to turn our LED’s on and off. The way to do that is using the function “digitalWrite();”, with this function we can tell the program what pin we would like to use and what digital value we would like to take place HIGH or LOW. So if we want to turn the LED’s on one-by-one then turn them off one-by-one we would need to code that in sequence like so.

void loop() {
 digitalWrite(light1, HIGH);

 digitalWrite(light2, HIGH);
 
 digitalWrite(light3, HIGH);
 
 digitalWrite(light4, HIGH);
 
 
 
 digitalWrite(light1, LOW);
 
 digitalWrite(light2, LOW);
 
 digitalWrite(light3, LOW);
 
 digitalWrite(light4, LOW);


}

               But hold on if you would run the program now there really wouldn’t be any sequences to lights. We need something to time our lights. This is where “delay();” comes in handy, what we can use delay for is to tell the program how long we want this light to stay on in milliseconds ,yep, milliseconds. But no fear I do know this 1000 milliseconds equals a second. So since we want each light to turn on one-by-one we are going to delay the first LED the longest then decrease by 100 each time. Then because of the timing of the HIGH everything works out for the LOW which will all be set at 300 milliseconds.

     void loop() {
 digitalWrite(light1, HIGH);
 delay(500);
 
 digitalWrite(light2, HIGH);
 delay(400);
 
 digitalWrite(light3, HIGH);
 delay(300);
 
 digitalWrite(light4, HIGH);
 delay(200);
 
 
 digitalWrite(light1, LOW);
 delay(300);
 digitalWrite(light2, LOW);
 delay(300);
 digitalWrite(light3, LOW);
 delay(300);
 digitalWrite(light4, LOW);
 delay(300);

}

   Great!! if this was your first time messing around with the world of Arduino. Congrats now you can change up the sequence of the lights and put your own flavor to it.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s