ESP32(三) Arduino ADC

需求

1.ESP32 读取模拟量
2.串口上传模量量

配方

  • esp wroom 32
  • arduino环境
  • 电脑
  • usb线

硬件连接

在这里插入图片描述

源码

// 电位器连接到GPIO 34(模拟ADC1_CH6)
const int potPin = 34;

// 用于存储电位器值的变量
int potValue = 0;

void setup() {
  Serial.begin(115200);
  delay(1000);
}

void loop() {
  // 读取电位计值
  potValue = analogRead(potPin);
  Serial.println(potValue);
  delay(100);
}

操作

1.连接esp32板子
2.烧录
3.打开串口助手并设定好波特率连接
4.串口助手观察到以下讯息
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/bayinglong/article/details/126671939