Jun 23

Lab 3

We are going to add an infrared (IR) LED and an infrared receiver to the arduino. We already know how to add an LED, and we have chosen to put it on pin 10. The new part is the infrared receiver. This outputs whether or not it sees an infrared signal turning on and off 38,000 times a second. We need to give this sensor power, ground, and connect its output wire to our arduino so that our arduino can sense the signal (high or low voltage) that the infrared sensor gives as an output. Below is a circuit diagram of what we need to add.

Figure 1: Picture of connections. (Click on the picture to make it bigger).

Note: I couldn't find an IR sensor in the software I use to draw circuits, so my IR sensor doesn't look exaclty like an IR sensor.

So, now that we have a red LED, infrared LED, infrared sensor and button, how do we want to program them? So, for laser tag, we want to push a button and send a signal out of our infrared LED (to send a tag). When we receive a tag on our infrared receiver, we want to indicate that we have been tagged with our red LED. So, we need to modify our code to follow those instructions.

We are going to use other people's code to make building laser tag easier. We call other people's code libraries. It is sort of like checking out a book at the library, only you are checking out other people's code and using it in your own code.

The first library that we are going to use will turn on and off our infrared LED 38,000 times a second. That library is called TimerOne. You can download the library here (note, download the file TimerOne-r11.zip for the latest version) and read about how it works with the TimerOne Tutorial (the tutorial on how it works is very advanced. I can go over it later if you would like. You do not need to know the details on how it works to use it properly).

Once you have the file downloaded, you need to tell the arduino programming software where the library is so that you can use it in your code. The arduino software has a folder where it stores all of the libraries it knows about. To move the library to a place where the arduino software can find it, you can follow the tutorials from either the arduino library installation or the sparkfun library tutorial. Once you have the TimerOne library installed, it's time to modify the code to make a rudimentary laser tag unit. To the code!

Jun 22

Lesson 3

We are going to use infrared light (the same kind TV remote controls use) to communicate between two arduinos so that they can play laser tag. This lesson goes over how to do that.

Now that you can get your arduino to respond to a button press, the next thing to do is make it send a signal using infrared light when you push a button. We need an emitter (an infrared LED to create the light) and a receiver to sense the light. We already know how to light up an LED, and if we use an LED that emits Infrared light, then the emitter is done.

So, if we wanted in infrared receiver, how would we build one? We could make one that turns on when it sees infrared light(remember, the arduino only communicates with voltage. When the receiver sends a signal saying that it sees something, it will do that by changing the voltage on one of its pins). However, there are a lot of sources of infrared light naturally. The sun, your body, fire - anything that gives off heat also emits infrared light. So, how can we make sure that the infrared light that our detector sees is coming from our infrared LED?

Well, the people who made the receiver made it only respond to infrared light that blinks. Really fast. For the receiver we will use, whenever the receiver gets hit with 38,000 pulses of light per second, then the receiver will say that it is seeing our infrared LED (and one of its pins will change from high to low voltage). Since our arduino can make the LED blink really fast (to create an output for the receiver), and our arduino can read high or low voltage from the receiver, our arduino can use the infrared LED and receiver to communicate. So voila! A way to take an infrared signal and make it control the arduino.

So, now that we have an idea of what we want to do, how do we do it? We're going to need to write a piece of code that pulses an LED on and off 38,000 times a second. We will also have to have the arduino check the infrared receiver to see if the infrared receiver is receiving the pulsed infrared light. This is the basics of communicating between arduinos. So let's build it. To the Lab!

Bonus Knowledge

The infrared reciever we will use is active low. That means when it activates [sees a infrared signal pulsing 38,000 times a second], it makes its output pin low. Why does it make the pin low and not high when it senses a signal? That has to do with power consumption, industry standards, etc. We won't go into that. If you really want to know, ask me. I'll be glad to try to answer.

There is a lovely tutorial at adafruit that goes into how to use IR (infrared) sensors, which you can find here if you want more information. For now, it's on to the circuit diagram and the code. (well commented, of course!).