Week 9: Input Devices

As a test for my final project, I decided to measure the value of a potentiometer as a proxy for angle. I repurposed by board from a couple weeks ago with a potentiometer soldered on. The potentiometer takes power and ground from the same source as the board and just connects the middle pin to an ADC pin on the board.



All the board needs to do is read the analog input on the data pin and apply the appropriate linear conversion to convert the reading to an angle. Note that even though the potentiometer runs from 0 to 9k/10k, the value measured at the pin is the voltage which ranges between 0 and 5v. That value is then converted to the range from 0 to 1023 by the 10 bit ADC. Due to inaccuracies in the circuit and the components, the exact midpoint of the measurement and the scaling may need to be adjusted.
void setup() {
  Serial.begin(115200);
  pinMode(DATA_PIN, INPUT);
}

void loop() {
  Serial.println(90 + (analogRead(DATA_PIN) - 512)*0.26);
}