# Part One: Theory

Sometimes you need an easy way to identify resistors laying around your workbench. Of course you can get a very inexpensive multi-meter for the task, but when you have to classify several dozen resistors you wondered if there is a better way of doing it.

When I am working on a new project, either with a breadboard or a new board to solder many times I need to fast identify a resistor and with the small 1/8 watt with five color bands I usually have a problem reading the value, as my sight is not what it use to be. I thought that it was a good idea to design an auto-ranging ohmmeter using an Arduino compatible processor. This project has several goals

1. It should have an easy way to connect the resistor to the meter, without probe cables. Using an integrated circuit socket with round holes is a convenient way to insert the leads of the resistor and measure it.
2. It will show a practical use of Ohm’s law and voltage dividers
3. It will show how to use an Arduino to properly interpret the voltage in terms of resistance
4. It will show a practical approach of using transistors as gates, as well of using a processor to turn the gates on or off.
5. My good friends of PCBWay  offered an opportunity to develop this project and provide the prototype printed circuit board.

Here is the message from Simon@pcbway.com

Hello,

Deeply impressed by the words on your website.

Just wanted to check if you would accept our support for your blog and projects, and we are willing to send you PCBs free of charge for getting a review blog from you, or just mention our service in your project posts. How does that sound to you ?

Best Regards

2018-07-10

Simon Gao

PCBWay – Cherish every designer’s inspiration.

## Organization of this blog

There is a lot of material that needs to be covered in this blog. You don’t need to understand all the physics or the math to build this project, but the idea is to show not only how, but why it works.

The blog is divided in three parts:

1. Theory behind an auto-range ohmmeter.
2. Circuit Schematic and PCB design
3. Building the auto-range ohmmeter

## Arduino programming

This blog is about how to make an auto ranged ohmmeter and will explore concepts of the Ohm’s Law and the law of conservation of energy. It will also explain how to lay out a circuit that performs the task. This tutorial is not intended to be an introduction to Arduino programming or to the Arduino microprocessor. If you need to learn more about these topics please refer to the official Arduino site: Arduino.cc

## Ohm’s Law

Ohm’s law is the fundamental principle in an electric circuit. It is very simple and can be stated as this:

The current through a conductor between two points is directly proportional to the voltage across the two points

Current is defined as the amount of electric charge that passes through a conductor in a given amount of time. The current is measured in amperes. It is usually identified with a capital letter I.

Voltage is the difference in electric potential between two points or in other words how much more electricity is in one point compared with the other. It is identified with the capital letter V.

How to express Ohm’s Law in mathematical terms? Like this:

`V ∝ I`

To make ohm’s law useful in calculations we need to add a term to the expression above to replace the proportional sign  for an equal sign

`V = I · R`

The new term R is called a proportionality constant, and in terms of an electric circuit is called Resistance. It is measured in Ohm’s, in honor of the German physicist that discovered it in the early XIX century. The word ohm for the unit is usually represented with the Greek letter omega: Ω

One ohm is defined as the resistance one conductor must have to allow one ampere to pass through a circuit with a differential of electric potential of one volt.

Once the equation is established we can manipulate it to express any quantity in terms of the other two:

```V = I · R
I = V / R
R = V / I```

The following circuit will show all this relations:

In the circuit above we can identify the two basic components of an electric circuit:

• A source of energy, in this case a battery. The voltage raises from the negative terminal to the positive
• A consumer of energy, in this circuit a resistor. The voltage drops from the top of the resistor to the bottom.

The wires that connect components also show some resistance, and in some case it is big enough to include it in the calculations. For the moment we will think of the wires as perfect conductors with zero resistance.

Any electrical circuit can be simplified to a source of energy and a consumer of the energy.

### Conservation of energy

An electric battery creates a differential of potential between its terminals. The positive terminal has a higher level of energy than the negative terminal. While the terminals are not connected there is no transfer of energy. The system is stable.

Once the terminals are connected, as in the circuit above, then electricity flows from the positive terminal to the negative one, passing the resistor.

The top (positive) terminal of the battery is connected to the top terminal of the resistor. The differential of potential between the two terminals is zero, as they are at the same level

The lower (negative) terminal of the battery is connected to the lower terminal of the resistor. The differential of potential between the two terminals is zero, as they are at the same level.

What happens is that the voltage drops through the resistor all the differential of potential of the battery. This can be expressed in the law of conservation of energy:

The algebraic sum of the voltages (drops or rises) encountered in traversing any loop of a circuit in a specified direction must be zero.

The amount of current that passes through the resistor is given by Ohm’s Law:

`I = V / R`

If instead of one resistor there are several then the drop of voltage is spread among the resistors in the circuit. Consider this circuit with two resistors:

The drop of voltage between the top of R1 and the bottom of R2 is V.  And the amount of current I in the circuit is the same as there is only one way in which the current can flow. But what happens in each of the resistors? Let’s find out.

The total amount of current in the circuit is I, and the individual drop of voltage in each resistor is:

`V1 = I * R1`

and

`V2 = I * R2`

The total voltage drop is of course

`V = V1 + V2`

And if we replace V, V1 and V2 for its equivalent in terms of I and R we have

`I * R = I * R1 + I * R2`

and simplifying the equation

`R = R1 + R2`

And this leads to an important conclusion:

In an electrical circuit with resistors in series (one after the other), the equivalent resistance or total resistance is the sum of the individual resistances.

The following links will give you more information about Ohm’s law, and the physicists whose names were used to name the units for current, potential differential and resistance:

• Ohm’s law. In this article you can see a formal definition of the law
• André-Marie Ampère. Ampère was a French physicist and founder of classic electromagnetism
• Alessandro Volta. Volta was an Italian physicist, credited as the inventor of the electric battery
• Georg Ohm. Georg Ohm, a German physicist, was the first to formulate this seminal law in the early XIX century

## Voltage Divider

In the last section we found a way to compute the total resistance of a circuit with resistors in series. But why would we want to have resistors in series? Because using the resistors in series we can set any voltage value, in between the resistors terminals. Consider this circuit:

We know that the voltage between terminal 1 and terminal 3 is exactly V. But what is the voltage between terminals 1 and 2, and between terminals 2 and 3?

In the last section we saw that the voltage drop because of resistor R1 is V1 and its value is

`V1 = I * R1`

Since we know the value of I we can express V1 in terms of the total voltage and the resistors:

```I = V / Rt
I = V / (R1 + R2)
V1 = I * R1 = V / (R1 + R2) * R1
V1 = (V * R1) / (R1 + R2)```

We can find the value of V in a similar way

```V2 = I * R2
V2 = V / (R1 + R2) * R2
V2 = V * R2 / (R1 + R2)```

### Numerical examples.

Let’s say that our battery is a 9V battery and that R1 = 100Ω and R2 = 200Ω. What are the values of V1 and V2?

```V1 = 9 * 100 / (100 + 200) = 900/300 = 3V
V2 = 9 * 200 / (100 + 200) = 1800/300 = 6V```

What happens if R1 = R2 = 100Ω?

```V1 = 9 * 100 / (100 + 100) = 900 / 200 = 4.5V
V2 = 9 * 100 / (100 + 100) = 900 / 200 = 4.5V```

As in the Ohm’s law, we can use the formula of the voltage divider to find the value of an unknown resistor. Let’s assume that we know V, V2 and R2, what is the value of R1?

```V2 = V * R2 / (R1 + R2)
(R1 + R2) = R2 * V /  V2
R1 = (R2 * V /  V2)  - R2
R1 = R2 *  (V / V2 - 1)```

Let’s say that V = 9V and V2 = 3V and R2 = 200Ω, what is the value of R1?

`R1 = 200 * (9/3 - 1) = 200 * (3 - 1) = 200 * 2 = 400Ω`

To build an ohmmeter, a device that measures the resistance, we only need a source of constant voltage, a way to measure the voltage between terminals 2 and 3 of the Circuit 3 above and a know resistor R2.

In the following sections we will see how we can use an Arduino microprocessor to measure the voltage and how to convert an Arduino into an auto ranged ohmmeter.

How to create and experiment with electronic circuits without physically building them? One way is using a simulator. Tinkercad is a web site powered by Autodesk that allows the creation of three dimensional solids and simulates electronic circuits. You can visit the site following this link: http://www.tinkercad.com

The site is free but you need to sign up in order to create electronic circuits. Once you have access to the site you will find in the left navigator the button that opens the circuit simulator

There are several simulations that are used through this blog. For each of them I will add the link to the project in Tinkercad as well as an embedded simulation of it. The embedded simulation will allow you to run the simulation inside this blog, but it has the disadvantage of being small and cannot change the values of the electronic components. Follow the link to the project if you want to explore it with more detail.

## Measuring Voltage

One of the features that made the Arduino microprocessor so popular is the ability to do an analog to digital conversion. Arduino features six pins that are dubbed “Analog Ports” that do a 10 bit analog to digital conversion. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.

When you combine the ability to read a voltage with a voltage divider you have the making of a resistance meter or ohm meter. A very simple approach is the following circuit where we setup a voltage divider using two 1KΩ resistors. You can play with the circuit and the resistance values in my Tinkercad project:

You can click on the “code” tab in the embedded simulation to find the Arduino code that computes the value of R1. However most of the code is devoted to display the value in the LCD screen. The following are the code lines where the value of the resistor value is computed

```...
float r2 = 1000.0;
...
...
float voltage = (value * 5.0)/ 1023.0;
...
float r1 = r2 * ((5 / voltage) - 1);
...
```

If you click the code tab in the simulation above you will be able to find this lines of code.
This code will report the value read in A0 (511) and convert it to a voltage (2.5V). The results will be sent to the console using Serial.

If you are not a member of Tinkercad this is a good opportunity to become one. You will be able to copy the designs in this blog and play with them. The designs come together with the Arduino code and you can also inspect it and modify it.

### Measuring a resistor

We can modify the code in the Arduino to compute the value of a resistor by using the formula:

`R2 = R1 * (V / V2 - 1)`

And this is the code

```void setup() {
Serial.begin(9600);
delay(500);
}

float oldValue = -1000;
float r2 = 1000;

void loop() {
if (oldValue != value) {
float voltage = (value * 5.0)/ 1023.0;
float r1 = r2 * ((5 / voltage) - 1);
Serial.print("Value: "); Serial.println(value);
Serial.print("Voltage: "); Serial.println(voltage);
Serial.print("R1: "); Serial.println(r1);
oldValue = value;
}
delay(500);
}```

This code is very similar to the previous one with two main differences. We included the value of R2 before the loop function. The program computes the value of R1. If you change R1 in the circuit the program will report its new value.

Try running the simulation and stop it and change the value of R1. What happens to the output in the serial port?

### A good value for R2

In the first paragraph of this log we discussed that the minimum voltage that can be measured with the Arduino, using a 5V reference is 0.0049 volts. Using

```Vin = 5Volts
Vout = 0.0049Volts
R2 = 1000 Ohms```

The value for R1 is

```R1 = R2 * (Vin/Vout - 1)
R1 = 1000 * (5/0.0049 - 1)
R1 = 1000 * (1020.4 - 1) = 1000 * 1019.4 = 1019408```

Using an R2 value of 1KΩ the maximum value of a resistance that can be identified would be about 1MΩ and the minimum of about 1Ω. It seems to be a good value to choose. And in theory it can be, however since the smallest voltage difference that can be detected is 0.0049, for some values the increment from one resistance to the next can be too big. For instance, when getting closer to 1MΩ a small increment in voltage represent a huge increment in resistance. For instance for

```Vout = 0.0098, R1 = 511KΩ
Vout = 0.0146, R1 = 340KΩ```

This means that a resistance of 400KΩ cannot be distinguished from an either 340KΩ or 511KΩ.

Another problem lies in the precision of floating point operations in an Arduino. Although the values can be computed with great precision using Excel or other spreadsheet software, that is not true for Arduino where the floating point values are stored in 32 bits and have 6 to 7 digits precision.

Instead of using one value for R2, it will be better to use several, to account for all the possible value ranges that are common with resistors. Using five different values it is possible to measure resistances from 0.1Ω all the way up to 100MΩ.

## Values for R2

R2R1 minR1 max
100101,000
1,00010010,000
10,0001,000100,000
100,00010,0001,000,000
1,000,000100,00010,000,000
Different values for R2 to optimize the range of values for R1

### Minimum value of R1

Although it is not required, it is a good idea to add a small resistance value to the circuit, just to limit the amount of current that can go into the Arduino. A 100Ω is a good selection. This implies that the R1 the circuit will measure will be 100Ω plus the value of the unknown resistance. Once the value of R1 is computed we only need to subtract 100 to get the unknown value result. Consider next circuit:

The battery produces 9V, we have an intermediate resistor of 100Ω, then an unknow resistor and finally a 1,000Ω resistor. A voltmeter measures the voltage between terminals 2 and 3 to be 3.451V. What is the value of the unknown resistor?

```Vin = 9V
Vout = 3.461V
R2 = 1000Ω
R1 = R2 (Vin/Vout - 1) - 100
R1 = 1000 * (9/3.461 - 1) - 100
R1 = 1000 * (2.6 - 1) - 100
R1 = 1000 * 1.6 - 100
R1 = 1600 - 100 = 1500
R1 = 1500Ω```

This resistor is used to protect the battery and the measuring device, in this case an Arduino microprocessor by limiting the amount of current that will go in the circuit. Even if the unknown resistor is very small, like zero, the amount of current is limited to

```I = V / R
I = 9 / 100
I = 0.09amp```

### Arranging multiple resistors to find the best value

In the following circuit there are five known resistors with a switch before each of them. When all of the switches are open, there is no voltage divider and the voltage between terminals is exactly V.

But when one of the circuits is closed, then the voltage divider circuit is complete and the voltage between terminals changes according of the values of R2.

For instance if S1 is closed then the voltage divider will be completed with the unknown resistor and the 100Ω resistor.

The image above is the rendition in Tinkercad of the schematic. The red array of switches has all the switches in the off position. The voltage is 9V, the same as the battery.

When the switch 1 is closed, the voltage divider with the 100Ω resistor is established and the voltage changes.

If you open switch 1 and close switch 2 then the value of the voltage is different.

Run the simulation and you will find out that the values of the output voltage are the ones in the following table:

Switch ClosedResistor valueOutput VoltageUnkown Resistor Value
NoneNone9VUnkown
S1100Ω0.817V1001.59
S21KΩ4.5V1000.00
S310KΩ8.18V1002.44
S4100KΩ8.91V1010.10
S51MΩ8.99V1112.35

It is clear that although all values of R2 gave us an idea of the value of R1, there is one that is better that the others, in this case R2 = 1KΩ. Since R1 is relatively small compared with 100KΩ or 1MΩ, the limitation in the voltmeter precision yields poor values. How to choose the better value for R2? The better value of R2 for any given resistor is the one that provides an output voltage closer to 1/2V.

Try playing with the model in Tinkercad. Change the value of R1 and see wich value of R2 is better

### Using transistors as switches.

A transistor is a sandwich of two classes of semi-conductor material. How a transistor works is beyond this blog, and you can find excellent sources just Googling “How a transistor works“.

For our project we will be using generic NPN transistors. The diagram for this device will help to understand how it works:

When the enable signal is zero, no current passes from the more positive to the more negative. In effect the circuit is open.

When a positive current is applied to the enable signal the current in the more positive side flows to the more negative side. This closes the circuit.

The following diagram shows how to use a transistor with the voltage divider.  We will connect the enable signal pin to the Arduino processor to enable and disable the reading of the voltage. As we are using five different values for R2 we will need five connections to the Arduino. We will test each value and the software will select the best value.

### Using an Arduino to select the value of R2

The only concept we need to add to our design is to be able to select the value of R2, and thus compute the better value for R1 using a micro processor, like Arduino. Instead of the switches we use in the last section we are going to use the ability of an Arduino to change the value of a pin, to turn on or off a transistor circuit. A basic transistor circuit looks like this

In this configuration the program in the Arduino tries to find the best value for R2 and with it the value of R1. Each transistor is connected to a digital output in the Arduino. When the output is set to HIGH then the corresponding transistor closes the circuit and a voltage value is read in the analog port 0. The program tries each transistor and uses the value of R2 that yields a voltage closest to 512.

The code in the sketch above includes the management of the LCD display. The core of the functionality is this:

```void loop()
{
int r2Index = 0;
int minDiff = 1000;
int bestValue = 0;

for (int index = 0; index < 5; index += 1) {
int pin = index + 3;
digitalWrite(pin, HIGH);
delay(100);
delay(100);
digitalWrite(pin, LOW);
int diff = abs(value - 512);
if (diff < minDiff) {
r2Index = index;
minDiff = diff;
bestValue = value;
}
}

float vout = (bestValue * vin) / 1023;
float r2 = r2values[r2Index];
float r1 = round(((vin / vout) - 1.0) * r2) - 100.0;

clearLine(0);
printLabelValue("Value: ", bestValue);
clearLine(1);
printLabelValue("R1   : ", r1);
delay(5000);
}```

### Arduino and transistors schematic

This is the configuration of the Arduino used as an auto range ohmmeter using transistors to select the best value for R2. Notice that each transistor is connected to a digital port on the Arduino. In this schematic the LCD display is not included because it add complexity that is not needed for the basic circuit.

### End of theory

This is the end of this blog on how it works. In the next one we will design the schematic and the printed circuit board. Stay tuned

## 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:

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:

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.

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.

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.
2. (1) 470Ω 1/4 watt resistor and (1) 220Ω 1/4 watt resistor
3. (4) 22Ω 1 watt resistors
4. (2) 100 μ farad capacitors
5. (1) LM7805 5 Volt regulator
6. (1) ULN2003A  7-Darlington Transistor
7. (1) Adafruit Triple-Axis Accelerometer – ±2/4/8g @ 14-bit – MMA8451 PID: 2019
8. (1) Adafruit Pro Trinket – 3V 12MHz PID: 2010
9. (2) Eight right angle male header connectors.

## 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.

### 2. LED and speaker resistors

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

### 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.

### 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 other

### 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 picture

### 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.

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 top

### 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.

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

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.

## 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:

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:

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

All the pieces together:

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:

## 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

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:

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:

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.

## 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.

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:

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:

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:

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.

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.

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

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:

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.

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.

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

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.

## 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.

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:

Push the headers all the way down

and the put the shield on top of the Arduino board

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

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

### 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.

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

### 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

### 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.

### 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

### 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.

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

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

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

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
//
// 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:

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

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

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

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.

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

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.

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

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:

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:

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:

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

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.

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 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!