Introduction: Project 5: Led Series Blink

In this instructable we are going to arrange 10 led's in a series or range together and make them blink one by one. We will also learn some new programming functions in this instructable. The requirements are as same as in my first instructable. By the progamming function we are going to learn it will be easier to make big projects in the further and will be essential because the data that can be entered in the Arduino Software or IDE has a certain limit and cannot be exceeded.

Step 1: What You Require?

  • Arduino Uno or Arduino Mega 2560 (They are the beginning boards of Arduino)
  • Jumper Wires (Male to Male)
  • 10 Led's {Preferable if all the led's are of the same color}
  • Breadboard
  • 10 K (more preferable) or 1k resistors [Qty. 10]
  • Cable (To connect board with your Computer for uploading the Program)
  • Arduino Program (Downloadable from https://www.arduino.cc/en/Main/Software)

Step 2: Build Your Circuit and Know Why Is It Designed So?

The above diagram shows blue lines which represents the Jumper Wires. Jumper Wires are connective units. They transfer power and do a lot of jobs. In this program they are only transferring power. An Led requires 2 types of power to light it up. Positive and Negative. Positive Energy is supplied by Digital Pins which is distinct than the other Pin giving Positive Energy by its name. It's vice versa for identifying the source of power and where is it transferred. An led when directly supplied by positive energy fuses up that's why we use a resistor. Before me move forward let's discuss about the positive negative rods of the led. The longer is positive and the shorter is negative. The resistor is connected with the positive rod which goes in the same row. In the same column but different row of the other end of the resistor comes the jumper wire connecting it with the digital pin.

Negative energy is noted as GND and is directly supplied to the shorter rod of the Led using a Jumper Wire. That completes the circuit diagram and why is it placed or designed in this way.

Step 3: Now for the Software and Understanding It

  • int delayTime = 100;
  • int currentLED = 2;
  • int dir = 1;
  • long timeChanged = 0;
  • byte ledPin[] = {2,3,4,5,6,7,8,9,10,11,};
  • void setup()
  • { for (int i=0; i<10; i++)
  • { pinMode(ledPin[i], OUTPUT); }
  • timeChanged = millis();}
  • void loop()
  • { if ((millis() - timeChanged) > delayTime)
  • { for (int i=0; i<10; i++)
  • { digitalWrite(ledPin[i], LOW); }
  • digitalWrite(ledPin[currentLED], HIGH);
  • currentLED = currentLED + dir;
  • if (currentLED == 9) { dir = -1; }
  • if (currentLED == 0) { dir = 1; }
  • timeChanged = millis(); } }

First we define a integer, delayTime as 100. We have not defined what is 100 but we will later in the loop section. Then we define another integer as CurrentLED as 4. Just as before we have still not defined what is 4. We will define it later. Then we define another integer dir which stands for direction. The integer is defined as 1. We will define 1 again later. Then we take a long function which means an integer with a large value both minus and positive. The long is named as timeChanged, you will not know the value of the long integer because it can go even more than billion. We will see abut it later. Then we define byte which is nothing but an array. The name is ledPin for the array and the numbers that are defined are known by their index number 0,1,2,3,4,5.... till 9. In an array we associate the numbers provided by the user from 0. So we can say that the index number for 4 is 0, 5 is 1 etc. Then we go forward to the void setup area. Here we use the function for. In the function we make spaces in the integer "i" for 10 numbers. First we make it as zero. Then we say that it is less than 10. Then we increment it. 10 actually means 11 numbers here because it also counts zero as a number. Then we use the pinMode function to describe the led pins as output. So the numbers that have been stored in the array are now being used as pin for the led's. Then we show here that timeChanged is equal to millis() a programming function.

Then time for the loop section. We say here through the function if that if millis() deducted by timeChanged is greater than delayTime [Which is equal to 100] then close all the led's. Then on the currentLed [It's a integer that we put before the setup part] which's pin is 4. Then with the help of the principle of integer which means that we can change the value of the integer we change the value of currentLED by adding it by dir which's equal to 1. So then it will go on to led pin 5,6, and so on. As we know that there is no led after index 9 [equal to pin 13] so then we say that if the currentLED becomes 9 then we change the dir value to -1 so that it will go to index 8,7 and so on. Then if the pin index is 0 then dir's value again becomes 1 so that it goes 1,2,3 and so on.

Step 4: Be Creative !!!

Now that you have done this you can change the pattern of the led blink. You can make the last on either side blink then the second last on either side then third last on either side and so on and vice versa. You can make hundred's of patterns with just some tweaking in the programming.

Rule No. 1 = Be Creative -- If you have any doubt you can ask through the comments. Dont forget to share and follow if you liked the instructable.

Comments

author
Quibus (author)2017-04-04

I tried it and it works. Only thing I wonder is if there is any reason not to use just 1 resistor over the negative side. I tried that in circuits.io and it seems to work.

author

Thanks for trying out the project, but I didn't understand this phrase "wonder is if there is any reason not to use just 1 resistor over the negative side."

Please explain a little better, because I didn't get what you wanted to say. If you might explain then I can add up your suggestion in this instructable by editing.

Any Way Thanks a lot.

author

Sorry, I did place a reply but there must have gone something wrong because it does not show up on here.

I meant exactly what janezdem (thanks for that) wrote.

B.t.w. thank you for sharing this.

Schermafbeelding 2017-04-14 om 17.35.42.png
author
EvanDallas (author)Quibus2017-07-05

If I want more space from the breadboard to the arduino, can I move the resister farther back and just connect a wire between it and the GND on the arduino?

author

I suppose (s)he meant removing the individual resistors and putting a single resistor between the common ground of the LEDs and the GND from the Arduino. The answer (@Quibus): you can and it's going to work OK for as long as only a single LED will be on. Otherwise I suppose the LEDs will be way dimmer since they'll share the current. Try it if you want to be sure!

There's a better trick: you can use a resistor network with, say, eight resistors in a single 9-pin element instead of having eight resistors.

author

Thanks for the suggestion I will use it in upcoming instructables. Thanks A Lot again.

author
sagarrgcer (author)2017-03-30

Very nice

author

Thanks a lot!!! If you have liked the instructable please do not forget to follow me and share the project.

Regards - ArduinoElectronics

About This Instructable

1,417views

18favorites

License:

Bio: I like Arduino. I learn new things about it every day and also upload it here on Instructables.
More by ArduinoElectronics:Project 6 : Led Fading With PWMProject 5: Led Series BlinkProject 3 : Push Button and LED
Add instructable to: