Tag Archives: Tutorial

Arduino Tutorial 22: Understanding and Using Active Buzzers to Add Sound to Your Project

In this lesson we show you how to add sound to your Arduino project using a buzzer, The Elegoo Super Starter kit contains two buzzers, an active buzzer and a passive buzzer. The active buzzer is the easiest to use, as you just need to apply 5 volts to it to get it to go off. In this lesson we show you how simple it is to use the active buzzer with Arduino. In future lessons we will show you how to use the passive buzzer.

The advantage of the active buzzer is that it is easier to use. Just apply 5 volts, and it goes off. The advantage of the passive buzzer is that it is cheaper, and allows you more control of the tone, or pitch of the sound produced.  If you want to follow along at home, you can order the Arduino Kit we are using HERE.

Arduino Tutorial 10: Understanding How To Read Analog Voltage using analogRead Command

So far in these lessons, we have just been using the Arduino output pins. If we actually want to read values from a sensor or other such components, we need to learn how to read values from the analog pins. These are pins A0 through A5. This lesson will teach you all about the analogRead command that allows you to interact with these pins. Enjoy!

In this new series of lessons, I will be using this Arduino kit. 

LESSON 32: Understanding Arduino Functions

So far we have written programs as a long string of code, pretty much all in the void loop. As we begin to need to develop more complicated code, putting all the programming in the void loop can become unmanageable. It is easy to lose track of what we are doing. For more complicated programs, we want to break the problem up into manageable chunks of code. This is called modular program. We develop small modules that do specific tasks, and then our void loop simply calls these modules. The modules are called “Functions” in arduino.

Lets consider an example. Lets say we want to write an arduino program that prompts the user for the number of grades he has. Then it averages the grades, prints the grades and then prints the average. The following program would do this job, with all the code in the void loop:

You can see that the void loop is getting pretty complicated, and it would be easy to begin to lose track of what is going on. If we think about what we are trying to do, lets try to break it down more logically. These are the logical tasks we need to do:

Input Grades

Average Grades

Print Grades and Average

I think that is the logical way to break the program down. Hence, we need three modules or functions, which we could define as follows:

inputGrades();

avGrades();

printGrades();

We could call these three functions in the void loop. then down below the void loop we would need to define, or teach arduino what each of these functions do. In effect, the code in the example above is put down in three logical blocks, which we call functions. Notice that when we do that, the functions must be defined AFTER the void loop. That means it is done after the closing curly bracket for the void loop. Using functions, we can rewrite the program above as follows:

Notice now that the void loop is very simple to understand, since each function is logically named. Also, if we look down at the function definition, it is clear what each chunk of code does. In this example, we are using global variables, so each function, and the void loop are all working with the same set of variables. In future lessons we will look at the use of local variables, and then how that would affect the structure of our functions.

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.

Keys to a Successful Engineering Career LESSON 19: How to Properly Take Problems to Your Boss

One of the worst things that can happen to your engineering career is to develop the reputation of being a whiner. Hence, you want to avoid complaining as much as possible. There are, however, times that important issues need to be taken to your management. This should be done in a manner that does not make you look like a whiner. In this video, we describe the right way to take issues to the boss.