const int POT_PIN = A0;
int lastRaw = -1; // stores previous reading
const int threshold = 1; // minimum change before printing
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(POT_PIN);
// Only update if the reading changed enough
if (abs(raw - lastRaw) >= threshold) {
lastRaw = raw;
float voltage = raw * (3.3 / 1023.0); // actual measured voltage (3.3V ADC)
float percent = (raw / 1023.0) * 100.0;
float expected5V = raw * (5.0 / 1023.0); // 5V equivalent
Serial.print("Voltage: ");
Serial.print(voltage, 2);
Serial.print("V | ");
Serial.print(percent, 1);
Serial.print("% | ");
Serial.print("5V Ref Equivalent: ");
Serial.print(expected5V, 2);
Serial.println("V");
}
delay(50);
}