banner



Arduino Tutorial Led Sequential Control Beginner Project

Today I am going to show you guys a very simple arduino project for beginners. We're going to get 2 different LEDs to turn on and turn off in a simple sequence, like you see in the gif below.
20180106_133016.jpg

PARTS NEEDED

20180106_103000.jpg

For this, you're going to need an Arduino Uno, a breadboard (preferably with a positive and negative rail like this one), male to male jumper wires, a USB type B cable to for the Uno, LEDs of different colors and 220ohm resistors.

20180106_124005.jpg

So lets first setup the hardware. The first step is to establish a common ground. To do this, use a jumper wire to connect the Ground pin on the arduino to the negative rail on the breadboard. This allows all the LEDs to use the ground pin on the arduino.
Now we'll insert the resistors into the breadboard. Space the resistors out with one leg connected to the the negative rail.

20180106_124053.jpg

Now its time to insert the LEDs. Before inserting the LEDs, its important to note that the longer of the two leads on most through-hole LEDs is the positive leads. Connecting it the wrong way, will cause this circuit to not work

20180106_103537.jpg

Connect the negative lead of the LED to the horizontal rail on which the resistor is connected and connect the positive lead to an adjacent rail. Repeat this process for all 2 LEDs. Now its time to complete the circuit.

20180106_124126.jpg

We are going to use output ports 13, 12 for the input signal. Connect the positive lead of the LED on the right to pin 13 and the LED on the left to pin 12. The circuit is now complete. Power on the Arduino Uno by connecting it to your computer using the USB cable. The LEDs on the board turn on and the board powers up.

SOFTWARE

Before we work on our sketch, make sure to download the Arduino IDE for your specific operating system. I'll leave a link to where you can download this software:

seq1.png

i make a sketch go ahead and copy this Sketch to run this program, using this code:

          /* A simple program to sequentially turn on and turn off 2 LEDs by pakganern */        
                      
          int LED1 = 13;        
          int LED2 = 12;        
                      
          void setup() {        
             pinMode(LED1, OUTPUT);        
             pinMode(LED2, OUTPUT);        
          }        
          void loop() {        
            digitalWrite(LED1, HIGH);    // turn on LED1        
            delay(200);                  // wait for 200ms        
            digitalWrite(LED2, HIGH);    // turn on LED2        
            delay(200);                  // wait for 200ms        
            digitalWrite(LED1, LOW);     // turn off LED1        
            delay(300);                  // wait for 300ms        
            digitalWrite(LED2, LOW);     // turn off LED2        
            delay(300);                  // wait for 300ms before running program all over again        
          }        

VERIFY/COMPILE the upload it to the board.

once done your LEDs should atart blinking in sequence like this;

20180106_125045.gif

the first code creates 2 variables. LED1, LED2. This allows us to change the output pins, without having to modify the entire program. The code in the setup part of the program tells the arduino that pins 13 and 12 will be outputs. The loop portion of the program is where the actual instructions live. The first two digitalwrite functions turn on one LED at a time with a 200ms delay between each of them turning on. The next two digitalwrite functions turn off the leds with a 300ms delay between each LED. Now you can change the delay between each LED to change the rhythm of the LEDs turning on and off.
I make another sketch that i will share on this post you can use this if you want, in this code i set 4 leds in sequence. here is the code:

          /* A simple program to sequentially turn on and turn off 2 LEDs by pakganern */        
                      
          int LED1 = 12;        
          int LED2 = 11;        
          int LED3 = 10;        
          int LED4 = 9;        
                      
          void setup() {        
             pinMode(LED1, OUTPUT);        
             pinMode(LED2, OUTPUT);        
             pinMode(LED3, OUTPUT);        
             pinMode(LED4, OUTPUT);        
          }        
          void loop() {        
            digitalWrite(LED1, HIGH);   // turn on LED1        
            delay(200);        
            digitalWrite(LED2, HIGH);    // turn on LED2        
            delay(200);        
            digitalWrite(LED3, HIGH);    // turn on LED3        
            delay(200);        
            digitalWrite(LED4, HIGH);    // turn on LED4        
            delay(200);        
            digitalWrite(LED1, LOW);     // turn on LED1        
            delay(300);        
            digitalWrite(LED2, LOW);     // turn on LED2        
            delay(300);        
            digitalWrite(LED3, LOW);     // turn on LED3        
            delay(300);        
            digitalWrite(LED4, LOW);     // turn on LED4        
            delay(300);                               // wait for 300ms before running program all over again        
          ; }        

here the LEDs blinking in Sequence using the last code with 4 leds that i make. You can change the delaytime in the sketchcode:


Hope this tutorial was useful. Please hit upvote for more Arduino tutorials and follow me @pakganern
20180105_182452[1].jpg


Posted on Utopian.io - Rewarding Open Source Contributors


Arduino Tutorial Led Sequential Control Beginner Project

Source: https://steemit.com/utopian-io/@pakganern/led-sequential-control-arduino

0 Response to "Arduino Tutorial Led Sequential Control Beginner Project"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel