Wikijunior:Raspberry Pi/Raspberry Pi Star Wars Lightsaber

Tutorial by Andy Baker, instructions by Hal Motley

This tutorial is available in the public domain. In this tutorial you will connect a multi-colour LED to the Raspberry Pi to create a lightsaber like in Star Wars.

How lightsabers work
For this tutorial, the colour-changing LED represents a kyber crystal. In the Star Wars universe, lightsabers are powered by a kyber crystal which the Jedi attunes to their will using the Force. There are a wide variety of blade colours including:


 * Luke Skywalker – green
 * Obi-Wan Kenobi – blue
 * Mace Windu – purple
 * Rey Skywalker – yellow
 * Ahsoka Tano – white

Sith lords such as Darth Vader, Kylo Ren and Darth Maul have red lightsabers because they dominate the kyber crystals using the Force causing them to bleed.

There is a full list of lightsaber colours here: https://www.bossksbounty.com/films/every-lightsaber-color-in-star-wars

The kit

 * ×4 male-female GPIO jumper cables (also called DuPont cables, preferably of different colours)
 * ×1 breadboard (a small 5×5 breadboard works well, but any size is fine)
 * ×1 68 Ohm (blue grey black gold) resistor
 * ×1 4-pin colour-changing LED

Using a breadboard
Breadboards are used to prototype and test electronic components without needing to solder them.

Each hole is identified with a notation system using numbers horizontally across the breadboard and letters vertically down the breadboard.

Connecting the components


To setup the lightsaber, do the following:

Step 1: Power off your Raspberry Pi by shutting it down.

Step 2: Connect the colour-changing LED to the 4 holes in the top row (A13, A14, A15 and A16). Make sure that the longest pin (the ground) is lined up with the jumper wire to GPIO 39 (GND) so the LED is properly grounded.

Step 3: Connect the 68 Ohm resistor into the breadboard by placing one wire into hole B15 the other into B20 (the last hole of the second row) above the jumper wires.

Step 4: Connect the 4 jumper cables from the GPIO pin 33 (GPIO 13), pin 35 (SPI1 MISO), pin 37 (GPIO 26) and pin 39 (GND) (the last four bottom right pins, assuming the USB and Ethernet ports are to the right) to the bottom left four holes of the breadboard. I recommend trying to use the same coloured jumper wires that match the diagram exactly, though any colour combination can be used.

Step 5: Run each of the Python scripts in order, which are,  ,   and. Try altering the code and see if you can make your own colour combinations.

lightsaber.pdf
The original PDF for this tutorial is on Wikimedia Commons: