Tag Archives: STEM

LESSON 29: The Dos and Don’ts of Arduino Software Interrupts

This is a follow on to lesson 28, to address some of the questions that come up. It is important to understand that all functions are not well suited for use with software interrupts. You must be mindful of timing. Key to being successful with Arduino Software Interrupts is the function called needs to be small and very fast. When the interrupt calls the function, you need to get in and out of that function as quick as you can. Hence, you should avoid doing printing in the function called by the interrupt. You should try and avoid working with serial data, because things can get lost if you are not careful. Also, you should know that you can not use a delay in the function.

For most beginner programmers, interrupts should just be used to call short functions, with minimal lines of code, that can be run quickly.

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 TimerOne-r11.zip 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.


Sketchup Tutorial LESSON 9: Designing and Printing Box with Movable Hinges

In this lesson we use Sketchup to design a more complex 3D device. This box is not a simple extrusion, because the hinges are extruded along an orthogonal axis. Hence in this lesson we learn how to sketch and extrude in orthogonal planes in the same design. In the end the design worked very well, and we printed it both on the Prusa Mk2 I3 and the Raise3D N2 Plus. Prints were successful on both machine.

Review of Raise3D N2 3D Printer

As most of you know I teach high school engineering classes. While our main focus is on electronics, circuits and microcontrollers, we also dabble in other engineering areas. A few years ago I wanted to expand more into the mechanical domain. We ended up getting burned really bad by purchasing a Makerbot Replicator 3D printer. Bases on how bad that went, I have been very cautious about dipping my toe back into the 3D printer arena. Being a sucker for bleeding edge technology, I did bite the bullet and purchase another 3D printer last week. After a whole lot of research I got the Raise3D N2 plus printer. I have it up and running, and the bottom line is that I believe this printer is a real winner, and is ready for prime time. My full review is in the video below:

To incorporate new technology into the classroom, the technology must be mature enough that you can count on it to work. If you are teaching a class on mechanical design, and the printer is down for weeks on end, the class becomes restless, and you have a pretty big problem on your hands. That is what happened when we got the Makerbot. The good news is that the Raise3D printer appears to be rock solid, and reliable enough to use in the classroom. I will be posting more tutorials and howto’s on this printer in the future, but for now, I will say I am impressed with everything I have seen in this printer. If you are interested in a rock solid 3D printer, I recommend the Raise3D, available at the link HERE. This is for the top of the line model which I have. Yes, it is a little on the pricy side, but like I say in the video, there is nothing more expensive than a cheap 3D printer. In my mind the Raise3D is worth every cent.