What is a potentiometer?
A potentiometer is a variable resistor. In other words, an electronic component that allows the intensity of the current (the amount of electricity) circulating around a circuit to be regulated. For example, if we want to control the intensity of the current that passes through a circuit and makes the LED light up, we can connect a potentiometer and, according to which way we turn it, we will see how the brightness of the LED varies in relation to the varying intensity of the current. Potentiometers are used to regulate many devices, such as in audio equipment for controlling the volume.
|The potentiometer generally serves to adjust a value within a desired range, which is highly useful. We will give two examples that use the potentiometer so that you can discover what it can do. Let´s get to work!You will need:
Got everything? Let´s get started:
Making the blinking speed of an LED vary using the potentiometer
Remember what we did to make an LED flash on and off? For sure you will have changed the time delay to make the blinking slower or faster. In this example, we will change the speed of that flashing on and off using the potentiometer. To do this, we will connect the LED to digital pin 3 and the potentiometer to analogue pin A1 as this connection diagram shows:
Remember that the potentiometer is a sensor, which is why it´s recommended that you assign a variable to it in order to read its possible values:
As we have said before, a variable that contains the values of the potentiometer is declared in the program. We will make the LED flash on and off, but instead of making it wait for a fixed period of time between on and off, we add the value that the potentiometer has at that moment (which depends on what position we have turned it to) to the waiting time. Using such a simple method as this, we can vary the blinking speed of an LED. Now we know how to make our own Christmas lights!
Varying the tone of the buzzer using the potentiometer
In this exercise, we will select the tone, and therefore, the note of the buzzer by turning the potentiometer. We will use a new block for this which is called map. This block will be very useful to us in the future, as it allows us to convert one range of values to another. To give you a better understanding: the potentiometer is an analogue component that give us values between 0 and 1023. In the last example, this meant that we were varying the LED blinking between 0 and 1023 milliseconds, 1 second approximately. This value is ok, but what would happen if we wanted to adjust the LED blinking to between 0 and 10 seconds? The solution is to use the map block:
But not everything is perfect, the greater the range to be mapped, the lesser resolution we will have. In other words, it will vary the value more with each small turn of the potentiometer, so we won´t be able to make very precise adjustments. To carry out the next exercise, we will connect the potentiometer to analogue pin A1 and the buzzer to digital pin 3, as shown in this diagram:
Now we will use the advanced buzzer block. This block is very similar to the one we have been using, only instead of allowing us to select notes, it allows to select the frequency of the buzzing, so we can create our own tones. We want the frequency of the buzzing to be between 0 and 20000, which is why we will have to map the potentiometer between those values:
As the advanced buzzer make different tones according to its frequency, we need to place the control variable that we have declared in the tone tab.
Now you know how to handle the potentiometer. You will have seen that the potentiometer can be of great use to us for varying different values and elements in our projects. From varying the intensity or the time of blinking light, to varying the sound of a buzzer, or selecting different modes on a machine… Although digital electronics have progressively replaced analogue controls, you can still find many examples in your home which use potentiometers… Can you think of any? Of course you can!