Skip to main content

Blinking LEDs


Jumping into Arduino microcontrollers can be a bit overwhelming at first. Many first-time coders may want to start with an intricate, complex algorithm, but it’s usually best to start out small - like placing a toe in the pool before diving in.

The schematic above shows a basic parallel circuit using three LEDs. Each LED is connected using a breadboard and resistors. The resistors restrict the flow of electricity to the LEDs - otherwise the voltage would cause the LED to blow. Yikes!

Each blue line on the schematic is a wire that connects to holes in the breadboard or pins on the Arduino UNO. Using the schematic, you can create a similar system using these hardware components.

When the hardware is ready to roll, the program below brings the LEDs to life. This “blink” program can be used to test out your hardware and process for downloading a .ino file to an Arduino UNO microcontroller.

Blinking LEDs Code

/*
Blinking LEDs - test program to run 3 LEDs in a pattern of blinks
*/

int yellowled = 12;
int greenled = 10;
int blueled = 7;

// the setup routine runs once when you press reset:
void setup() {                

// initialize the digital pin as an output.
pinMode(yellowled, OUTPUT);   
pinMode(greenled, OUTPUT);  
pinMode(blueled, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {

// turn the LED on (HIGH is the voltage level)
digitalWrite(yellowled, HIGH);

// wait for 1/2 a second
delay(80);

// turn the LED off by making the voltage LOW
digitalWrite(yellowled, LOW);

// turn the LED on (HIGH is the voltage level)
digitalWrite(greenled, HIGH);

// wait for 1/2 a second
delay(80);

// turn the LED off by making the voltage LOW
digitalWrite(greenled, LOW);

// turn the LED on (HIGH is the voltage level)
digitalWrite(blueled, HIGH);

// wait for 1/2 a second
delay(80);

// turn the LED off by making the voltage LOW
digitalWrite(blueled, LOW);

// wait for a second
delay(500);
}

Comments

Popular posts from this blog

Tippe Top Design

The physics behind the tippe top toy have been the subject of studies by scientists for years - dating back to the early 1890s. The tippe top is spun just like any other top, but pulls a surprise stunt. The top flips over and spins on its stem when given a strong twist. Why does the tippe top flip over? What does this mean for anyone planning to make one on a 3D printer? Nobel Prize winners, Wolfgang Pauli and Niels Bohr, take a break with a tippe top at the 1954 inauguration of the Institute of Physics in Lund, Sweden. Early Top Patents The first patent for the top, listed as “Wendekreisel”, was filed in Germany by Helene Sperl in 1891. While the patent seems to describe the top’s inversion property, reproductions of the top have proved unsuccessful. The patent expired after one year because the fee wasn’t paid. During a trip to South America, Danish engineer Werner Østberg noticed kids spinning a small, round fruit. While spinning, the fruit would flip over (or...

Creating VR Environments

Virtual reality (and augmented reality) have become major buzz words in educational technology. With inexpensive VR headsets, such as Google Cardboard , and the use of student smart phones, teachers can take their classes on virtual reality field trips - a much more preferred trip to administrators than pouring money into bus fuel. But besides immersing students in gimmicky games and field trips until the VR sickness kicks in, how else can virtual reality be leveraged as a learning tool? Building with A-Frame I attended the annual Computer Science Teachers Association (CSTA) Conference in Omaha, Nebraska. I had made it my personal and professional mission to learn how virtual reality could be used as a learning tool in computer science education. On the very first day I dove into a VR workshop where I discovered one method of programming virtual reality worlds and creating interactive 3D environments. Anyone who thinks code must be developed from scratch is kidding ...

micro:bit Fireworks with Python

I used the MicroPython editor to program a fireworks animation that controls the brightness of the LEDs as the firework explodes on the LED display. For young computer science students, this is a great introduction to text-based programming, arrays, and animating LEDs. Code # Display message and show pacman with firework option from microbit import * firework1 = Image("00000:00000:00000:00000:00200") firework2 = Image("00000:00000:00000:00200:00100") firework3 = Image("00000:00000:00200:00100:00000") firework4 = Image("00000:00000:00900:00000:00000") firework5 = Image("00000:07870:08580:07870:00000") firework6 = Image("60706:01210:72127:01210:60706") firework7 = Image("30503:00000:50005:00000:30503") firework8 = Image("10201:00000:20002:00000:10201") all_firework = [firework1, firework2, firework3, firework4, firework5, firework6, firework7, firework8] while True: if button_a.is_pressed(): ...