Multiple sequence on breadboard

Multiple sequence on breadboard

Main Diagram

Hardware Required

  • PICUNO Microcontroller board
  • 4 × LEDs
  • 4 × 220Ω resistors
  • Breadboard
  • Jumper wires
  • USB cable

Description

Each GPIO pin controls a single LED. The program turns on each LED one by one with a small delay between each. Once all LEDs are turned on in sequence, the loop repeats, creating a basic flowing LED pattern.

Circuit Diagram

[Fritzing image to be added here]

Circuit

  • Connect the PICUNO board to the computer using a USB cable.
  • Place 4 LEDs in a row on the breadboard.
  • Connect the anode (long leg) of each LED to one end of a 220Ω resistor.
  • Connect the other end of each resistor to GPIO pins 2, 3, 4, and 5 respectively.
  • Connect the cathodes (short legs) of all LEDs to GND.

Schematic

GPIO 2 → 220Ω → LED1 Anode

GPIO 3 → 220Ω → LED2 Anode

GPIO 4 → 220Ω → LED3 Anode

GPIO 5 → 220Ω → LED4 Anode

All LEDs Cathode → GND

Code - C

int ledPins[] = {2, 3, 4, 5};
int numLeds = 4;

void setup() {
  for (int i = 0; i < numLeds; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
}

void loop() {
  for (int i = 0; i < numLeds; i++) {
    digitalWrite(ledPins[i], HIGH);
    delay(300);
    digitalWrite(ledPins[i], LOW);
  }
}
int ledPins[] = {2, 3, 4, 5} - Array of GPIO pins to which the LEDs are connected.

digitalWrite(ledPins[i], HIGH) - Turns ON the corresponding LED.

delay(300) - Waits for 300 milliseconds.

digitalWrite(ledPins[i], LOW) - Turns OFF the LED.

Code - Micropython

from machine import Pin
import time

led_pins = [2, 3, 4, 5]
leds = [Pin(pin, Pin.OUT) for pin in led_pins]

while True:
    for led in leds:
        led.value(1)
        time.sleep(0.3)
        led.value(0)
led_pins = [2, 3, 4, 5] - List storing the GPIO numbers used for controlling the LEDs.

leds = [Pin(pin, Pin.OUT) for pin in led_pins] - Creates a list of Pin objects, each set as an output.

led.value(1) - Turns ON the current LED.

time.sleep(0.3) - Waits for 0.3 seconds.

led.value(0) - Turns OFF the current LED before moving to the next one.