All posts by admin

Arduino Tutorial 4: Understanding Arduino Variables

In our earlier lessons we would program using “constants” when we needed numbers. For example, if we wanted to set pin 13 to an output, we would use the command:

pinMode(13, OUTPUT);

The problem with using constants like the number 13, if you decided later to use pin 8 instead, you would have to edit every line of code that used that number. It is much better practice to use variables when coding. In this video we show you have to program using variables. We start by doing things the wrong way, using constants, then show you the advantages of using variables.

Hopefully you can see from this video how much better it is, and more efficient to use variables instead of constants. In all the future lessons, we expect you to use variables.

Arduino Tutorial 3: Understanding How Breadboards Work

 

LED Arduino CircuitThe cool thing about the arduino is you can program it to interact with the real world. The arduino can connect to and interact with a variety of sensors and actuators which allow you to monitor what is happening around you, and to control things like motors, relays, and servos. To do this though, you need to be able to connect components to the arduino. For prototyping, that is most easily done by using a breadboard. If you want to play along at home, and follow all these lessons with the same components I am using, you can order this Arduino kit. 

The video below describes in detail how to use a breadboard, and even helps you get your first circuit prototype up and running.


As explained in the video, key to using the breadboard to create circuits is to understand how the little holes on the breadboard are connected. This graphic will help you understand which holes are connected and which are not.

Breadboard
Breadboard for prototyping your Arduino Circuits

Study this graphic, and make sure you understand how the breadboard works. You can see that to connect two leads together, they should be plugged into the same column on the breadboard. It does not matter which column, as long as the two leads are in the same column.

It will take some practice, but if you follow the video carefully, you should be able to get your first circuit connected and working.

Arduino Tutorial 2: Understanding How Light Emitting Diodes (LEDs) Work

In this series of Arduino lessons, I really want you to begin to understand how the arduino works. That is, open the hood, and begin to understand how the magic happens. You already are thinking about how you can type commands to make the Arduino do what you want, but how does it all work. The magic happens because of special materials called semiconductors. Semiconductors are used to make computer chips, microprocessors, LED’s and just about any electronic component you can imagine. Since semiconductors are so important, this lesson will give you a little bit of an introduction to the Physics behind semiconductor materials. We will do this by really explaining how LED’s work. The video will serve as an introduction to these amazing materials that have enabled computer technology. In this new series of lessons, I will be using this Arduino kit. If you order this kit, you can play along at home as I go through all these lessons.

Arduino Tutorial 1: Getting Started with the Arduino for Beginners

Arduino

Guys, our original series on the Arduino Microcontroller was insanely popular. Those original lessons had some great technical content, but the production quality of the videos was pretty low. Because of that, I want to go in and redo the arduino tutorials, taking advantage of improved production capabilities I now have, and using fresh hardware and software. For those who have taken the original series, the first few lessons will be material you already have learned. You can choose to review the material, or just skip to the later lessons.  In this new series of lessons, I will be using this Arduino kit. 

So, enough of this small talk, lets get right into the new and improved lessons.

With the hardware linked to above, you will simply have to install the Arduino software. You can download the Arduino Software here. The installation is explained step-by-step in the above video, but it is pretty self explanatory.

The video takes you through the steps to make the on-board LED turn on, off, or blink. This will be your first few example programs, and hopefully you will see that programming is not that difficult. When you are done with this lesson, you will have written your first few programs. Enjoy!

LESSON 33: Understanding Local and Global Variables in Arduino

In lesson 32 we introduced you to the concept of Arduino Functions. Functions are little blocks of code that allow you to break a complicated task down into small logical chunks of code. All the parts of the program shared the same set of variables.  This is the easiest way to do functions, but is really not a good way of doing it. As programs get more complicated, with more functions, unexpected problems can arise if all the parts of the program are sharing the same variables. One function might inadvertently change a variable in use by another function causing unexpected problems. The best way to write modular code is to use local variables.

In Arduino, if a variable is declared at the top of the program, before the void setup, all parts of the program can use that variable. Hence, it is called a Global variable. On the other hand, if the variable is declared between a set of curly brackets, the variable is only recognized within that scope . . . that is, it will only be recognized and can only be used between that set of curly brackets.

For example, if a variable is declared in the void setup, it will not be recognized and can not be used in the void loop, because the void loop is within its own set of curly brackets.

Similarly, if there are two for loops inside the void loop, each for loop has its own set of curly brackets. If a variable is declared inside the first for loop, it will not be recognized inside the other for loop, and will not be recognized in the other parts of the void loop.

This might sound like a hassle, but using local variables really helps you stay out of trouble. The best way to do functions is to use local variable, and inside each function, the variables are declared that are needed by that function. Watch the video and I will give you clear examples of using local and global variables.