Blinky

Introduction

In this lesson, we'll cover the basics of circuits and electricity, and how to design your very first circuit using the components in your kit. The goal of this project is to create a simple circuit with an LED that blinks on and off at a regular interval.

Wiring the Circuit

To build the Blinky circuit, you'll need to connect an LED and a resistor to one of the GPIO pins on your controller. Remember that the LED is directional, meaning it will only light up if you connect it the right way. There is a small arrow next to the LED symbol on the components in your kit that indicates the direction of current flow. Make sure that the arrow correctly points from higher voltage towards ground. The resistor should be connected in series with the LED to limit the current and prevent it from burning out. You can connect the resistor either before or after the LED in the circuit.

If you'd like, you can test this circuit by using the 5V pin instead of a GPIO pin. If you connect the LED and resistor in series between the 5V pin and GND, the LED should light up as soon as you connect it. This can be a good way to verify that your circuit is wired correctly before you start writing code to control it.

We have included below the diagram from lesson 1-01 Circuits, which shows a basic circuit with an LED and resistor in series. You can use this as a reference for how to wire your Blinky circuit. Remember here that our source of positive voltage is going to be one of the GPIO pins instead of the 5V pin, but the rest of the circuit will look the same.

Example basic circuit with an LED and resistor in series

Writing the Code

We've left comments for you in the starter code to guide you through writing the code to control your Blinky circuit. As a refresher, here are some of the functions you may wish to use.

FunctionDescriptionUsage
digitalWriteInstructs a pin to output a digital signal until changed.digitalWrite(#, HIGH/LOW);
pinModeSets a pin to either be an ouptut or an input from here on out.pinMode(#, OUTPUT/INPUT);
delayWaits without doing anything for a specified length of time, in milliseconds. (1000 milliseconds = 1 second)delay(1000);

Testing Your Circuit

Once you have your circuit wired and your code written, you can test it out by running your program. If everything is set up correctly, you should see your LED blink on and off at a regular interval. If it's not working, double-check your wiring and make sure your code is correct. If you need, you can read through the solution below.

Code and Run