How to make an LED Blink

Levan-Techa
6 min readApr 27, 2022

--

In this tutorial, you will learn how to control an LED using a microcontroller by making it blink.

Materials:

  • Arduino Uno
  • Wire
  • LED
  • Resistor (220 ohms)
  • Breadboard

Background:

First, let’s get you started with Arduino. You’re going to need to download the Arduino IDE for your computer (Windows or Mac). Here’s a link to download.

Once the software is downloaded, go ahead and open it up. It should look something like this:

Plug in the usb cord into your computer that connects to the Arduino.

Next, you need to select the correct Arduino board from the Tools menu.

Then, select the correct COM port under Serial Port within the Tools Menu.

Verify : Checks your code for errors.

Upload :Compiles your code and uploads it to the Arduino board.

New :Creates a new sketch.

Open : Presents a menu of all the sketches in your sketchbook. Clicking one will open it within the current window.

Save : Saves your sketch.

Serial Monitor :

  • Opens the serial monitor
  • To send data to the board, enter text and click on the “send” button or press enter.
  • Choose the baud rate from the drop-down that matches the rate passed to Serial.begin in your sketch.

Basics of Arduino Coding

Arduino programming is based on Java and JavaScript.

Every Arduino program (aka Sketch) require these two functions/routines:

void setup() { }

  • All code written within the curly brackets will be ran a single time once your Arduino code is compiled.
  • Used for initializing the code, or getting things “set up” which only runs once.

void loop() { }

  • This code runs after setup has finished
  • After this code is ran once, it continues to run over and over again until the power is off

// (single line comment)

  • Commonly used to write notes to explain the code being written
  • When the code is ran, anything after these on a single line is ignored by the compiler

/* */ (multi line comment)

  • Commonly used to write longer notes to explain the code being written
  • When the code is ran, anything within these symbols are ignored by the compiler

{} (curly brackets)

  • Used to define where blocks of code begin and end

; (semicolon)

  • Each line of code must end with a semicolon to ensure there are no errors.
  • Think if them like a period to a sentence

pinMode(pin, mode); (digital function)

  • Used to set a pin’s mode,
  • the pin is the pin number you want to address
  • The mode can be with INPUT or OUTPUT
  • Goes under void setup

digitalWrite(pin, value); (digital function)

  • Once a pin is set as an INPUT or OUTPUT,
  • the pin is the pin number you want to address
  • The value can be set as either HIGH (pulled to +5 volts) or LOW (pulled to ground)
  • Goes under void loop

int digitalRead(pin); (digital function)

  • Once a pin is set as an INPUT,
  • the pin is the pin number you want to address
  • You can determine whether it is HIGH (pulled to +5 volts) or LOW (pulled to ground) and return that information
  • Used to detect signals from other components such as sensors or buttons as “input”

int (data type)

  • Short for Integer
  • Includes all numbers, positive, negative and zero
  • Does NOT include decimals

Process:

Electronics

Note: Keep all electrical components disconnected from the battery until you are ready to test the circuit and everything is connected together.

  1. Connect the negative side (short leg) of the LED to the GRD port on the Arduino using a wire.
  2. Connect the resistor in line with the positive side of the LED.
  3. Connect the other end of the resistor to pin 13 on the Arduino board.

Note: The LED won’t automatically turn on once connected to the Arduino. There’s an extra step using code to activate the current.

Code

// the setup function runs once when you press reset or power the board

void setup() {

pinMode(13, OUTPUT); // initialize digital pin 13 as an output

}

// the loop function runs over and over again forever

void loop() {

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

delay(1000); // wait for a second

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

delay(1000); // wait for a second

}

  1. Once you have the code within the Arduino IDE. Save it and Verify there are no errors.
  2. After you have confirmed there are no errors, Upload the code.
  3. At last, you have successfully made an LED blink!

Troubleshooting:

Sometimes you run into problems or errors. Don’t get frustrated, it happens to all of us!

Let’s go through what could potentially be the problem:

Mixing up positive and negative.

This is the common cause of issues when first starting out. Make sure positive connects to positive and negative connects to negative. So in this case, the short leg of the LED connects to the GRD pin of the Arduino; it is ok to have a wire or resistor in between.

Make sure everything is connected with each other.

Pretend your finger is the current and run it along the circuit starting at the pin being used and end it at the GRD pin of the Arduino. The Arduino is drawing current from the computer source. Refer to the image to make sure they look similar.

Sometimes there’s a pin mismatch.

Make sure the pin connected to the LED matches the one you assigned within the code.

Ideation:

Ok, you got control of an LED and made it blink! Nice! Great Job… now what?

Well you’re a cosplayer who came here to learn new skills for cosplay right? Let’s come up with a couple ideas of what you could do with blinking an LED.

Now magic users, instead of just having fire on, you could add the effect of flickering to bring it more to life!

Glowing Fire

You could show a heartbeat from inside your chest… or one that was ripped out.

Heart Glowing

Here’s how I used the electronics within my own cosplay props.

That’s just the beginning! The purpose here was to introduce the concept and get you to think outside of the box to not only bring your favorite characters to life, but also elevate your craft so you can look even more super too! Now you have a new tool, go make your cool costume even cooler!

References:

Arduino Coding References: https://www.arduino.cc/reference/en/

ArduinoDocumentation: https://docs.arduino.cc/

Arduino Tutorials: https://www.tutorialspoint.com/arduino/index.htm

https://arduinogetstarted.com/arduino-tutorials

Instructables Arduino: https://www.instructables.com/Arduino-Blinking-LED/

--

--

Levan-Techa
Levan-Techa

No responses yet