Potentiometers are often found on guitar amplifiers and other audio gear, as well as in other electronics like radios and light dimmers.
In the 1984 American mockumentary film, "This Is Spinal Tap", some potentiometers "go to 11":
The "Rotary Angle Sensor" is a component that allows a user to turn a number to input a value.
Build this CodeCraft sketch ➡
Use the "Serial Plotter" to view the pot variable.
(Be sure to set the correct baud rate, 19200, in the Serial Monitor.)
What is the range of the "Rotary Angle Sensor" output?
Build this CodeCraft sketch ➡
Create a variable named "period"
From the Input menu, select the "Rotary Angle Sensor" block.
You can also use the "AnalogRead" block; it is functionally equivalent. They both generate the same Arduino code:
analogRead(A0)
Is it working as expected?
Can you increase the blinking rate until it looks to you like it isn't blinking? What's happening?
Use the Serial Println block to show the value of the potentiometer.
In the "setup" function, include a Serial Baud Rate block at 115200.
When you click on "Serial monitor" be sure to set the "Baud rate" to 115200 as well.
Refer to Using the Serial Monitor
What is the range of values (lowest, highest numbers) from the potentiometer?
Next, modify the Arduino sketch to do something different, such as:
Change the Delay time calculation. For example:
(period / 2 --> period * 2)
Include the Button to blink when the button is pressed, and change the number of blinks based on the value of the rotary potentiometer.
Refer to the Button LED lesson to remember how to use the Button.
Idea: Use the Map block (in the Operators menu) to map the rotary potentiometer values (0-1023) to the number of blinks (1-10, perhaps).
Calculate the blink frequency (see Time period and frequency, below) Note that the "period" is equal to the off time plus the on time. Also note that the "period" variable is in "ms" - "milliseconds." There are 1,000 ms in 1 second.
You'll need to use two operator blocks to perform the calculation:
Divide: /
Multiply: *
Display the frequency using the Serial Println block.
Example: Potentiometer Blink Frequency.cdc
Your ideas?
We have been using the Delay function to create the LED on and off times.
The sum of the on and off times is the "period, " usually labeled as "T."
We can say that the LED is on once during every period.
(For example, if we have been using an on delay of 1000 msec and an off delay of 1000 msec, the period is 1000 msec + 1000 msec = 2000 msec.
Or, 2 seconds.
But, if we want to express how many times per second the LED is blinking, we can to use frequency, usually labeled as "f."
The equation is easy:
Frequency = 1 / period , f= 1/ T
Frequency units are "cycles per second" or Hertz, abbreviated as Hz.
So, if the time period is 2 seconds, the frequency is
1 / 2 = 0.5 Hz.
Another way to say this:
1 / (2 blinks per second) = 0.5 blinks per second
Period to Frequency Calculator:
https://www.sensorsone.com/period-to-frequency-calculator/
More info: https://www.electronics-tutorials.ws/waveforms/waveforms.html
The potentiometer present a voltage between 0 and 5 volts DC to the microprocessor.
The ATMEL328p microcontroller includes a 10 bit analog to digital convertor (ADC) that measures the analog input and converts it to a number.
Details: Analog to Digital Converter Module of ATmega328P MCU
People usually use base 10 to represent numbers.
Each digit can have the value 0,1,2,3,4,5,6,7,8,9
Most computers physically represent numbers using binary notation -- base 2.
Each "bit" (binary digit) can have the value 0 or 1.
Think of input or output pins representing a single bit with a HIGH/LOW, TRUE/FALSE, +5 volts/Ground, ... value.