ESP32 Learn

ADC: Read Potentiometer & Filtering

2025-09-20 路 ~1 min read
Table of contents
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <Arduino.h>

const int PIN = 34;
int readAvg() {
  long s = 0;
  for (int i = 0; i < 16; i++) {
    s += analogRead(PIN);
    delay(2);
  }
  return s / 16;
}
void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
}
void loop() {
  Serial.println(readAvg());
  delay(200);
}

馃敄 #adc #analog #filter