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

Time for your first program! Your Arduino UNO has several small LEDs – you will now repeatedly turn one of them on and off, making it blink.

 

First, open the Arduino IDE and create an empty sketch. To do this, select “New sketch” from the “File” menu. Now you will see the two empty functions void setup() and void loop().

The Setup Function

Let’s start with the setup function. Enter the following line of code between the two curly braces { }:

pinMode(LED_BUILTIN, OUTPUT);

 

The setup function should then look like this:

void setup() {
  // put your setup code here, to run once:
  pinMode(LED_BUILTIN, OUTPUT);
}

 

Let’s take a closer look at this line. First, there’s another function here: pinMode(). This function also performs a specific action – it sets a direction or mode for a specific pin on your Arduino: either sending a signal (OUTPUT) or receiving a signal (INPUT).

Unlike the setup and loop functions, this function “expects” something between the round brackets ( ), namely so-called parameters.

The first parameter determines which pin’s direction should be set. In our case, this isn’t an analog or digital pin on the sides of the Arduino, but the internal LED. This is referred to in the sketch as LED_BUILTIN.

The second parameter then determines the direction – either OUTPUT or INPUT. If you want to control an LED, the Arduino needs to send appropriate signals to it. From the Arduino’s perspective, this is an OUTPUT. However, if a sensor sends measurement data to the Arduino, this is an incoming signal – so it’s an INPUT.

Note: Make sure that every line that doesn’t end with an opening or closing bracket ends with a semicolon (;). Otherwise, your sketch cannot be uploaded. There are exceptions to this rule, but they aren’t important right now.

You only need to set the direction of the pin once at the beginning of your program. That’s why the pinMode() function is in the setup function.

The Loop Function

Now let’s move on to the loop. In the previous lesson, you learned that the code within the loop constantly repeats. We can use this to make the LED blink.

Actually, blinking is nothing more than 1) turning the light on and 2) turning the light off – and then starting over:

Blinkendes Licht

Turning the LED on

First, enter the following line in your loop function between the curly braces { }:

digitalWrite(LED_BUILTIN, HIGH);

 

This is another function, digitalWrite(). This function can send either a HIGH or LOW signal via a digital pin. HIGH means something like “on” or 1 – LOW, on the other hand, stands for “off” or 0.

Using an LED as an example, this is easy to understand: HIGH turns the LED on, LOW turns it off.

The digitalWrite() function also expects two parameters: the pin it should control and the signal. In our case, that’s the LED_BUILTIN pin and initially the “Turn on” signal – so HIGH.

You now have a line to turn on the LED. But that’s not proper blinking yet.

Wait a moment

An Arduino is amazingly fast. If you turned the LED on and immediately turned it off again, you wouldn’t notice any blinking. The change from on and off would be so fast that it would look like the LED was constantly lit.

So we need to wait a moment.

In the sketch, this works with the – yes, correct – delay() function. This function delays the further execution of your program. For this, it expects a single parameter, namely the duration of the delay – in milliseconds.

Enter the following line next in the loop function:

delay(1000);

 

This delays further execution by 1,000 milliseconds, which is exactly one second. The delay ensures that the LED, which you turned on in the previous line, stays on for one second. Only then is the next line executed.

Turn the LED off and wait again

In the next two lines of code, you reverse the process – first, you turn the LED off and make sure it stays that way for a second:

digitalWrite(LED_BUILTIN, LOW);
delay(1000);

 

You already know the digitalWrite() function. This time, however, it sends the LOW signal to the internal LED (LED_BUILTIN). So it turns it off – also for one second.

The complete loop function then looks like this:

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);                      
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
}

 

Start all over again

Now you have everything you need for your blinking LED: You turn the light on briefly and turn it off again briefly. The loop function takes care of the rest, namely the repetition, all by itself.

As soon as your program has completed delay(1000); for the second time, it has reached the end of the loop and jumps back to its beginning – to the line digitalWrite(LED_BUILTIN, HIGH);

Have you already loaded the sketch from the downloads for this lesson onto your Arduino? If not, try it out right away! Afterward, play around a bit with the parameters in the delay function and change them. Maybe you can even practice Morse code by making the LED light up for different lengths of time.

You can find the complete sketch in the Exercise Files tab above.

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