Physics For Toys Blog

miniDuino

The ATmega 328 chip is the heart of the Arduino Uno Board. Although it has limited memory, it has several general purpose I/O pins and six Analog to Digital pins. This makes the Arduino excellent for projects that read sensor values, or that control servos, motors or lights. The only problem with the Arduino Uno is that it does not fit on a breadboard.

There are Arduino compatible boards that fit on a breadboard, like the Arduino Mini, Arduino Nano and adafruit Pro-Trinket. Another option is to use the ATMega 328 chip directly on a breadboard:

This is the minimal configuration for the ATmega 328, in addition to the chip you need a crystal and a two capacitors. The crystal should be rated 12~16 MHz and the capacitors are usually 20pF. The only drawback is that in order to program the chip you may need to put it in a programmer circuit, or use an Arduino Uno to program the chip, as explained in this article

From Arduino to a Microcontroller on a Breadboard

The prototype above show the connections to a power source and ground, without specifying how that will be done. The next diagram shows a complete power source, including a switch and a voltage regulator:

And in a breadboard it looks like this:

This circuit is capable to drive LED’s or monitor sensors, but still we need and external programmer to modify the code inside the ATmega 328. One solution is to add USB capability, but USB requires a lot of engineering and registration. The ATmega is capable of serial communication (UART) and we can use that to connect our circuit to a computer, using a bridge technology created by FTDI (Future Technology Devices). A FTDI cable will convert the signal from a USB port to UART protocol. The cable has five different pins in six wires: Reset (green), Tx (yellow), Rx (orange), +5V (red) and Ground (Black and Brown). In the following diagram we show how you wire your ATmega 328 to have UART communication with a PC:

Notice that only one Ground pin is required for the FTDI connection, however the FTDI adapter from adaFruit has six pins and the last two are connected to ground. The breadboard will look like this:

This circuit is a full functional Arduino compatible board, but we did not have any advantage over an Arduino Uno board. What we need is a more compact solution in a board:

Order from OSH Park
As you can see you have a full functional Arduino compatible board that can be used in a breadboard, with enough space left on the breadboard for your project. By using the battery connector (9V) and the LM385 regulator this board is capable of delivering current for up to 1.5 amps., provided you put a heat sink on the LM385 chip.

To solve different problems I have created two additional flavors of the miniDuino:

The miniDuino-np. This is exactly the same breakout as the miniDuino but without the power supply circuitry. Ideal for problems where the power (5V) is already supplied to the breadboard:

Order from OSH Park

I also designed a miniDuino with an i2c bus. The four headers going out to the left of the pcb are GND, 5V, SCL and SDA. Look for a blog in the future about connecting a miniDuino to a Raspberry PI using the i2c bus.Order from OSH Park

To power the miniDuino-i2c there is also a power supply break out that can be daisy chained to the miniDuino-i2c, you just need to connect it to a 9V battery or a 9V battery eliminator and you can power up to three miniDuinos.

Order from OSH Park
You can daisy chain the miniDuinos and the power supply using any topology. Here you can see a miniDuino-i2c, power supply and another miniDuino-i2c. The power supply has well labelled pins to add the power to the breadboard rails if needed. For more than two miniDuinos, or to provide up to 7Watts of power, you may need to add a heat sink to the back of the LN7805.

You can order any of the miniDuino boards from OSH Park following the links embedded below the image

 

Building the GlowSaber main board

All the logic, sound and light effects of the GlowSaber are performed by a small microprocessor board. In this tutorial I will explain, step by step how to put together the main board of a GlowSaber.

Where do I find the parts?

This is an open source project. In 2014 we ordered enough parts to build 60 GlowSabers, and we still have enough parts to build about 20 more. All the parts and PCB’s are available from this site while they last, but you can also order them from the same manufacturers and distributors that we use. Ordering from us has the only advantage of getting everything in a single place.

At the end of the article you will find the links to all the providers, as well as links to the GitHub code repository.

Bill of Materials

  1. The printed circuit board. 
    dsc_0572
  2. (1) 470Ω 1/4 watt resistor and (1) 220Ω 1/4 watt resistordsc_0627
  3. (4) 22Ω 1 watt resistorsdsc_0588
  4. (2) 100 μ farad capacitorsdsc_0590
  5. (1) LM7805 5 Volt regulatordsc_0591
  6. (1) ULN2003A  7-Darlington Transistordsc_0654
  7. (1) Adafruit Triple-Axis Accelerometer – ±2/4/8g @ 14-bit – MMA8451 PID: 2019dsc_0651-crop
  8. (1) Adafruit Pro Trinket – 3V 12MHz PID: 2010dsc_0649-c
  9. (2) Eight right angle male header connectors.dsc_0636-c

Put everything together

1. Voltage divider resistors

The 470Ω and the 220Ω resistors are a voltage divider that the code uses to monitor the health of the battery. When the battery voltage is too low the program will shut down the RGB LED and the sound. Although monitoring the battery for normal AA disposable batteries is not critical, it could be if you decide to power your GlowSaber with rechargeable nickel metal hydride or lithium ion (Li-Po) batteries.

As these two resistors are positioned to be under the microprocessor board, it is required that they are as close to the PCB as possible.

Resistors do not have polarity and can be connected either way. dsc_0660

2. LED and speaker resistors

The 22Ω resistors control the amount of current that pass through the RGB LED and the speaker.dsc_0664

3. 5 Volt Regulator

The 5 Volt regulator may need to dissipate heat, and for that purpose all the ground copper in the top layer of the PCB is connected to the heat sink of  the regulator. A 1/4 inch 2-26 screw and bolt help to keep a good heat flow.
dsc_0667

4. 100μf Capacitors

These two capacitors help to regulate the initial current demand from the RGB LED. As these are electrolytic capacitors they are polarized and can be damaged if connected backwards. Make sure that the long lead goes to the round soldering pad and the short one goes to the square soldering pad. The capacitors have a silver strip running the length of their body. That is the negative side of the capacitor. When properly connected the silver stripes face each otherdsc_0674 dsc_0676

5. ULN2003 A

This array of transistors drive the current to the RGB LED and the speaker, effectively working as a current amplifier for the signal the microprocessor sends. Notice that the chip has a notch. The PCB outline for the chip is interrupted. The notch must face the outline interruption, as you can see in the picturedsc_0679-c

6. Accelerometer

dsc_0683

7. Processor

Notice that the Pro Trinket 3V3 has two additional headers. They are to connect A6 and A7 two additional analog ports in the Pro Trinket. A7 is used by the GlowSaber to measure the battery voltage.dsc_0689

8. Connector headers

There two sets of connectors. One goes to the switch assembly and the battery, the other to the RGB LED and the speaker. Although they could go either on the top or the bottom of the board, they will fit better in the hilt if they go on the topdsc_0695-2016-09-11_17-41-42-864

9. Clean the board.

Solder rosin residues on the board will show as a white dust on top of the soldering spots. It could be slightly corrosive and is better to clean it up. An old tooth brush with some dish detergent will remove all the residual rosin from the board. Just put a couple of drops of the detergent on the brush, and brush the circuit with it and water. Let it dry thoroughly before making any electrical connections.

Links to parts:

All the parts can be ordered from this site.

OSHPark

OSH Park is a community printed circuit board (PCB) order. They do a great job and have reasonable response times. You can find them here

You will find the PCB for the GlowSaber here: OSHPark – GlowSaber. Notice that the minimum order is three PCB’s

adafruit

The triple axis accelerometer and the Pro Trinket 3V3 can be ordered from adafruit.com

Digi-Key

Digi-Key is an electronic parts provider. The good thing is that you can order items in very small quantities, even only one. Almost all the parts for the GlowSaber were ordered from this site. You can find the order for the GlowSaber parts here

What else?

This article describes how to make the main board for the GlowSaber. In addition you will need:

  • The switch assembly
  • The RGB LED assembly. Found a description here
  • Cables to put all together
  • The handle. Found a description here
  • The code for the GlowSaber is in GitHub: GlowSaber code
  • For a limited time I will offer the parts to build a GlowSaber, including the Handle, light emitter, LED assembly and Switch assembly. I will only charge my cost and after my inventory is exhausted I may not replenish it. If you are interested please send an email to: Carlos.Vadillo@gmail.com. Please put GlowSaber in the subject.

 

 

Building the GlowSaber handle

Design constrains

One premise that I had while designing the GlowSaber was that I should be able to build all of it with tools that I already have. That limited the materials I could choose to those that I could cut, drill and glue with just the basic tools:

  • Miter Saw
  • Drill press
  • Dremel hand held tool
  • Hand drill
  • 4-40 Drill and Tap kit

The choice of materials included several plastic materials, PVC piping, copper piping and aluminum piping. The last two were immediately discarded as they are very expensive and not easy to find in the dimensions the GlowSaber required.

A quick visit to the Tap Plastics web site showed me that the only adecuate material would be Poly-carbonate. It has excellent strength characteristics and is very easy to cut using a miter saw. However, there are only transparent pipes and that did not see appealing for the GlowSaber handle, although it makes a perfect material for the blade. Is light and impact resistant.

That left PVC as the material of choice. It is available in any hardware store and if you go to Home Depot you can buy two foot segments at a reasonable price. More than that, it has a great variety of connectors that can be used to transition from the diameter of the handle to the diameter of the blade.

When I put the circuit board and the battery pack together I found that the smallest internal diameter pipe that I could use was 1.25 inches. PVC pipes are sold in 1/2″, 3/4″, 1″  1-1/4″, 2″ and so on. The 1 1-4″ nominal internal diameter is actually 1.4″ inches and that gave some extra room to put everything together.

It took several iterations to design the handle, and eventually I arrived to this simple design:

handle

It has three slots. The one in the front will allow the installation of the switch assembly and the two slots in the back allow to secure the speaker with a plastic tie. More on this in the assembly guide.

Bill of Materials

I bought all the PVC at Home Depot:

  1. A 2 ft. length of 1-1/4″ pipe. This is enough to make two handles
  2. A 2 ft. length of 1″ pipe. If you can get a smaller size go for it. You really only need about 4 inches total.
  3. One 1-1/4″ coupling.
  4. One 1-1/4″ to 1″ reduction
  5. One 1-1/4″ end cap.
  6. A small amount of PVC cement.
  7. Two 3/4″ 4-40 bolts
  8. Four 5/8″ 4-40 bolts

The firs few handles that I build were made with plumbing grade PVC. Then I found Formufit, a furniture grade PVC provider. They sell very attractive PVC pipes in various colors. As I was going to make many GlowSabers I did not mind buying 8 foot long pipes, and at that time they did not sell shorter segments. Anyhow, check their site: Formufit

Cutting the pieces

I start cutting the 1-1/4″ pipe. The design calls for a 9-3/4″ long:

153

Next cut the 1″ pipe. You need two lengths on of 2″ and another of 1″:

170

All the pieces together:

171

From the back, left to right: 9 3/4″ long by 1 3/4″ diameter pipe, the 1 1/4 coupling, the 1 1/4″ to 1″ reduction and the end cap. In the front a 2″ long by 1″ diameter pipe and a 1″ long by 1″ diameter pipe.

You may want to sand some of the markings in the couple, reduction and cap. I use a grit #80 sandpaper to remove the markings. Then I use 200 and 400 grit sand paper to make the PVC smooth. Anyhow it will be painted and the paint will cover the small scratches from the sand paper:

162

167

160

166

172
175

Machining the handle.

Next step is to drill guide hole for the slots. This PDF file has a template to cut and put on the pipe and the couple: Handle and Light emitter templates

038

The top design is for the pipe, and the bottom one for the couple. Let’s start with the pipe template. Once it is cut you can tape it to the pipe as follows:

012

Drill the three holes with a 1/8″ bit. Then use a Dremel rotary tool to machine the slots from the holes to the top of the pipe. Last drill a 3/8″ hole in the front slot:

018

A Dremel rotary tool can be hard to control by hand for this job. I have a small router table for it. Still is a hard job to do. However the slots are not going to be visible and if they are not perfect it really does not matter.

019

Assembling the light emitter

The 1-1/4″ couple, the 1-1/4″ to 1″ reduction and the two segments of 1″ pipe will make the container for the RGB LED and the base for the blade.

First we insert the 2″ x 1″ piece into the 1-1/4″ to 1″ reduction.
Use the screw vise to press the pipe into the reduction. The reduction has a small ridge half way. Make sure the you don’t press beyond that or you will add too much stress to the pipe and the reduction and they can break.

176

177

Now use the 1″ x 1″ pipe and glue it on the other side of the reduction. Use PVC cement and make sure the the 1″ hole are perfectly aligned:178

179

181

Let the PVC cement cure for at least 10 minutes before proceeding. Once the pipe is firmly attached we will complete the light emitter by inserting the reduction into the couple:

182

184

Be gentle when you are pressing the reduction. Slow is better.

Once the reduction is in place you can cut and put the screw pattern on the light emitter. Then mount the emitter on top of the handle, making sure to align one set of screws with the front slot:

193

The next picture shows the couple on top of the handle. After I took the picture I realized that the pattern was upside down. I corrected it and drill the holes. I used a 1/16 drill bit to be able to tap a 4-40 thread on the holes.

195

The finished handle with the light emitter bolted in place. The two screws on the front will secure the switch assembly. The top screws secure the blade, and the bottom ones secure the LED assembly.

205

The 3/4″ 4-40 bolts go in the front, as they need to hold the switch assembly.

206

The only step missing is to screw the cap at the bottom. If you go to Formufit you can get nicer end caps than the plumbing ones:

208

This cap does not need screwing. You just press it into the pipe and it will stay in place.

The next picture is a full handle, using Formufit PVC. The light emitter can be painted with Krylon paint. This particular handle has the light emitter cover with PVC film, also by Formufit.228

231

Building an ATmega328 uploader

The ATmega328 is the heart of the Arduino Uno micro controller and has a very successful ecosystem and is used in hundreds of projects. The ATmega328 can be found as a SSD chip or as 28 DIP chip. The last is the one used in the Arduino Uno, and it is easy to handle and small enough to be used in really small projects.

When starting the design of the GlowSaber I used complete boards for the project, first with the Arduino Nano and later with the Adafruit Pro Trinket. Both boards are complete with USB port, voltage regulation, clock and other features.

As I learned more about Arduino I realized that it is possible to redesign the GlowSaber around the ATmega328 chip, and that only a few extra components are required, like a crystal and two condensers. Of course you need to provide also a well regulated voltage, using a linear regulator like the 7805 chip.

Problem is that to upload the code into the chip you need an AVR Programmer and need to do some magical configuration in your computer and use some arcane programs (the AVR programmer).

However there is an easier alternative, without leaving the Arduino IDE. I stumbled by chance in the excellent article From Arduino to a Microcontroller on a Breadboard. This blog explains how to use an Arduino Uno to burn the bootloader into an ATmega328 chip. The bootloader is the code that allows to upload code to the firmware in the chip.

Once you have bootloaded your chip is ready to get uploaded with any program using also an Arduino Uno, as explained in the article above.

If you are going to program one or two chips, the breadboard solution in the article is enough. But if you want to program several dozens of them then you need a more reliable way of doing it, and not having to deal with flimsy prototype boards and cables. That was my case as I plan to use this technique for my newer GlowSaber design, as well as for my Auduino breakout board.

To achieve that I designed an Arduino Shield that can be used to burn the bootloader and upload programs to an ATmega328 chip. I had the shield fabricated for me at OSH Park, my favorite PCB provider.f86ae9c5963cb58ac72055506a12c0f0
Order from OSH Park

The shield can be used either to burn the bootloader or to upload code into the chip. However they are two different operations and require slightly different configurations.

The bootloader burning configuration requires a complete Arduino Uno board, with the Arduino ISP code loaded, as explained in the article From Arduino to a Microcontroller on a Breadboard. The pins used in to send data to burn the firmware are 10, 11, 12 and 13. Pin 10 in the Arduino is used to control the reset pin in the chip to burn.

The code uploader requires an Arduino board without the chip. It uses pins Tx0 and Rx0 to upload the code. The reset pin needs to be connected to the reset pin in the Arduino board.

The shield has a switch to select whether you want the reset pin connected to pin 10 or to the reset pin in the Arduino board. It also has an option to add LED’s to pins 9, 8 and 7 as suggested in the code for Arduino ISP.

The rest of this blog will show the process of building this shield step by step.

Parts list

You will need the following parts. This is a link to order them from DigiKey

  • (1) zero insertion force (ZIF) 28 pin socket. This is a must if you are going to be doing a lot of chips. 
  • (1) crystal oscillator. The documentation says anything from 4 to 16 MHz. I am using a 16 MHz crystal.
  • (2) matching condensers for the crystal, usually 20~22pF
  • (3) 1 KΩ 1/8 watt resistors
  • (1) 10 KΩ 1/8 watt resistor
  • (1) Green LED 5mm
  • (1) Yellow LED 5mm
  • (1) Red LED 5mm
  • (1) switch slide SPDT
  • (1) male header 40 pins

Arduino Programmer Shield 030

The three 1 KΩ resistors and the LED’s are optional. The board will work without them. The single most expensive part is the ZIF socket, and I did not buy it from DigiKey.  You can find it from other suppliers and is included in the shared cart for completeness.

And last but not least you will need the PCB. You can order from OSH Park following the link above. They will send you three copies of the board for about $25. You will need one for the bootloader, if you plan to burn it and one for the uploader. You can use the third one as a spare.

Arduino Programmer Shield 003

Tools needed

You need a good soldering iron, cutters, pliers, soldering vacuum to remove excess solder or fix mistakes, and a good vise to hold the board

Assembling the board

I have two Arduino Uno R3 boards and all the instructions are based on them. Previous versions of Arduino may have fewer positions in the headers. That should not matter but I have not tested the hardware/software with other boards.

1. Start with the headers.

The Arduino board has four groups of pins with 10, 8, 8 and six pins. The easiest way to solder the headers and make them align right is to put the headers in your Arduino board:

Arduino Programmer Shield 038

Push the headers all the way down

Arduino Programmer Shield 039

and the put the shield on top of the Arduino board Arduino Programmer Shield 040

Solder all the pins and make sure there are no short circuits.

Arduino Programmer Shield 042

If you are going to use the board to burn the bootloader do not put headers in the TX0 and RX0 pins, as the may interfere with the burning operation. See the picture below

IMG_3230[1]

2. 10 kΩ resistor

Now notice the resistor close to where the 28 pin socket will be. This resistor need to go on the other side of the board, otherwise it will interfere with the socket. Also the board says 1 kΩ, but we should use the 10 KΩ resistor instead.

Arduino Programmer Shield 045

Once the resistor is soldered in place, cut the leads as flush as possible with the board.

3. Crystal and capacitors

Flip the board again and solder the crystal and the capacitors. They can go either way in the holes

Arduino Programmer Shield 054

4. 1 kΩ resistors

This step is optional. If you don’t plan to add the LED’s you can skip to step 6.

Position the three resistors in their holes. They can go either way, and I like to put them so I can read their color code from left to right

Arduino Programmer Shield 057

5. LED’s

You may want to skip to step six if you are not installing the LED’s. I position them from top to bottom as Yellow, Red and Green. The yellow LED will blink steadily when connected to the Arduino ISP. The red will get on if an error happens while burning the bootloader and the green will flicker to show that there is communication between the Arduino Uno and the Shield. The LED’s are only used while burning the bootloader.

The LED’s should be installed properly. The long leg should be closer to the resistors. The short leg close to edge of the board.

Arduino Programmer Shield 069

6. Slide switch

If you plan to have two boards, one for burning the bootloader and another for uploading code you may want to dispense with the switch and use a piece of wire instead. For the bootloader solder the left and middle holes together. For the uploader solder the middle and the right holes together. If you decide to use the switch then simply solder it in place. Move it to the left for the bootloader and right for the uploader

Arduino Programmer Shield 070

7. ZIF socket

Now is time to solder the socket. Before placing the socket in the holes examine it carefully. Some of the pins may have bent during transportation. Make sure that all are straight and that all fit into the holes.

Arduino Programmer Shield 071

Take your time and do it right. It is not fun to find that one pin was bent after you started soldering the socket. Arduino Programmer Shield 072

Solder each and every one of the pins. Make sure that there are no short circuits

Arduino Programmer Shield 074

You are done with assembly. Make sure that you cut all the leads and that the board is clean and free of rosin. I use a soft tooth brush with a little dish soap to scrub both surfaces of the board, rinse with water and let it dry on top of a paper towel.

Once the shield is completed and dry it should look like this, mounted on top of the Arduino Uno and with an ATmega328 ready to be programmed

Arduino Programmer Shield 075

Burning the bootloader

I am using the Arduino IDE 1.6.4 and I have not tested this hardware with previous versions. The documentation states that you should use at least Arduino IDE 1.5.

Make sure that the reset switch points to the bootloader position. Load the Arduino ISP sketch from your Examples folder.  This are the first lines of the version I am using

// ArduinoISP version 04m3
// Copyright (c) 2008-2011 Randall Bohn
// If you require a license, see
// http://www.opensource.org/licenses/bsd-license.php
//
// This sketch turns the Arduino into a AVRISP
// using the following arduino pins:
//
// pin name:    not-mega: mega(1280 and 2560)
// slave reset: 10:          53
// MOSI:        11:          51
// MISO:        12:          50
// SCK:         13:          52
//
// Put an LED (with resistor) on the following pins:
// 9: Heartbeat - shows the programmer is running
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave

In the Tools menu select the board: “Arduino/Genuino Uno”, set the proper serial port and set AVR ISP as programmer. Load the sketch into your Arduino before you put the shield on. Once the sketch has been loaded you can put the shield. The yellow led should start blinking slowly.

Now change the board to “Arduino Duomilanove or Diecimilla”. Set the Processor to ATmega328 and change the Programmer to “Arduino as ISP”.

Put a new ATmega328 chip in the ZIF socket and do Tools->Burn Bootloader. After a moment the green led should blink fast for a few seconds and the in your screen you can see the message:

Done burning bootloader

And that is it. You have changed a factory clean ATmega328 into and Arduino processor.

Uploading code

To upload code you need to remove the ATmega328 chip from your Arduino
April 25 024

April 25 025

Now you can use your bootloaded chip to upload any code in the ATmega328 chip. Keep the settings you had for burning the bootloader, that is select the Duomilanove board with the ATmega328 processor and the Arduino as ISP programmer. Upload your sketches in the usual way. When uploaded you can remove the chip from the ZIF socket and use it in your project.

Have fun using the Bootloader/Programmer Shield.

GlowSaber RGB LED assembly

The GlowSaber uses a Vollong 3 watts RGB LED. It is very bright and more than enough to light the length of the blade. When designing the GlowSaber I found that I needed a way to connect the LED to the main PCB and I designed a LED break out
11068412_1603898416534244_4239972562777874584_n

In the picture above you can see the LED as it comes from the factory. In the lower left corner is one mounted in the LED breakout, and to in the lower right corner there is a focusing lens. The later is very important because without it the light will shine mostly to the sides and not enough above the LED.

11203529_1631695973754488_4758279067568345814_o

The LED requires two connections per color, one positive and one negative. In the picture above it shows the breakout on both sides.

11728689_1631696573754428_9203729120447919308_o

This picture shows the LED ready to be inserted in the PVC housing of the GlowSaber. I used a piece of acrylic tubing 1″ outside diameter to protect the LED and the focusing lens and make it easy to mount.

Links:

Vollong 3W RGB LED This is the site of the RGB LED manufacturer

http://Super Bright LEDS And this is the site of the vendor I use to get the LED’s. They also sell the focusing lens

How to use a potentiometer to change the behavior of the GlowSaber

GlowSaber Switch assembly

11999092_1652403508350401_7697716071713430521_n
GlowSaber switch assembly and protection guard

The GlowSaber has a switch assembly, that controls the on/off functions. It also has a LED to show that the GlowSaber is ready to start, and finally has a small 1 kΩ potentiometer. The following is a schematic of the switch assembly:

GlowSaber-switch-assembly-schematic_schem
GlowSaber switch assembly schematic

The connector at the bottom is used with a cable to connect to the GlowSaber main PCB. The pins are, from left to right:

  • gnd: Ground
  • off: This is the input from the battery.
  • on: When the hard switch is closed this routes the input voltage back to the main PCB
  • led: This is connected to a digital output port in the GlowSaber processor. It is turned on when the GlowSaber is ready to start.
  • pgm: This is the output of the center pin of the potentiometer, and is connected to port A0 (analog zero) in the processor.
  • ssw: Soft switch. This is the switch that actually turns the GlowSaber RGB LED and sound on.

The processor inside the GlowSaber is very small and only has about 2 kbytes of memory. The program is loaded from a flash memory and it takes some time to load, usually about 3~4 seconds. Leaving the battery always connected is a bad idea since although in its “Off” state the saber does not use too much power, still it uses some and the battery will be dead after only a few days of storage.

To save battery the GlowSaber design uses two switches, the hard switch in the schematic above, used to load the program and have the saber ready. The soft switch uses a temporary switch to let the processor to turn the lights on or off.

What is a voltage divider

The potentiometer acts as a voltage divider. In the switch assembly there is a Vref voltage coming from the main board. This is used to light the switch assembly LED, to complete the circuit for the Soft Switch and to provide a reference voltage for the potentiometer middle pin.

The understand how a voltage divider works we need some math and physics concepts. The first concept that we need to apply is Ohm’s Law:

The current through a conductor between two points is directly proportional to the potential difference across the two points.

In mathematical terms this can be written as:

Current∝ Voltage

and it is read the Current is proportional to the Voltage (potential difference). To make this principle useful we need to move from a proportion to an equality. To do this we need to introduce a constant of proportionality:

Current ∗ Resistance = Voltage

or as more commonly stated:

Voltage = Current * Resistance

The common symbol for voltage is V, measured in Volts(V), for current is I, measured in Amperes (A) and for resistance is R, measured in Ohms(Ω), and we arrive to the famous Ohm’s Law in mathematical terms:

V = I*R

This expression can be written to compute each of the terms in it:

I = V / R

and

R = V / I

Ohm’s Law help to understand how current is related to potential differential, but does not explain what happens when electricity flows through a resistor. For that we need to introduce the law of energy conservation:

In a closed system (like an electric circuit), no energy is ever lost. The total amount of energy in the system is always the same.

For instance, in a circuit with a light bulb, some energy is released from a battery, moves to the light bulb, lights the bulb filament, and returns to the battery.

Using the law of conservation of energy it can be stated that the sum of changes of potential in a circuit is zero. In the light bulb circuit the battery increases the potential, and the light bulb decreases it,  and, in this case the increase is the same as the decrease.

Let’s consider the following circuit:

Resistors in Series Circuit
Resistors in Series Circuit

It has a 9 Volt battery and two resistors, one of 220Ω and one of 470Ω. According with the conservation of energy law, the increase of potential in the battery is the same as the decrease of potential in the resistors:

Vbattery – Vresistor1 – Vresistor2 = 0

or

Vbattery = Vresistor1 + Vresistor2

To simplify the expression we can write it as

V = V1 + V2

And we can read it as the drop of voltage in the resistor 1 and the resistor 2 is equal to the voltage provided by the battery.

In this circuit the amount of current remains constant as there is only one source of energy and all of it has to pass through the only path in the circuit. The only element that provides energy is the battery. Based on this observation we can rewrite the expression above as:

I*Rtotal = I*R1 + I*R2

I*Rtotal = I*(R1 + R2)

and we can remove I from the expression to get

Rtotal = R1 + R2

This is a very important consequence of the conservation of energy law: the total resistance of circuit with resistors in series (one after the other) is equal to the sum of the individual resistance of all the resistors.

If we measure the difference of potential between points A and C of the circuit we will be measuring the voltage of the battery. But what is the voltage between A and B? And between B and C?

The potential drop between A and B is given by the equation:

V1 = I * R1

since we know that

I = V / Rtotal

we can rewrite V1 to get:

V1 = R1 * (V / Rtotal)

V1 = V * R1/(R1+R2)

To get the potential drop between B and we can use a similar expression:

V2 = R2 * (V / Rtotal)

V2 = V * R2/(R1+R2)

The important thing about V1 and V2 is that the actual value of the resistance is not enough to determine the potential drop. To determine the voltage drop we need to find the ratio of the particular resistance to the total resistance in the circuit.

In the specific circuit above we have a battery voltage of 9V and two resistors, one of 470Ω and one of 220Ω. Thus

R = 470 + 220 = 690Ω

V1 = 9 * 470 / 690 = 6.1304 V (potential drop between A and B)

V2 = 9 * 220/690 = 2.8696V (potential drop between B and C)

V = 6.1304 + 2.8696 = 9V

I = V / R = 9 / 690 = 0.01304A

If both resistors had the same value, then the values for V1 and V2 will be:

R = R1 + R2 = 2R1 or 2R2 (since the value is the same)

V1 = V * R1/2R1 = V/2

V2 = V * R2/2R2 = V/2

And using two identical value resistors we are dividing the voltage exactly in two.

Let’s now consider a more general case:

resistorsInSeries3

V = V1 + V2 + V3

I * R = I * R1 + I * R2 + I * R3

I * R = I * (R1 + R2 + R3)

R = R1 + R2 +R3

Potential drop between A and B

V1 = I * R1 = (V / R ) * R1

V1 = V * R1 / (R1 + R2 + R3)

Drop between B and C

V2 = V * R2 / (R1 + R2 + R3)

Drop between C and D:

V3 = V * R3 / (R1 + R2 + R3)

and we can extrapolate that for a system with n resistors, the voltage drop for one of them will be

Vi = V * Ri / (R1 + R2 + … + Ri + … + Rn)

What is the potential drop between B and D? This involves two resistors, R2 and R3 so the answer is:

VBD = V2 + V3 = V * R2/ Rtotal + V * R3/ Rtotal = V * (R2 + R3) /  Rtotal

And generalizing to resistors in series the voltage drop from resistor i to will be

Vi-n = V * (Ri + … + Rn) / Rtotal

A potentiometer is a voltage divider

resistorsinseries-pot

Consider the diagram of the two circuits above. The resistance with an arrow across is the symbol for a potentiometer. At any given point the slider, represented by the arrow is in a position in between the two extremes. If all the way to the left, then the resistance is zero and no voltage drop happens. If it is all the way to the right then the resistance is 10KΩ and the voltage drop is 9 Volts. Imagine that the slider is somewhere in between, in such a position were there is a resistance of 3.3kΩ to the left and about 6.7kΩ to the right. That is equivalent to the lower circuit in the figure. The voltage drop from B to C is:

VBC = V * 6800/10000 = 6.12 Volts

A potentiometer usually has three terminals, as suggested by its symbol. When connected to a reference Voltage on one of them and to ground on the other, the slider will have a voltage value that ranges from zero (0V) to the reference voltage.

Getting the voltage value in an Arduino board

The Arduino family of processors have several analog input ports, that are in effect a Digital to Analog Converter, that takes a given voltage, compare it to its own reference voltage, and convert the value to a number between 0 to 1023. This is what is called a 10bit DAC.

The following figure shows a potentiometer connected to a ProTrinket 3V3 board. This processor is the heart of the GlowSaber.

pot-with-trinket

This code will read the voltage reported in the port A0 and will communicate the value to the host computer:

#define LS_BATTERY_VOLTAGE A0
void setup() {
 Serial.begin(9600);
 analogReference(DEFAULT);
 pinMode(LS_BATTERY_VOLTAGE, INPUT);
}

void loop() {
 float voltage = 3.3 * analogRead(LS_BATTERY_VOLTAGE) / 1024;
 Serial.print('Voltage now is: '); Serial.println(voltage);
 delay(500);
}

Of course that this is a very trivial example, but based on this very simple circuit and code you can perform very complex operations. In theory you have a value between 0 and 1023 and you can make decisions based on that value. In practice I don’t think that you should use more than 10 different values, and for that you could use the map Arduino function:

void loop() {
  int aValue = analogRead(A0);
  int anotherValue = map(aValue, 0, 1023, 0, 10);
  ...
  switch(anotherValue) {
  case 0:
    doSomething();
    break;
  case 1:
    doSomethingElse();
    break;
  ...
  }
}

OUR CAMPAIGN IS LIVE

Yes, that’s right, we are open for business!

You can check out the campaign HERE

A BIG thank you to everyone who has helped us spread the word so far.

If you’d like to share our Facebook Page, like us HERE

As always, while your donations are important to us, we also appreciate you spreading the news with your friends and followers in all your social networks.

May the 4th be with you!