Category Archives: Arduino

ARDUINO LESSON 28: Tutorial For Programming Software Interrupts

In this lesson we will show you how to take your arduino programs to the next level by learning to program software interrupts. The challenge with the Arduino platform is that you can only have one program or “thread” running at a time. Hence, something simple like blinking two LED’s at the same time at different rates can not be done because only one line of code is executed at a time. Much more powerful projects can be achieved if we learn how to get around this by programming interrupts. An interrupt can be thought of like an alarm clock. You set the alarm clock, and then when the alarm goes off, no matter where your program is in the execution code, it stops what it is doing, and then runs and executes the interrupt code. In order to use software interrupts, you must load a new library. The TimerOne interrupt library can be downloaded here:

Click on the link, and it will download a zip folder to your computer. Find your Arduino Library folder (Video above explains how if you do not know how). In your Arduino Library folder create a new folder called TimerOne. Take the CONTENTS of the zip folder you just downloaded and put it in your TimerOne library folder. Remember that when you install a new library, you have to close and reopen the Arduino IDE for it to find the new library.

Now you will want to build a simple circuit to allow control of a yellow and red LED. The current limiting resistors in the circuit should be between 200 and 500 ohms. So, lets build the following circuit:

Make sure to connect the long legs of the LED to the control pins.

Now we are ready to create our first interrupts.  First matter of business is your program should load the interrupt library:

This should be at the top of your code, and will load the library.

To create an interrupt, you need to first now initialize the interrupt, specifying what time frame you want it to “interrupt” on,  and then what you want it to do when the interrupt alarm goes off. You would typically set these two things up in the Void Setup. Consider this sample code:

If you place this code in the void setup, it will do two things. The first is it will initialize an interrupt that will go off every .1 seconds. Understand the units for the Timer1.initialize command are in microseconds, so 100,000 microseconds would create an interrupt every .1 seconds. Now you have to tell arduino what to do when the interrupt goes off. This is done with the Timer1.attachInerrupt command. In the code above, you can see that the command is telling the arduino that every time the interrupt goes off, it should pause what it is doing, go and run the BlinkYellow function, and then afterwords return to whatever it was doing.

So, lets pull all this together to crate a program that will blink a Red LED slowly, 1 second on, followed by one second off, and then at the same time blink a yellow LED quickly using the Timer1 interrupt. The following code would do just that.


Python with Arduino Lesson 14: Introduction to Xbee Radios and Wireless Communication

In the video lesson above, we introduce our next series of lessons, which will step you through using Xbee radios to allow your arduino projects to wirelessly communicate with your PC. The good news is that you already know how to communicate between your Arduino and the PC over the serial cable based on our previous lessons. Using Xbee radios is very similar, you just remove the cable. You are still communicating over the serial ports, so the coding remains virtually unchanged . . . you just have to configure and connect the radios. In order to do these lessons, you will need a pair of Series 1 (S1) Xbee Radios (you will need two). If you want longer range, and are willing to pay more, you can get the Seris 1 (S1) Xbee Pro Radios.

To program the radios, you will need a SparkFun USB Explorer.

The final equipment you need will be an Xbee Shield. The shield allows you to plug the Xbee radio into the Arduino.

LESSON 27: Instrument Package

In this lesson we bring together a lot of the material from the first 26 lessons to create an instrument package that could be deployed in a demonstration project. We will wire wrap up an Arduino Nano, a Virtuabotix SD card reader, and the Adafruit Ultimate GPS to create a system that will track and log position and altitude, and save the data in a format that can be displayed on Google Earth.

Wire Wrapping
Wire Wrapping tools and Perforated Board

You will want to place the Adafruit GPS, the SD Card Reader, and the Arduino Nano into a perf board.  Then, you will want to carefully wire wrap the components as follows:

Connecting the Adafruit Ultimate GPS Unit to Arduino
GPS Pin Arduino Pin
Vin 5V
RX Pin 2
TX Pin 3


Connecting the SD Card Reader
Sd Card Reader Pin Arduino Pin Details
GND GND Common Ground
3.3 V – (NOT USED)
+5 5V Power
CS 4 Chip Select
MOSI 11 SPI Data
SCK 13 Clock
MISO 12 SPI Data
GND GND Common Ground


Now the code you developed in LESSON 26 should run on this prototype. The code creates a Google Earth friendly set of coordinates. Just put a KML wrapper on the coordinates as described in LESSON 26.  Putting it all together, I took the system outside and walked around, and this is the data track I got.

GPS Track
GPS track generated by my wire wrapped prototype


LESSON 26: Wire Wrapping

The neat thing about using breadboards and jumper wires to build a circuit is that it is a quick and easy way to get your prototype up and working. It is an excellent way to get your circuit and code debugged. The wires are very easy to connect by just plugging them into the holes. the downside is, those wires come out just as easily as they went in.

Breadboard Prototype Wires are Not Securely Connected

The breadboard prototype is great for getting your prototype going, but to use in a real project like a robot, unmanned aerial drone, or high altitude balloon, you will need a more secure way to connect your circuit up. Typically the next step for commercial products would be to order a custom PC board, and then solder the components into the board. This is a great way to go, but there are some pretty large barriers to doing this. There is a fairly steep learning curve to the board design software. The second issue is that even for simple projects the minimum order is usually around $100. Once you order the board you really can not tweak or make changes to your design. Also, you typically solder the components into the board, so you can not take it apart and use your components in other projects.

Wire Wrapping Tool
Wire Wrapping Tool and Wire

Luckily, there is a good options for students working with a limited budget. It is an almost lost art form known as Wire Wrapping. To make a robust circuit suitable for deployment in real projects, you need a minimum of equipment, and it is very easy to learn.

In order to get started, you will need a few things. You will need a good Wire Wrapping Tool,  30 AWG Wrapping Wire,  and some Prototyping Boards.

Once you have your gear, the rest is pretty simple.  Measure out the length of wire you need, leaving excess on each end for the “wrap”. I like to use about 1 inc of wire for a wrap. Hence, I would leave 1 inch extra on each end, or two inches total extra for each wire. Then strip about 1 inch of wire off each end. Insert the wire into the small hole or indention in the wire wrap tool. Place the tool over the post or pin you want to wire wrap, and gently rotate the tool clockwise until the wire is wrapped around the post. Simple as that. The video above shows you just how to use it.