What is a potentiometer?
|A potentiometer is a variable resistor, or in other words, a component that regulates the intensity of electrical current in a circuit. They are used in many devices, such as lamps, to regulate the light intensity, or in musical equipment to adjust the volume.
As with all analogue sensors, the potentiometer will return values between 0 and 1023.
Modifying the blink speed
Remember when we made an LED blink by changing the waiting times? In this example, we will modify the blink speed using the potentiometer .
Connect an LED and a potentiometer to your board.
In the Control -> Advanced tab,
Under Loop, we will declare the blink_time variable as the value that the potentiometer returns. Under the Control -> Advanced tab, we will select the Wait block, which will enable us to enter the blink_time variable as the waiting time between switching the LED on and off.
Modifying the tone of the buzzer
We will use the potentiometer to vary the note produced by the buzzer. Before we start programming, we need to connect the components:
Let´s remember that the potentiometer can have values between 0 and 1023, but in this case, we want to follow a scale of 200 to 500 Hz, a scale which is very close to the most commonly used notes. To do this, we will be using a new block called Map.
What is mapping?
Mapping is converting one range of values into another.
In the previous example, we were varying the blink of the LED between 0 and 1023 milliseconds. But… what if we wanted to control the blinking of the LED so that it was between 0 and 10 seconds? The solution is to use the Map block, that will transform the scale from 0 to 1023 to a new one of 0 to 10.
With the buzzer, we must transform or map the scale from 0-1023 to a scale of 200-500.
We will select the advanced buzzer block to allow us to enter frequencies, and the Map block under the Advanced option of the Maths tab. .
|ADVICE: The larger the range to be mapped, the more the value of each small turn of the potentiometer will vary, resulting in a lower resolution. This means that we won´t be able to make precise adjustments.|
There´s even more
- Here´s a few more ideas so you can keep on practising:
- Continuing with your Christmas LED lights and buzzer melody programming project, now add the potentiometer in order to modify the blink speed and the melody
- Build some electronic bagpipes using the light sensor, the potentiometer and the buzzer.
The potentiometer can be very useful for controlling different values and elements in our projects. For example, varying the intensity or the blink time of a light, varying the sound of a buzzer or selecting different modes on a machine.