Potentiometer in Arduino
Potentiometer in Arduino
ARDUINO
EPN-FIM-2016
POTENTIOMETER - EXCERCISE
• Measure the position of a potentiometer and use it to control the
blink rate of a LED. Turn the knob to make it blink faster or slower!
What's a potentiometer?
• It's the same type of control you'd use to change volume, dim a lamp,
etc. A potentiometer changes resistance as it is turned. By using it as
a "voltage divider", the Arduino can sense the position of the knob,
and use that value to control whatever you wish (like the blink rate of
an LED, as we're doing here).
Potentiometer:
• Potentiometers have three pins. When we're using it as a voltage
divider, we connect the outside pins to power and ground. The
middle pin will be the signal (a voltage which varies from 0 Volts to 5
Volts depending on the position of the knob).
• Connect the middle pin to ANALOG IN pin 0 on the Arduino.
• Connect one of the outside pins to 5V.
• Connect the other outside pin to GND.
Circuit
Circuit
The code
• In this code we'll start using "variables".
• A variable is a named number. We'll often use these to store numbers
that change, such as measurements from the outside world, or to
make a sketch easier to understand (sometimes a descriptive name
makes more sense than looking at a number).
Data types
• Variables can be different "data types", which is the kind of number
we're using (can it be negative? Have a decimal point?) We'll
introduce more data types later, but for the moment we'll stick with
good old "integers" (called "int" in your sketch). Integers are whole
numbers (0, 3, 5643), can be negative, and for reasons we won't go
into right now, can range from -32768 to 32767.