hhhwwwyyy 发表于 2017-4-5 16:16:19

【求教】关于Arduino用模拟口读取电压问题

请教各路大神!小弟通过电流转电压模块把4-20mA电流转成0-5V电压,然后通过Arduino的模拟口接受,并把采集的电压在串口监视器上显示。遇到的问题:串口监视器上的接受的电压都为0!!以下是程序代码、模块说明及结果截图,麻烦大神们帮我看看问题出错在哪???
连线的话是电流转电压模块VOUT接Arduino的模拟口A0,模块gnd与板子GND连接(模块要另外24V电源供电)。
int potPin = A0;                     //设置模拟口0为sensor的信号输入端口
long val = 0;                     //设置val为长整型变量
float T;                            //设置电压为浮点型变量

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(potPin,INPUT);
delay(2000);
}

void loop() {
// put your main code here, to run repeatedly:
   val=analogRead(potPin);
   T = (val/1023*5.00);
   Serial.print("T_sensor=");
   Serial.print(T);
   Serial.println(" V");
   delay(3000);
}

弘毅 发表于 2017-4-6 09:15:40

pinMode(potPin,INPUT);这一句是不需要的

hhhwwwyyy 发表于 2017-4-6 10:21:10

弘毅 发表于 2017-4-6 09:15
pinMode(potPin,INPUT);这一句是不需要的

恩恩是的 谢谢弘毅老大提醒,我知道原因了我主要错的是15行的数据类型 尴尬。。。

eagler8 发表于 2019-7-20 17:34:44

/*
【Arduino】66种传感器模块系列实验(62)
实验六十二:电压检测模块 Voltage Sensor 电压传感器
试试看波形如何
*/

void setup()
{
Serial.begin(9600);
}
void loop()
{
      int val;
      float temp;
      val=analogRead(0);
      temp=val/40.92;
      val=(int)temp;
      Serial.println(val);
      delay(1000);
}

eagler8 发表于 2019-7-20 17:35:19

页: [1]
查看完整版本: 【求教】关于Arduino用模拟口读取电压问题