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

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

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.

Application

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:

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.

Apr 01

Open Source Microcontroller Development

uCtools is an open source collection of microprocessor programming tools. So far they support development for AVR, ARM, MSP430, STM32L1xx and are developing tools for others. If I need to develop firmware for embedded systems, this will be a handy tool to have at my disposal. For now, the arduino IDE seems like the best choice for teaching, since it is simple to use and understand. But who knows? Maybe something else will be better. You don't know unless you explore the possibilities.

Mar 27

Lesson Planning

I ran across the idea of recording my lessons via iPad using this tutorial (I probably want to have objects to demonstrate with, so I may want to not use an iPad). I was inspired by Salman Khan of Khan Academy (great article here about him). I can create the non-linear curriculum that I want by making the lessons cover everything that you need to know while putting links in the video to point people who want to learn more to more things (hence non-linear learning. There are many branches that you can go down in addition to learning the core material).

The whole point of non-linear learning is to capture the moment of inspiration, that time when someone is genuinely interested in a subject and wants to learn more. It is at that moment that I want to present the possibility of diving into extra material that goes above and beyond what is necessary to understand what I want people to learn. I've always wanted a course that gave me the opportunity to learn more than was necessary and explore things that I found interesting, and now I can create that for other people.

Mar 15

Bitlash: Arduino interpreter language shell

I love having a shell. When I want to know what a single line of code will do, I don't want to add print statements to code just to see what's going to happen. Bitlash is an arduino interpreter, so you can send individual commands to your arduino. I haven't used it yet, but once I get back into arduino development, it will be on my to learn list. It may be helpful for students to be able to run individual lines of code. Or I'll just have them write extensive test benches to test their code. Maybe both?

Mar 12

Do I ask you what you want?

I cam across an article today in the helpscout blog (article). It is about Steve Jobs' quote, "It's really hard to design products by focus groups. A lot of times, people don't know what they want until you show it to them." Part of me agrees with this, because I'm trying to design a curriculum for electronics, and I really can't ask fourteen-year-olds what they want to learn about electronics. They would probably tell me that they'd like to make an iPhone, which is way beyond their (and my) scope. They would probably never think that they could make laser tag, which is what I'm trying to show that they can learn. The problem is, they don't know what could exist (or at least, most don't).

If you don't know that something is possible, how can you ask someone to make it for you? That is the essence of Jobs' quote. You don't know if people will like something innovative, something that they haven't thought of, unless you can find out what they want without asking them. The article sites an article about customer feedback, which points out that people are notoriously bad at telling you what they want.

Why should we care? It means that while people can tell you what they want, it is unlikely. If you want to create a new curriculum to promote electronics education by making a fun, engaging and open source set of classes to teach the fundamentals of electronics, computer science and embedded systems (as I do), then you may not be able to just ask a teenager what they want to learn about electronics. Because they won't tell you. I have to learn everything that I can about teaching, get help from the teachers I adored and mimic their teaching styles, generate a set of lectures and labs to demonstrate the principles required to make laser-tag and then test this, refine it, test again.

At the same time, this also has to be taken with a grain of salt. After all, this was Steve Jobs. He was a particular person in a unique industry. Getting feedback on what is working is different then feedback on how to generate something entirely different. And sometimes innovation does come from getting feedback. It can work. This all points to getting feedback from my curriculum and taking it not as dogma, but as a suggestion from a person, because that's what it is. It is information that another person, with all their knowledge, experience and biases, telling me what their mind has computed. It could prove to be useful. Or not. And how will we ever know if we don't try?

Here's an interesting article on customer feedback information. You know, for those who want more.