(Reference) Potentiometers
Potentiometers
Potentiometer (Pot)
Wiring
- Requires analog input pin
A0
A1
A2
A5
A3
(SDA
or D0
)
A4
(SCL
or D1
)
Operation
- As you turn the knob, Photon 2 will measure a voltage change on analog input (due to voltage divider)
- Since this is an analog input, we use analog to digital conversion to read input
- Voltage on pin will varies 0v to 3.v, and Photon 2 will read 0 to 4095
Code
const int PIN_POT = A0; //input pin
int potValue = 0; //value from read
void setup() {
pinMode(PIN_POT, INPUT);
}
void loop() {
// read analog value (ADC); range 0-4095
int potValue = analogRead(PIN_POT);
// if you want to know the actual voltage
int voltage = (float) lightReading / 4095 * 3.3;
}
Credit