0% found this document useful (0 votes)
41 views23 pages

6-1 - Potentiometer and Analog Input

A potentiometer is a variable resistor that can divide an electrical signal to produce a range of output voltages. It has three connections - one each to the power supply, ground, and the wiper/output. As the wiper is turned, it produces different output voltages that can be read by an Arduino's analog input pins. The code example reads the potentiometer's output voltage and uses it to vary the delay between blinking an LED, demonstrating how analog sensor values can control behavior.

Uploaded by

Darwin Vargas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views23 pages

6-1 - Potentiometer and Analog Input

A potentiometer is a variable resistor that can divide an electrical signal to produce a range of output voltages. It has three connections - one each to the power supply, ground, and the wiper/output. As the wiper is turned, it produces different output voltages that can be read by an Arduino's analog input pins. The code example reads the potentiometer's output voltage and uses it to vary the delay between blinking an LED, demonstrating how analog sensor values can control behavior.

Uploaded by

Darwin Vargas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Potentiometer

and Analog Input


Life is analog. Arduino is digital. They can still be friends.
UNLIKE WITH OUTPUT...

The Arduino can read/receive/sense


both digital AND analog INPUT
What is a Think of it as a volume knob

potentiometer? It changes resistance

What does it look like? It works by “divides” the constant


electrical signal
What does it do?

How does it work?


A Potentiometer is a
Variable Resistor
frequently referred to by the abbreviation: POT
As you turn the knob on the
The “variable resistor” potentiometer, we detect a
different amount of input voltage
on the analog input sensor pin
on the Arduino

To analog input sensor pin

Input +5V
potentiometer
To GND
Arduinos and “Analog Sensors”

The input pins A0-A5 detect input voltage.

They have no clue what is connected to them.

Anything connected to analog input is a “SENSOR”

Arduino

Analog Input Pins A0-A5


When input is really output
The terms input and output are in reference to one thing at a time.

Output from the POT becomes input to the Arduino.

input output input


+5V
Signal
Potentiometer Arduino
Reading Analog Input
analogRead() Function reads input voltage

variable=analogRead(pin);

example:

sensorValue=analogRead(A0);

After this line, the variable sensorValue contains the value that was read at that moment.
Input Voltage and Input Voltage comes in the range of
Sensor Values 0.00V to 5.00V

analogRead() returns a value in the


input voltage to the Arduino range of 0 to 1023. No units.
This code reads the POT level and blinks the LED with a
variable pause between blinks
const int outputPin=11;
const int inputPin=A0;
void setup() {
pinMode(A0,INPUT);
pinMode(11,OUTPUT);
}
void loop() {
int inputLevel=analogRead(inputPin);
digitalWrite(outputPin,HIGH);
delay(inputLevel);
digitalWrite(outputPin,LOW);
delay(inputLevel);
}
Breaking down
the code
Identify Parts of Code: Global Constants
1: const int outputPin=11;
2: const int inputPin=A0;
3: void setup() {
4: pinMode(A0,INPUT);
5: pinMode(11,OUTPUT);
6: }
7: void loop() {
8: int inputLevel=analogRead(inputPin);
9: digitalWrite(outputPin,HIGH);
10: delay(inputLevel);
11: digitalWrite(outputPin,LOW);
12: delay(inputLevel);
13: }
Identify Parts of Code: Local Variables
1: const int outputPin=11;
2: const int inputPin=A0;
3: void setup() {
4: pinMode(A0,INPUT);
5: pinMode(11,OUTPUT);
6: }
7: void loop() {
8: int inputLevel=analogRead(inputPin);
9: digitalWrite(outputPin,HIGH);
10: delay(inputLevel);
11: digitalWrite(outputPin,LOW);
12: delay(inputLevel);
13: }
Identify Parts of Code: Function Calls
1: const int outputPin=11;
2: const int inputPin=A0;
3: void setup() {
4: pinMode(A0,INPUT);
5: pinMode(11,OUTPUT);
6: }
7: void loop() {
8: int inputLevel=analogRead(inputPin);
9: digitalWrite(outputPin,HIGH);
10: delay(inputLevel);
11: digitalWrite(outputPin,LOW);
12: delay(inputLevel);
13: }
Looking at the analogRead() function call
5 4 1 3 2

int inputLevel=analogRead(inputPin);

1. Call the analogRead method


2. With the inputPin as an argument
(so it knows where to read)
3. Take a sample of the input voltage
4. Return a value between 0 and 1023
5. Assign it to the inputLevel variable
Return value of
analogRead() and
sampling
inputValue=analogRead(pin);

Sampling voltage and returning an int value


Input Voltage: 0.0V 2.5V 5.0V

inputValue: 0 255 512 767 1023


Sampling (reading) rate: 1 per second (1 second delay between samples)

614 716 798 491 225 102 307 512 818 1003
3.0V 3.5V 3.9V 2.4V 1.1V .5V 1.5V 2.5V 4.0V 4.9V
5.0--- x
Input Voltage (V)

4.0--- x x
x
3.0--- x
x x
2.0---
x
1.0--- x
x
| | | | | | | | | |
1 2 3 4 5 6 7 8 9 10
Time (s)
Sampling Rate
In this example, the sampling rate changes as the delay() value changes. When the input
value is greater, the delay is longer, and the sampling rate is slower.
Schematic and Wiring
a Potentiometer
Schematic Symbol
for Potentiometer
Since it is a variable resistor with two
outputs, the symbol looks like a resistor
with an extra output.
Notice:
Voltage In
Voltage Out (to Analog In)
Ground
Wiring a POT with a breadboard

.. .. .. .. .. .. .. .. .. .. .. .. .
.+-. ..... ..... .
GND ..
13
12 .. .. .. .. .. .. .. .. .. .. .. .. ..
~11 .. . ..... ..... .
~10
~9 ..
5V
8 .. .. .. .. .. .. .. .. .. .. .. .. ..
GND
7
~6 .. . ..... ..... .
..
A0
~5
4 .. .. .. .. .. .. .. .. .. .. .. .. ..
A1
A2
~3
2 .. . ..... ..... .
A3 1 ..
A5 0
.. .. .. .. .. .. .. .. .. .. .. .. ..
.. . ..... ..... .
..
.. .. .. .. .. .. .. .. .. .. .. .. ..
.. . ..... ..... .
..
.. .. .. .. .. .. .. .. .. .. .. .. ..
.. . ..... ..... .
..
.. .. .. .. .. .. .. .. .. .. .. .. ..
.. . ..... ..... .
..

You might also like