Grove Beginners kit: Arduino Lesson 3 Rotary dial controlling the Blink Frequency
This lesson introduces Analog to Digital conversion. The LED flash rate is controlled by the Rotary Potentiometer.
|The Grove Beginner Kit For Arduino includes an Arduino Uno board with preconnected devices. The Grove lessons supporting this present coding using the Arduino IDE. These pages present the same lessons using the Codecraft IDE that uses the Block style of coding with specific Grove Arduino blocks.|
The rotary dial voltage is read as an analog signal, the level of which determines the LED falsh rate.
Like the first lesson, the LED flashes off and on but the on and off periods are determined by the rotary dial. The LED is once again driven directly from Pin D4 with an on delay and off delay as previous. The voltage level of the rotary dial is read in as an analog signal from pin A0 and converted into a number between 0 and 1023. 0 voltage equals 0 and 5 volts equals 1023. This value sets the period of both delays (on and off) in milliseconds so the range of delays is 0 to about 1 second.
When the dial is turned completely in one direction, the input will be 0 volts and the analog signal will be 0. When the dial is at the other extreme, the input will be 5 volts and the analog signal will be 1023. If the rotary dial is in the middle of its range the analog input would read at about 512 and the delays will be about one half of a second.
Grove Beginners Kit
Components this lesson
- Grove LED
- Grove RotaryPotentiometer
|Component||Interface||Type||Pins or Address|
|AirPressureSensor BMP280||I2C||sensor||I2C 0x77(default)/0x76(optional)|
There are two ways to implement this lesson as shown. The first is simpler. The second introduces using variables. The following video demonstrates the second method.
The lesson code block.
The loop function is similar to the previous 2 lessons. In the first leson there was a fixed delay between toggling of the LED state. In the second lesson the LED just tracked the state of the button press. In this lesson the on/off periods are set by the rotary dial that is input as an analog signal which when digitised gives a value of 0 to 1024. That results in periods of 0 to slighly more than one second.
How to create this ...
Watch the video on Youtube:
For this lesson, The LED flash changes when the rotary dial is turned.
You should now understand tha there are digital input and output signals which can be either on or off. Alternatively for analog signals, the input vottage is converted (digitized) to a number which can be used in code. In this lesson the rotary dial analog value was used to set the on/off delays for the LED and so controlled the flash rate.
|This Category Links|
|Category:||Arduino Beginners Index:||Arduino Beginners|
|Next: >||Grove Beginners kit||Arduino Lesson 4 The Buzzer|
|< Prev:||Grove Beginners kit||Arduino Lesson 2 Press Button|