使用ESP32采集压力传感器信号
·

esp32引脚及其对应的gpio口如图,本文采用esp32采集压力传感器的数值,

连接如图,传感器的一个引脚连接至gpio12,另一个引脚连接至3v3供电引脚
代码如下:
const int sensorPin = 34; // 模拟传感器接到 GPIO34(ADC1 通道6)
int sensorValue = 0; // 用于存储读取的值
void setup() {
Serial.begin(115200); // 初始化串口通信,用于调试
pinMode(sensorPin, INPUT); // 设置传感器引脚为输入模式
Serial.println("Sensor reading initialized...");
}
void loop() {
// 读取模拟值
sensorValue = analogRead(sensorPin);
// 输出读取的原始值到串口
Serial.print("Raw ADC Value: ");
Serial.println(sensorValue);
delay(1000); // 每秒读取一次
}
更多推荐
所有评论(0)