In this project, we will explain how to make an RGB Lightsaber, which color can be changed using an Android App through bluetooth. In addition, a 3-axis accelerometer will detect movement and play a melody using a buzzer, which can be changed to the user preference using code. To achieve this we will use an Arduino Nano located inside the lightsaber case.
Step 1: Materials
- Arduino Nano
- Mini USB to USB cable
- 4 RGB LED's (either common anodes or cathodes, in this tutorial we used anodes)
- H-05 Bluetooth module for Arduino
- 3-axis accelerometer Buzzer
- An Android phone with bluetooth
- A bunch of Jumper Cables (you can also salvage your common Ethernet cable for wires)
- A breadboard for testing (preferably one with detachable power lanes)
- A case to hold the project (we used an old lightsaber toy)
- Soldering Iron and Solder
- Glue gun and glue sticks
- Electrical tape
Step 2: Setting Up the RGB LEDs
RGB LEDs are pretty simple to use with Arduino, connect the four legs using the diagram for reference. For this project, we connected four LEDs in series, as we wanted the color to remain consistent for every LED. The red legs are connected to pin 9, the green legs to pin 10, and the blue legs to pin 11, as we are using common anodes, connect the common leg to the power source. We used the detachable power lanes of the breadboard to distribute the power throughout the components and later we secured them into the lightsaber.
If you don’t know whether you have common anodes or common cathodes, simply connect the longest leg to either +5V (for common anodes) or to ground (GRD, for common cathodes). We used common anodes in this project, so if you have common cathodes, there’s a few changes that need to be done to the coding.
Step 3: Connecting the H-05 Bluetooth Module
The module is connected in the following way:
- VCC to power (+5V)
- GRD to ground.
- TXD to pin 8
- RXD to pin 12
In this case, we will not use EN y STATE pins.
Step 4: Connecting the Accelerometer
The accelerometer is connected in the following way:
- VCC to power (+5V)
- GRD to ground
- X to A0
- GS1 to pin 0
- GS2 to pin 1
- SLP to pin 2
In this case, we will not use the values of the Y and Z axis. Due to the project being a lightsaber, the sound is activated when it detects a sudden movement. The values in the x axis is enough to determine that the saber is moving (through the derivative, that results in the velocity of the saber) and activates the sound.
Step 5: Installing the Buzzer
The next step is connecting the buzzer to pin 7. And the negative pole to ground.
Step 6: Loading the Program Into the Arduino
The next step, once everything is connected, is to plug the Arduino Nano into the PC using a Mini USB to USB cable. Using the Arduino app, load the attached code into the Arduino
It is very important to copy the pitches.h file into the same folder that the Final.ino file, otherwise, the code will not work.
This code connects the bluetooth module to change the color of the light, changes the color of the LEDs, gets the value of the x axis from the accelerometer and from that, it gets the velocity in order to determine whether the saber is moving, to conclude, it sends the melody that the buzzer will play.
NOTE: If you want to change the buzzer melody, simply edit the values of the array variables melody (in which the notes are defined, and played) and note Durations (which is the duration of the sound using as reference a 4/4 bar).
Step 7: Check That the LEDs Work Correctly
When you run the program, you’ll notice that the LEDs didn’t turn on. Before panicking download the app BT LED Controller from the Google Play Store and intall it in an Android cellphone.
Turn on your cell phone's bluetooth, and open the app. Click on BT List in the top left corner and look for the H-05 option. This is our Arduino bluetooth receptor and connection will be established.
Press the tun LED On option and verify that the LEDs did turned on. Check the RGB channels, one by one using the app sliders. If everything is okay go to the next step.
If the G and B channels are reversed, you can change them physically by changing the pin of the green leg with the one of the blue leg, or in the code changing the variable established at the beginning. If the LEDs didn’t turn on, check the connections.
Step 8: Check the Accelerometer and the Buzzer
To test these components, simply move quickly the accelerometer, a familiar and funny tone should sound. If everything works correctly proceed to the next step, otherwise check the connections with the diagram.
Note: The music can be changed easily, see step 5.
Step 9: Assemble the Lightsaber With the Components
First, we secure the accelerometer the original board of the saber was. The buzzer matched with a hole in the lightsaber, so we secured it there. Then we secured the bluetooth module with tape, on top of the accelerometer. We put the Arduino Nano using the foam it came packaged with. We paste it with glue. We secured the channel of the breadboard using hot glue. Finally, we secured the LEDs with tape and glue in the top of the saber.
Step 10: Enjoy the Lightsaber
Codebender_cc ( s.f.) How to Use an RGB LED - Arduino Tutorial. Recuerado de https://www.instructables.com/id/How-to-use-an-RGB-LED-Arduino-Tutorial/
Kerimil (s.f.) How to control arduino board using an android phone and a bluetooth module. Recuperado de https://www.instructables.com/id/How-control-arduino-board-using-an-android-phone-a/
Roux, N. (2015) Arduino Light Saber. Recuperado de https://www.myminifactory.com/object/arduino-light-saber-15696
Learn.adafruit.com. (2017). Overview | Introducing Pro Trinket | Adafruit Learning System. [online] Recuperado de https://learn.adafruit.com/introducing-pro-trinket