project
For this project, I needed to create a schematic involving at least 3 LEDs connected to an Arduino, implement this circuit using a breadboard, and write Arduino firmware to make the LEDs blink in some pattern.
I decided to try to create a sort of moving or scrolling effect across five LEDs.
hardware
My circuit for this project consists of five white LEDs connected directly to five pins of the Arduino.
calculation
The appropriate resistor value for these LEDs was calculated as follows:
- White LED forward voltage drop:
- Resister voltage:
- Desired forward current:
- Required resistance (using Ohm's law):
- Round up to nearest standard resistor value:
schematic
circuit
The circuit was built using the Arduino, breadboard, white LEDs, 100Ω resistors, and jumper wires from our kit.
software
// number of leds to show
const int LED_COUNT = 5;
// first pin (of LED_COUNT) to be used for LED sequence
const int LED_PIN_START = 8;
// setup: runs once at start
void setup() {
// Repeat for each of the LEDs:
for (int i = 0; i < LED_COUNT; i++) {
// Declare the pin associated with each LED
// as an output which can be written to
pinMode(LED_PIN_START + i, OUTPUT);
}
}
// the LED_COUNT least significant bits of pattern
// are used to store and update the current pattern
// displayed by the LEDs
int pattern;
// loop: runs repeatedly until you get bored, power
// runs out, or the universe explodes
void loop() {
// Shift the bits left one place in pattern,
// essentially shifting the bit pattern over
pattern <<= 1;
// Add either 0 or 1 to pattern, essentially
// choosing the new LSB of pattern at random
pattern += random(2);
// Repeat for each of the LEDs:
for (int i = 0; i < LED_COUNT; i++) {
// The ith least significant bit of pattern is written
// to the ith LED.
digitalWrite(LED_PIN_START + i, pattern & (1 << i));
}
// Block for 100ms
delay(100);
}
all together now!
The final effect can be seen in the video below. (This video loops, but in real life, new bits are determined randomly—well, as “randomly” as the little Arduino can muster—over time.)