Controlling Multiple LEDs With Arduino Uno

745

In previous tutorials, we have done with blinking one led with Arduino. Now its time to do little more – controlling multiple LEDs with Arduino.

An Arduino has enough pins to control multiple LEDs at once. In this tutorial, we will use 5 LEDs at once and control their blinking time simultaneously.

We execute two different codes on Arduino Uno and check their output.

LED is a semiconductor that emits light when passing through an electric current. Also called a light-emitting diode.

led2

Here some more tutorials for you:

Components List

  • Arduino Uno
  • LED’s
  • Resistors (300Ω – 1 KΩ)
  • Breadboard
  • Jumper Wires

Connection with Arduino

Connect the following Arduino with LEDs respectively.

LEDs LegArduino Pins
All LED CathodesGND
RED AnodeD7
BLUE AnodeD6
ORANGE AnodeD5
GREEN AnodeD4
YELLOW AnodeD3

Always connect a resistor of 1KΩ with an LED. The bigger one wire of led is +ve and the other is -ve.


Circuit Diagram for Multiple LEDs with Arduino

Circuit diagram For controlling multiple leds with arduino

Understand the circuit diagram given above, connecting the LEDs from the resistor and then the Arduino pins. Before connecting LEDs using breadboard you have the knowledge of how a breadboard works. Follow the above circuit diagram to controlling multiple LEDs with Arduino.


Code 1

Connect your Arduino with the computer and select the board name and port number. Now upload the below code.

The above sketch work in the following ways:

  1. Pin 7 becomes HIGH which turns on LED1.
  2. Wait 200ms.
  3. Pin 7 becomes LOW which turns off LED1.
  4. Wait 200ms.
  5. Pin 6 becomes HIGH which turns on LED2.
  6. Wait 200ms.
  7. Pin 6 becomes LOW which turns off LED2.
  8. Wait 200ms
  9. Now same as pin 5, 4, 3 works.

Output 1

Output of Controlling Multiple LEDs With an Arduino

Code 2

Now upload the below code to the Arduino. The below code has a different algorithm.

The above code work in the following way:

  1. Pin 7, 6, 5, 4 and 3 become HIGH which turns on all LEDs.
  2. Wait 200ms.
  3. Pin 7 becomes LOW which turns off LED1.
  4. Wait 200ms.
  5. Pin 6 becomes LOW which turns off LED2.
  6. Pin 7 becomes HIGH which turns on LED1.
  7. Wait 200ms.
  8. Pin 5 becomes LOW which turns off LED3.
  9. Pin 6 becomes HIGH which turns on LED2.
  10. Wait 200ms.
  11. Pin 4 becomes LOW which turns off LED4.
  12. Pin 5 becomes HIGH which turns on LED3.
  13. Wait 200ms.
  14. Pin 3 becomes LOW which turns off LED5.
  15. Pin 4 becomes HIGH which turns off LED4.
  16. Repeat from Step 1.

Output 2

Output of multiple LED's blink using Arduino Code 2

Troubleshooting / Errors

  • The LED’s inserted backward, so ensure that led’s big leg connected to +ve.
  • LED’s burst problem. So the use of a resistor is mandatory.
  • Wire connections may be loose.

You’ve seen how we control multiple LEDs with Arduino. Controlling multiple LEDs with Arduino is a very easy task and we can also add more LEDs and with different code algorithms. So now it’s your turn to make more awesome projects using Arduino and LEDs.

If you liked this article, then give us feedback. Share this article with the needy one. If you get any error then tell us your error by commenting


LEAVE A REPLY

Please enter your comment!
Please enter your name here