Apr 09

Lesson 1

In order to tell your arduino how to play laser tag, you are going to need to know how it talks. Arduino's talk using electricity. The purpose of this lesson is to teach the basics of electricity that you will need to build laser tag.

Why learn this?

Two main reasons:

1. Computers communicate using electricity. More specifically, they only understand one thing: whether electricity is present or not. That's it. If we want to talk to our computer, or have it talk to other computers, we are going to have to talk to it in the language it understands (electricity). So, we need to know a little bit about how electricity works in order to talk to the arduino and have the arduino's talk to each other. Arduino's talking to each other is the basis of laser tag.
2. Too much electricity will break the arduino. You need to know how electricity works to keep your arduino from overheating, melting and breaking.


Electricity is tiny particles called electrons that flow through material. It flows more easily in some materials than others. We will be using metal wires to build circuits (more on circuits later), since electrons flow easily through metals (but not as easily through the insulation around the wire, so the electricity won't accidentally flow through something else). There are three factors that determine how much electricity flows through a circuit: voltage, current and resistance.

Voltage measures of how much one thing wants electricity compared to another thing. The higher the voltage, the more the electrons want to flow. One of the best visualizations I know of for electricity is water flowing through pipes. If you imagine a bucket with a pipe in it, the electrons are the water in the bucket. When you lift the bucket off of the ground, water flows out of the pipe. The higher you lift the bucket, more water will come out of the pipe. Similarly, the higher the voltage, the more the electrons want to flow through the circuit (higher electric potential).

Voltage is important because voltage is the only thing that the arduino can understand. The arduino can sense whether voltage is present or not. If you know what the voltage is (or what you want it to be), you can use that knowledge to tell the arduino what to do. Voltage is usually supplied by a battery, and in our case, we are going to regulate the voltage so that we are always working with a voltage that the arduino likes. Voltage is measured in volts, which is represented by the letter V. The voltage that the arduino likes (and that we will use) is 5 Volts, or 5 V.

Current is how many electrons are flowing through a circuit. Going back to the pipe example, current is how much water is flowing through the pipes. Current is important because as electricity flows through something, it heats up. If you have too much current flowing through your arduino, it will overheat, melt and break. Current is measured in amperes. Different electrical devices require different amounts of current, but mostly, our arduino will only want a little bit of current, like 0.02 Amperes, or 0.02 A.

Resistance is how hard it is for electrons to flow through a material. In the pipe example, resistance is how big the pipes are. If you have a really small pipe (or put a kink in the pipe), then less water will flow through the pipe. Resistance is measured in Ohms and is represented by the letter R, and the symbol that represents resistance is the ohm, Ω.

So, putting it all together with the water bucket example. Voltage is how much electricity wants to flow. We can think of that as how high a bucket of water is lifted off of the ground. We will always use a voltage that the arduino likes, which is 5 Volts. Current is how much water flows through a pipe attached to the bottom of the bucket. If there is too much current, your arduino will heat up, melt and break. Resistance is how big the pipe is, which restricts the water and keeps too much from flowing through the pipes. We can put 'kinks' in the pipe to keep too much electricity from flowing through our circuit.

So, how does voltage, current and resistance relate to one another? Georg Ohm figured this out in 1827 and published a paper about it. He called the equation Ohm's Law (he got to name a law of physics after himself because he discovered it), and it states that

 \frac{Voltage}{Current} = Resistance

This means that the voltage through a circuit is equal to the current times the resistance (note, Ohm wrote his equation to read V = IR. V is Voltage, I is current, R is resistance).

That's all the theory that we need to know for laser tag. If you understand electricity, you will be able to keep your arduino happy and control all of the lights, buttons, etc. that we attach to it.


So how do we use Ohm's Law to do useful stuff? The first thing that we are going to do is turn on a light. Light bulbs convert electricity into light. The type of light bulb that we are going to use is called a light emitting diode, or LED for short. An LED is a diode that emits light when electricity flows through it. A diode only lets electricity flow through it in one direction.

We already know that the arduino likes 5 volts, and that we will always set our voltage to 5 volts in laser tag. That means the only two things left to figure out is how much current and resistance we should have to light up our LED. Since current is the thing that damages electronics, we want to make sure there isn't too much flowing through the LED. We can limit the current by putting a resistor in the circuit. Adding a resistor is like adding a kink in the pipe, it keeps electricity from flowing too fast. We will use resistors to limit how much current flows through our circuits and protect our components.

Our LED's are happy with up to about 0.01 amperes of current flowing through them. So what resistance should we use? Looking back at Ohm's law, we know that $latex \frac{Voltage}{Current} = Resistance $ or, written the other way, $latex Resistance = \frac{Voltage}{Current} $. Plugging in that the voltage is 5 and the current is 0.02 (and using a calculator) we learn that:

Resistance = \frac{Voltage}{Current} = \frac{5 Volts}{0.01 Amps} = 500 Ohms

Quick note on resistors. People don't build resistors at exactly the resistance you want. For example, I have a 220 Ohm resistor and a 680 Ohm resistor. If I use a larger resistor, my LED will still work (even though it is bigger than the 500 Ohms of resistance I need). What I don't want to do is use a smaller resistor, which will then have more electricity flow than I want. In this case, we will use a 680 Ohm resistor.

So, how do I use this knowledge to build a circuit? What we need to do is build a path for the electricity to take. It should go through our LED and through our resistor. It doesn't matter which order. If we are using a battery, we need to connect the positive end of the LED to the positive end of the battery, the negative end of the LED to the resistor, and the other side of the resistor to the negative end of the battery. That will make a complete circuit. A complete circuit is a circuit that has a path for the electricity to take from positive voltage to zero voltage (in the bucket example, there is a pipe from the bucket to the ground for water to flow). If we are using a battery, electricity will only flow out of the battery if there is a path from the positive end of the battery to the negative end.

Quick note: electricity will flow through the path of least resistance. When you connect components, make sure that the electricity has to go from positive voltage, through the thing you want to power, through a resistor, and then gets to ground.

But we don't want to have it constantly be on, right? What a waste of energy. Why not put in a button? A button is a momentary switch: it is on (electrically connected) when you push it down and off (electrically disconnected) when you do not push it. To use a button, you put the button in between the battery and the LED. This way, electricity will only flow when you push the button.

Now we need to put all this together and electrically connect it. That's where the breadboard comes in. This is a board with little metal pieces that pinch wires that you put into the holes. This makes it easy to connect wires together. Lab 0 has a little mini-lesson on how to use a breadboard and how to draw your circuit so that other people can make the same thing.

That's everything you need to know to complete lab 0. Now go build something.

Bonus Knowledge
You don't need to know the following to build laser tag. This is extra knowledge if you want to learn more.

Note on units: as you recall, the current that we need to use for the LED is really small (0.02 A). We can use the SI (international system of units) to represent that number as 20 mA (you divide 0.020 A by 1000 to get 20 milliamps, or mA). The SI system has a number of prefixes that you can put in front of the standard unit (in this case, amperes or A), to represent a multiple of ten of that unit. Milli or m, stands for  10^{-3} or \frac{1}{1000} of that unit. If we use mA for current, we have multiplied the current part of Ohm's law ( \frac{Voltage}{Current} = Resistance) by \frac{1}{1000}, so we need to multiply it by 1000 in order to make sure that everything is still equal. The letter k is the SI prefix for 1000, so we can make the equation still hold true by using k Ω for the units of resistance.
If this doesn't make sense to you, don't worry.

I can post more on unit conversions at a later time, since it isn't important for understanding the concepts.