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

LED brightness values in the Serial Monitor are nice and good, but you probably want to control some actual hardware. So let’s go ahead – time to create a dimmer for your LED!

Your breadboard should now have both the LED with its current-limiting resistor and your potentiometer. If not, set them up quickly using this diagram that you already know from the previous lesson:

LED und Poti am Arduino

___STEADY_PAYWALL___

In the previous lesson, you saw how to use the potentiometer to generate values from 0 to 1023 on an analog pin.

You can use these values to directly “map” them to the LED’s brightness. This would mean that 0 represents an extinguished LED and 1023 represents maximum brightness.

However: There’s a small catch here. To control the LED’s brightness, we need an analog (variable) signal. This is created using pulse width modulation (PWM for short). Simply put, this allows you to simulate an analog signal through a digital pin. The signal strength or voltage is created by turning the pin on and off at a specific frequency.

This way, you can make the LED not just simply turn on or off (digitally), but you can make it “rotate” brighter or dimmer through higher or lower voltages.

However, when using PWM, only values from 0 to 255 are allowed. Your potentiometer “delivers” 0 to 1023. That’s why you need another new function: map();

How to bring the values together

The map function is extremely useful and will help you frequently in the future. Its principle is quite simple:

You take a specific value that lies in a range X. Then you determine what position this value would have in a different (larger or smaller) range Y.

Schaubild Map-Funktion

In your sketch, it looks like this:

potiValue = analogRead(potiPin);
ledValue = map(potiValue, 0, 1023, 0, 255);

 

First, you read the current value of the potentiometer with the analogRead() function. The analog signal from the potentiometer is converted into a value from 0 to 1023 using the analog-to-digital converter.

The determined potiValue (potentiometer value) is the first parameter in the function, followed by the allowable range of the potentiometer, which is 0 to 1023.

Finally, there’s the range in which the corresponding potiValue should be found. This is the allowable range for PWM, which is 0 to 255. You then store the corresponding value in the ledValue variable.

Let the LED shine

Now you just need to send the ledValue to the LED. You do this with the analogWrite() function:

analogWrite(ledPin, ledValue);

This uses pulse width modulation and creates a signal that makes the LED light up with the desired brightness that you’ve set on the potentiometer.

Try it out right away! You can find the appropriate sketch in the Exercise Files for this lesson.

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