Lesson 2

In order to tell the arduino how to play laser tag, we need to understand how to give it instructions on what to do. We do this using our computer and a program that allows us to write instructions for the arduino. The purpose of this lesson is to introduce people to the arduino and its integrated development environment (IDE) that is used to program it.

To begin with, you need to tell your computer how to talk to the arduino. To do this, you need to get the correct software running on your computer. Fortunately, there is a tutorial on the arduino website that goes through the steps required to set this up, which you can find here. In addition to the setup, the arduino website has many reference pages and forums that are useful for finding answers to questions and solutions to problems.

So, what can an arduino do? An arduino can interact with the outside world using electricity through its pins (the little pieces of metal sticking out of the microcontroller). It can measure the voltage that is on specific pins and output voltages on other pins. This can be used to read sensors, move a motor, turn on a light, tweet, send an e-mail, or do pretty much anything that you can have done by turning on a switch, or pushing a button. But in order to communicate to the arduino without breaking it, there are some things that we need to be aware of.

First, the arduino can only supply 0.03 Amperes (30 mA) of current from any pin. That means that if whatever circuit is attached to a pin tries to draw more than 0.03 Amperes (30 mA) of current, the arduino will eventually overheat and break. It could break that pin or the entire board. This is why you learned Ohm's law. Every circuit that is turned on by the arduino can not draw more than 0.03 Amperes (30 mA) of current, or it will damage the arduino. In addition, the arduino uses a specific voltage, five volts. We will be using the arduino's digital inputs. Digital, or discreet inputs, are like counting numbers. They can only take on certain values, like 1, 2, 3, 4, etc.
For the arduino, it can only count to one. When it reads a voltage, the voltage is read as either 0 or 1. Since the arduino likes using five volts, we will give it a five volt signal. The arduino will think that any signal that it reads on one of its pins that is five volts is a one (or that the voltage is set to high). If the arduino does not sense five volts, it will think that the pin is a 0 (or that the voltage is set to low).

So, now that we know the basics of electricity, we need to learn the basics of programming the arduino. In the arduino IDE (programming environment), a file is called a sketch, and I wrote an example sketch called first sketch to go over the basics of the arduino IDE. Read it. It goes over basic coding practices and tips for writing code.

After reading the example sketch, which you can find here, you can complete Lab 1.
Now go build something.

Note: The brains of the arduino is a microchip called the ATmega328p. Atmel, the company that produces the ATmega328p has a naming convention for their chips. It starts with AT, which stands for the company Atmel. This chip is part of the mega family, which as 32 or more pins, has 32 kilobytes of program memory (which is why 32 is in the name), it has 8 kilobytes of flash memory (which is why there's an 8 at the end), and it is the low power chip (p). Put all of those features together, and you get the ATmega328p. This naming convention lets you compare chips simply by looking at their names. For more information, the Atmel naming convention for these chips is here.

2 thoughts on “Lesson 2

  1. Hi, I am using an ATmega 128 to try to send information through a 940nm wavelength LED to an IR receiver, I believe you are using a similar system for your laser tag lab.

    I was wondering, are you using a RTZ line of code or a NRZ with your light communication? I am curious because the RTZ will effectively cut your bitrate in half, unless you are using an inverted RTZ (RZI).

    I am also wondering if the bitrate for this setup is based on the carrier frequency (38KHz)? If it is based on this but is not actually the carrier frequency, how do you solve for bitrate? Thanks!

    • Indeed, I am using a 940nm LED to an IR receiver. I have chosen to use a Return to Zero (RTZ) line of code instead of NRZ (non return to zero). The IR communication that I am mimicking used RTZ, and it allows me to isolate each bit that I send. This makes it easier for me to debug individual bits, which is helpful because I'm using a 16MHz resonator for my clock signal, and it is not as precise as using a 16HHz crystal oscillator. My timing is not as precise, but the resonator is cheaper and and easier to isntal. I also am not doing high speed communications, so I don't care about increasing my bitrate over debugging capability. I don't use inverted RTZ (RZI).

      I am planning on sending 4-8 bit packets. I have a start and stop signal that I also send, so the bitrate would be based on the sum of the time it takes to transmit all of those pieces (start, bits, end). I'll let you make your own assumptions of whether the bits I'm sending are evenly distributed between 0's and 1's. Hope that helps.

Leave a Reply

Your email address will not be published. Required fields are marked *