CosplayTutorials

Basic RGB LED Tutorial – Vamprea

SAFETY NOTE

If you are going to have a TONNE of LEDs in your costume please put a fuse between the microcontroller and LEDS on the positive wire (BUS pin). If your LEDs for some reason short circuit it will prevent you from catching on fire.

Soldering irons are hot! Be careful

 

The aim of this tutorial is a basic introduction on how to get started with RGB LEDs and microcontrollers for your cosplays/projects.  This tutorial requires some basic coding knowledge as it will help you to understand what the hell is going on! However I will try and explain it to my best capabilities.

There are many MANY tutorials on RGB leds and how to set them up, there is also a lot of pre-written code out there which you can use and customise if that is an easier option.

(I will provide a purchasing/links list at the end of the tutorial for each of the options)

The Microcontroller

To start with we need a microcontroller! For this I chose the Trinket Pro 5V from Adafruit

Powering the Microcontroller

To power the Trinket there are two simple and easy options which can be chosen to fit your project.

Option 1:

The first option is to use the Trinket Pro 5V with a Powerboost 500 Charger and a Lithium ion battery connected by a micro USB cable:

Option 2:

The second option is to use the Trinket Pro 5V with a power bank used for charging a mobile phone. The benefit of this is that you can get different sizes and shapes of power banks to fit your project.

For my deathknight I used a 10,000mAh power bank like this, which lasted me more than an entire day!:

For the mace of my deathknight I needed a smaller solution that would be able to fit within the handle, so I used this small 2600mAH power bank that fit perfectly inside the PVC pipe!

Option 3:

It is also possible to use batteries such as AA’s/AAA’s/button-cell in a battery pack and solder these directly to the board with a switch, however please ensure that the voltage is correct for the Trinket you get (either 5V or 3V), if it is greater than the voltage the Trinket can take it will stop working.

 

The LEDs

So we next need some LED’s, for this we need WS2812B LEDS’s (be sure to purhcase the correct type). There are a few places you can purchase these, I found the cheaper option was to buy from Aliexpress since Adafruit international shipping to Australia would cost a bit.

You can get these LED’s as single LED’s or strips:

Aliexpress – WS2812B Single LEDs

 

Aliexpress – WS2812B Strip LEDs

 

They are also available on Adafruit but have 4 pins rather than 6 (so slightly different).

Note: When buying LED strips, it’s best to buy non-waterproof if you’re cutting them up and resoldering them!

 

Getting Started

Finally once we have all out LEDs and our microcontroller we need to have a few more supplies before we can begin soldering:

  • Soldering Iron
  • Solder
  • Three different colour wires, usually black for negative, red for positive and one other colour (your preference).
  • Pliers (and wire stripper if you have one)

We now need to understand how our microcontroller will be used! I am not going into an in-depth explanation of this but you can read about the Trinket Pro Pinouts on the Adafruit learning system.

 

 

The first things about using your controller (circled in blue) are:

  • Micro USB port – Used to power and connect your Trinket to a battery or computer.
  • Reset Button – Used to reset the Trinket and also used when uploading program to Trinket.
  • Red Reset Light– Pulses when reset button is clicked (signals ready to upload).
  • Green Light – Shows Trinket is powered on.

 

The next thing is to go over the pins which will be using to connect our LEDs to (circled in Red):

  • G – The ‘G’ pin stands for ‘Ground’, we will connect our negative wire to this.
  • BUS – The BUS pin is for the positive wire, direct power from the Micro USB port is connected to this pin.
  • Pin 8 – Is the pin we will use to tell our programs where our LEDs are located (you can use other numbered pins too, 8 is just closer).

Finally we need to understand how our LEDs will be connected.

 

 

  • Positive (BUS) – This pin will connect to the BUS pin on the microcontroller which provides power. Use a RED wire to indicate positive.
  • Pin (Pin 8) – This pin will connect to Pin 8 (unless other pin is used).
  • Ground (G) – This pin will connect to G, Ground. Use a BLACK wire to indicate negative.
  • LED Direction – This is important! All LED’s must connect with the arrows facing away from the controller, eg: Micro controller → LED → LED → LED

Soldering Circuit Together:

Here is the basic diagram of how we need to solder the circuit together.

  1. First, cut your three different coloured wires to size, and strip the plastic casing off each end.
  2. Twist the ends of each wire.
  3. Add solder to the ends of each wire.
  4. Add solder to the 6 points on your LEDs
  5. Connect your wires to your LEDs
  6. Once you have connected your wires to your LEDs you can connect them to your microcontroller.

 

Now your circuit is complete! This is the same process for LED strips however you will only need to solder the LED strip to the microcontroller.

 

Setting up the Trinket with a Computer

I will give the basic instructions for setup, I personally ran into a bit of trouble to get mine working on Windows but if you persist and follow the provided instructions Adafruit has written then you should be fine.

 

Mac/Linux Users:

  1. Download the Arduino IDE and install it.
  2. Follow these instructions to add the Trinket Pro as a board to the IDE

Windows Users:

  1. Download the Arduino IDE and install it.
  2. Download the Trinket Pro (Tiny USB) Driver and follow instructions.

Next we need to import the Arduino FastLED Library, this library allows us to easily control the LED’s both sold by Aliexpress and Adafruit.

  1. Download FastLED Iibrary
  2. To import the ZIP into Arduino IDE: Sketch > Include Library > Add .ZIP Library
  3. Select FastLED ZIP file

 

Finally, you can connect your microcontroller via micro USB to your computer. If all goes well it should connect.

 

Our First Program!

To begin with our first program with need to define a few things. We need to include the FastLED Library so we can use it, we then need to define how many LEDs we have, in this case 2 and then finally define which pin we are using, which is 8.

The defined values can be called later using the variable name. This saves us from re-typing the numbers each time, and makes it easier to change the number of LED’s in the future.


#include <FastLED.h>

#define NUM_LEDS 2

#define DATA_PIN 8

Next it we setup the block of memory that will be used for storing and manipulating the LED data:


CRGB leds[NUM_LEDS];

Now to setup our LEDs, we need to tell the microcontroller the number of leds and pins connected:


void setup() {

FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

}

 

 

Once this is completed we can now write code to write to the LED. We are going to make it turn red.


void loop() {

 

}

We can select the LED number in the line starting from 0. Then we can choose the colour, to set RGB colour values .setRGB(red, green, blue). 255, 0, 0 is red.


void loop() {

leds[0].setRGB( 255, 0, 0);

}

We then need to tell the micro controller to show the LED and add a delay.


void loop() {

leds[0].setRGB( 255, 0, 0);

FastLED.show();

delay(30);

}

Now to upload your code onto the microcontroller. You need to hit the button once on the microcontroller so that the red light comes on and pulses. Once you have done this you can go ahead and click the upload button (the arrow next to the tick) on the menu bar.

 

 

 

If all goes correctly, you should have a red led turned on! If you get an error in the console check the Adafruit link to find out what is wrong on the Adafruit site!

 

 

Our Second Program! Blinking

This red LED is a little boring so this time we are going to make it blink.

We are going to change the content that was in Void loop() by first turning the LED on to Red then turn it off to Black.

First, change your delay from 30 to 1000.


void loop(){

// Turn the first led red for 1 second

leds[0].setRGB(255, 0, 0);

FastLED.show();

delay(1000);

}

Now we will add another piece of code within the loop which is the same as above but setting the colour to black.


void loop(){

// Turn the first led red for 1 second

leds[0].setRGB(255, 0, 0);

FastLED.show();

delay(1000);

 

// Set the first led back to black for 1 second

leds[0].setRGB(0, 0, 0);

FastLED.show();

delay(1000);

}

Again go ahead and upload your code and you should get something like this!

 

 

Third Program Many LEDs

We need to give that other LED some loving. This is a bit more complex if you have not coded before.

We have to create for loop which will count through the number of leds starting from 0 to 1 (total of two leds).

How the loop works is:

Integer ‘dot’ will start at 0 until it is no longer less than NUM_LEDS (which was defined at the start), if it is still less than NUM_LEDS it will increment by 1.

By setting the led number Led[dot] rather than specifying an led like we did previously, it should go through both leds as the value of ‘dot’ will change from 0 to 1 as it is within a loop.


void loop() {

for(int dot = 0; dot < NUM_LEDS; dot++) {

leds[dot].setRGB(255, 0, 0);

FastLED.show();

delay(1000);

 

// clear this led for the next time around the loop

leds[dot].setRGB(0, 0, 0);

delay(30);

}

}

 

Now upload the new code and you should have something like this!

You can adjust the delay to either make it go faster or slower. This will obviously look better with a long strip of leds!

 

 

Final Program, Fading!

Finally the next complex thing is to fade to black rather than blink on and off.

We can still use the code from above however, we need to add a new for loop inside of the already existing for loop that we created to control both LEDs!

Currently, the colour we are using (red) has 255 values, we need to decrease the value to eventually end up at 0 which is black (0, 0, 0). To do this we need to create a new integer ‘fade’ and set it to 255. We then need to decrement until it gets to 0.

Finally to slow down the fade we can add another delay of (5).


void loop() {

for(int dot = 0; dot < NUM_LEDS; dot++) {

leds[dot].setRGB(255, 0, 0);

FastLED.show();

delay(1000);

 

//Fade to black

for(int fade= 255; fade > 0; fade--){

leds[dot].setRGB(fade, 0, 0);

FastLED.show();

delay(5);

}

 

//clear to black

leds[dot].setRGB(0,0,0);

delay(30);

}

}

 

 

That concludes this tutorial! Please leave a comment if you have any questions or shoot me a message via my Facebook page and I will try and answer as best as I can!

Purchasing List:

Adafruit:

Aliexpress:

Amazon:

Ebay:

Useful Links:

Vamprea

Vamprea is a cosplayer from Melbourne, Australia who specialises in sewing, armour making and electronics. She has been cosplaying since 2015 and has won a range of competitions with her cosplays over the years.

Leave a Reply