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

Next, you’ll build a counter in the Serial Monitor that starts at one and counts up by one every second.

Output Variables in Action

Let’s first look at how to declare a variable for integers. For this, you need the variable type int – which stands for integer. Let’s say the variable should be called number and initially have the value 1:

int number = 1;

 

That was easy. But you might be wondering where in the sketch this line should go – and this brings up another important aspect of variables: scope.

Global and local variables

Basically, there are two states that variables can have regarding their scope: global and local. Simply put, global means that the variable is available to all functions in the sketch and can be modified there. Local variables, on the other hand, can only be used in the function where they were declared – and can only be read and modified there.

You already know two of these functions from every sketch you create: void setup() and void loop(). If you were to create the variable in the setup function, it would only be available there as it would be local:

void setup() {
  int number = 1;
  Serial.begin(9600);
}

void loop() {
  Serial.println(number);
}

 

This specifically means that the loop cannot “see” the variable number – and therefore cannot output it to the Serial Monitor. This means we need a global variable. You declare this at the very beginning of the sketch, before the setup:

int number = 1;

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(number);
}

 

This ensures that the loop can access it. Let’s return to the counter. For this, we first want to output the variable number to the Serial Monitor. Then the number in the variable should be increased by one. This works quite simply:

number = number + 1;

 

Does this notation confuse you? Then try reading the line of code like this: “Take the variable number, assign it its previous value and add the number 1 to it.”

There is another, shorter notation – from which the language C++ actually gets its name:

number++;

 

This notation might be less intuitive at first glance, but it saves you some time when programming – and looks more professional. 😉

By the way, if you want to use other types of calculations instead of addition, this works as follows:

number = number - 1; //Subtraction
number--; //Also subtraction
number = number * 2; //Multiplication
number = number / 2; //Division

 

And that’s all you need for the counter. The complete sketch then looks like this:

int number = 1;

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(number);
  number++;
  delay(1000);
}

 

Here again you make use of the loop: It outputs the variable number, adds one, waits a second – and starts this procedure again from the beginning. This continues until you restart or turn off the Arduino.

In the next lessons, we’ll turn to the hardware – starting with an LED.

Exercise Files
Variables_in_Action.zip
Size: 1.35 KB
We don't track you. Enjoy your cookies while making awesome projects!