0% found this document useful (0 votes)
16 views7 pages

Lab 3

The document outlines three tasks related to programming LED strips using Arduino. Task 1 involves making 10 LEDs blink with a 100 ms delay, Task 2 focuses on sequentially blinking 20 LEDs in red, green, and blue colors with a 200 ms delay, and Task 3 describes creating unique lighting patterns such as breathing, alternating pairs, and wave effects. Each task includes code snippets and explanations of the functionality and control flow.

Uploaded by

lituhalder132
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Lab 3

The document outlines three tasks related to programming LED strips using Arduino. Task 1 involves making 10 LEDs blink with a 100 ms delay, Task 2 focuses on sequentially blinking 20 LEDs in red, green, and blue colors with a 200 ms delay, and Task 3 describes creating unique lighting patterns such as breathing, alternating pairs, and wave effects. Each task includes code snippets and explanations of the functionality and control flow.

Uploaded by

lituhalder132
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ICS 423 Internet of Things

Name: ANISH HALDER


Roll No: 2021BCS0034

LAB-3
Task 1: Write a sketch that uses 10 LED strips (make the 10 LEDs to
blink).
Here 10 LED’s will blink after a time delay of 100 ms

Code:
Working of the Code:
setup() Function:
• pinMode(ledPins[i], OUTPUT);
This loop iterates through all the pins in the ledPins array and sets
each pin to OUTPUT mode. This enables control of the LED
connected to each pin.
loop() Function:
• digitalWrite(ledPins[i], HIGH);
This line turns on the LED connected to the current pin (ledPins[i])
by setting the pin to HIGH.
• delay(100);
A short delay of 100 milliseconds is added to keep the LED on for a
brief moment.
• digitalWrite(ledPins[i], LOW);
This line turns off the LED by setting the pin to LOW.
• delay(100);
Another short delay is introduced before the next iteration starts,
ensuring the LED stays off for a brief moment before turning on the
next one.
Task 2: Write a sketch that sequentially blinks LED strips (20 numbers) in
three different colors.

Code:
Working of the Code:
1. The loop() function cycles through three different colors (Red,
Green, and Blue):
For each color:
▪ The LEDs light up sequentially using a for loop to iterate
through the LEDs in the strip.
▪ The setPixelColor() function sets the color of a specific
LED by using the corresponding RGB values for the
color.
2. The switch statement determines the color of the LED based on
the color variable:
Case 0: Red (RGB: 255, 0, 0)
Case 1: Green (RGB: 0, 255, 0)
Case 2: Blue (RGB: 0, 0, 255)
3. Each LED lights up in the selected color with a delay of 200ms:
The delay(200) ensures the LED stays lit for 200 milliseconds
before moving to the next LED.
4. After the delay, the LED is turned off:
The setPixelColor() function is called again with RGB values of
(0, 0, 0), turning the LED off.
strip.show() updates the strip to reflect the changes (turning
off the LED).
5. The outer loop (for color) ensures all LEDs blink sequentially in the
order of colors:
The LEDs first blink in Red, then Green, and finally Blue.
6. The process repeats indefinitely due to the loop() function:
Once all LEDs have cycled through the three colors, the
process restarts and repeats endlessly.
Task3: Identify a unique pattern to blink LED strips to use in your study
room.

Code:
Working of the Code:
1. Sending Signals to the NeoPixel Strip:
o The Arduino sends digital signals to the NeoPixel strip through the data pin 6.
o These signals contain the color and brightness information in the form of RGB
(Red, Green, Blue) values for each LED in the strip.
2. Adafruit NeoPixel Library:
o The Adafruit NeoPixel library simplifies the control of the LED strip by
providing functions such as:
▪ setPixelColor(): Sets the color of each individual LED using RGB values.
▪ show(): Updates the strip to apply the changes made with
setPixelColor().
3. Effects Implementation:
o Breathing Effect:
▪ All LEDs gradually brighten and dim by incrementing and
decrementing their RGB brightness values. This creates a smooth,
breathing-like effect.
o Alternating Pairs:
▪ LEDs light up in pairs with different colors, creating a calm, alternating
pattern.
o Wave Effect:
▪ LEDs turn on and off sequentially, simulating a wave or ripple effect
across the strip.
4. Control Flow:
o The loop() function repeatedly cycles through the programmed lighting
patterns.
o The timing of each effect is controlled using delay() to achieve the desired
transitions, blinking speeds, and smoothness of the effects.

You might also like