0% found this document useful (0 votes)
3 views

Potentiometer in Arduino

This document explains how to use a potentiometer with an Arduino to control the blink rate of an LED. It describes the function of a potentiometer, its connections, and the necessary code to read its value using the analog input. Additionally, it introduces variables and data types in Arduino programming, emphasizing the importance of declaring variables before use.

Uploaded by

Oscar Sotomayor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Potentiometer in Arduino

This document explains how to use a potentiometer with an Arduino to control the blink rate of an LED. It describes the function of a potentiometer, its connections, and the necessary code to read its value using the analog input. Additionally, it introduces variables and data types in Arduino programming, emphasizing the importance of declaring variables before use.

Uploaded by

Oscar Sotomayor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

POTENTIOMETER IN

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.

• For a list of data types


• http://arduino.cc/en/Reference/VariableDeclaration
Variables
• You must "declare" variables before you use them, so that the
computer knows about them. Here we'll declare two integer
variables, and at the same time, initialize them to specific values.
We're doing this so that further down, we can refer to the pins by
name rather than number.

Note that variable names are case-sensitive! If you get an


"(variable) was not declared in this scope" error, double-check
that you typed the name correctly.
The code
The code - inside void setup
The Code – inside void loop()
The code – inside void loop ()
• The Arduino can read external voltages on the analog input pins using
a built-in function called analogRead(). This function takes one input
value, the analog pin we're using (sensorPin, which we earlier set to
0). It returns an integer number that ranges from 0 (0 Volts) to 1023
(5 Volts).
• We're sticking this value into the sensorValue variable:
The code – inside void loop()
The full code
Do it!

You might also like