基本信息
源码名称:红外测距Arduino.ino
源码大小:0.43KB
文件格式:.ino
开发语言:C/C++
更新时间:2021-04-11
   源码介绍
float cm = 0.0;
const int analogPin = A1;
void setup()
{
  Serial.begin(9600);
  pinMode(analogPin, INPUT);
}

void loop()
{
  cm = (float)analogRead(analogPin); //读取模拟端口数值
  cm = (cm * 5) / 1023.0; //将数值还原为模拟电压值
  cm = 26.928 * pow(cm, -1.217) 1.9; //转换为距离,单位CM
  if (cm < 80.0 && cm > 6.0)
    Serial.print(cm);//串口输出
  Serial.print("cm");
  Serial.println();
  delay(1000);
}