Course Content
The Arduino UNO
In the following three lessons, you will get to know your microcontroller - the Arduino UNO. You will learn more about its history, its functions, and most importantly: how to power it.
0/3
The Arduino IDE
For beginners, the Arduino IDE (Integrated Development Environment) is usually the first choice – and for good reason. You can program all Arduino boards with it and manage libraries for sensors, displays, etc. It also features the "Serial Monitor," where you can output data and troubleshoot.
0/2
Your first sketch
In the following lessons, you'll get to know the basic structure of an Arduino sketch and write your own programs. Let's get started!
0/2
The Serial Monitor
Now let's turn our attention to the Serial Monitor – a feature of the Arduino IDE that you will use in virtually every one of your projects.
0/2
Variables
No programmer can avoid variables. In the following lessons, you'll learn what types there are and what you can do with them.
0/3
Controlling an LED
Now it's time for more hardware! In the next lessons, you'll connect an LED to your Arduino. You'll first turn it on and off with a button. After that, you'll build a dimmer to control the brightness of the LED.
0/6
Lie Detector
Discover the entertaining side of electronics by building your own simple lie detector with your Arduino. This fun project uses basic components to measure skin resistance changes when someone might be telling a fib, perfect for adding some playful suspense to your next gathering with friends.
0/1
There’s music inside!
Your Arduino can do much more than "just" make LEDs shine at different brightness levels. For example, it can make music. In the following lesson, you'll learn how to use a piezo buzzer and coax some charming tones out of it.
0/3
A Theremin with Ultrasound
Do you want to make a bit more music? In this lesson, you'll build a theremin that you operate with your HC-SR04 ultrasonic sensor. You move your hand toward and away from the sensor - your Arduino calculates the pitch of the tones from the distance, which are then played through your piezo buzzer.
0/5
The Sound Sensor
Ready to explore how your Arduino can respond to sounds? In this lesson, we'll connect a sound sensor to your Arduino and learn how to make it respond to both digital noise detection and analog volume levels.
0/1
Build an Alarm System
In this project, you will build your own alarm system. It consists of three components: the sound sensor, which you have just learned about, the active piezo buzzer, and the RGB LED.
0/2
The DHT11 Temperature Sensor
Let's move on to another component that you'll certainly use in many projects: the temperature sensor. In this case, the popular DHT11, which can measure not only temperature but also humidity.
0/3
Arduino Course for Beginners

How about a theremin that sounds less like science fiction and only plays notes of a scale – just like you know from the piano or guitar? No problem, but for this you need to familiarize yourself briefly with another important programming building block: arrays.

An array is simply a collection of variables or values. These can be frequencies of notes in a scale, but also any other chain of values that belong together – for example, values for the brightness of an LED, measurement results from the lie detector, etc.

So far, you have assigned a single value to a variable, e.g.,

int var = 10;

 

An array, on the other hand, can contain several of these values. You declare it as follows:

int myArray[] = {1, 2, 3, 4, 5};

 

Please note the square brackets after the name of the array. The values in the array are separated by commas within curly brackets.

Accessing values in an array

How can you now read the values in the array above? It’s quite simple, each value in the array has an index, which is a number that defines the position of the value in the array. Just like the note C is the first note in the C major scale and D is the second. That makes sense, but in C++ (and many other languages) you need to note one thing: arrays are zero-indexed, which means that the first value is not at the 1st position in the array, but at the 0th.

So if you want to access the value 1 in myArray[], you do it with the index 0:

int firstValue = myArray[0];

___STEADY_PAYWALL___

You access the second value (i.e., 2) with myArray[1] – and so on. The last value in the array above is the number 5 with the index 4.

But what happens if you want to access a value that doesn’t exist in the array? For example, if you access index 5 in myArray[]? Here your sketch will be a bit lost and won’t provide any meaningful data – and in the worst case, it will crash.

Reading values with a FOR loop

If you want to output all values of the array one after the other, it’s quite simple with a FOR loop:

for (byte i = 0; i < 5; i = i + 1) {
  Serial.println(myArray[i]);
}

 

Here the counter i initially stands at 0 and accordingly in myArray[0] ensures that the first value appears in the Serial Monitor. Then i is increased by 1 – myArray[1] outputs the second value, and so on.

Adding new values

myArray[] still doesn’t have an index 5 – but you can change that. You simply add new values as follows:

myArray[5] = 6;

 

But of course, you can not only add new values to the end of an array, but also replace existing values. To do this, simply choose the index of the number you want to replace and assign it a new value.

In the next lesson, you’ll use an array to store different tones – which your theremin can then access.

We don't track you. Enjoy your cookies while making awesome projects!