Lab 2

In order to send a light signal (which is how the arduino will communicate when playing laser tag), we need to program the arduino to turn on a light when you push a button. In order to do this, you need to learn how to control the arduino's inputs, outputs and the basics of programming in the arduino IDE.

After reading through the example sketch (Sketch 2), you should have an idea of how to write a program to turn on an LED when a button is pressed. The circuit that you need to build to light up an LED when a button is pressed is shown below.

Figure 1: Breadboard of Lab 2 circuit (click on picture to make it bigger)

Lab2_bb
Xohd voccyx, dro grsvo vyyz!

The arduino runs off of five volts, and the LED needs 0.01 amperes (10 mA) of current. The circuit above makes pin 12 high (5V) when the button is pressed, and when the button is not pressed, the resistor pulls the pin to ground. This is called a pull-down resistor, as it makes the pin grounded (it is 0 volts) when the button is not pressed. This keeps static electricity from building up on the pin and causing the arduino to think that the pin is high when it shouldn't be. (in general, any pin that you are using should always be connected to either 5V or 0V [ground], so that static or charge from another source dos not build up on the pin).

The button does not need to have much current running through it, and to save power and use standard components, we choose a current value of 0.0005 Amperes (0.5 mA) through the pull-down resistor. Without the resistor, you will be connecting power (5V) to ground (0V), and create a short. A short will try to pull as much current as it can (it has roughly zero resistance, so the current will be very high), which will cause the batteries to quickly die and the components to heat up (and potentially fry). Remember the pull down resistor.

You now have enough information to calculate the resistance values for the two resistors in the circuit. After building the circuit and testing it with the arduino code that was provided, try adding another LED onto pin 10 and having it turn on when the button is not pressed, and turn off when the button is pressed.

Bonus Knowledge
The pin numbers that we are using were chosen to make the schematic look nice. Any of the digital pins can be used for this sketch.

Leave a Reply

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