頁:
[1]
arduino程式問題
本帖最後由 RMine 於 2018-5-7 09:25 PM 編輯這是利用"ZMPT101B"電壓感測器來量測125VAC的整個程式
double sensorValue=0;
double sensorValue1=0;
int crosscount=0;
int climbhill=0;
double VmaxD=0;
double VeffD;
double Veff;
void setup() {
Serial.begin(115200);
}
void loop() {
sensorValue1=sensorValue;
delay(100);
sensorValue = analogRead(A0);
if (sensorValue>sensorValue1 && sensorValue>511){
climbhill=1;
VmaxD=sensorValue;
}
if (sensorValue<sensorValue1 && climbhill==1){
climbhill=0;
VmaxD=sensorValue1;
VeffD=VmaxD/sqrt(2);
Veff=(((VeffD-420.76)/-90.24)*-210.2)+210.2;
Serial.println(Veff);
VmaxD=0;
}
}
在實際測試方面已確認過接線無誤,也用電表量測過確定進來的電壓是125VAC,但不知道為什麼在arduino的序列埠上就是抓不到VAC的量測值,已知從數位轉類比後需要在校整公式但是反覆測試就是沒有結果....求指導
...<div class='locked'><em>瀏覽完整內容,請先 <a href='member.php?mod=register'>註冊</a> 或 <a href='javascript:;' onclick="lsSubmit()">登入會員</a></em></div><div></div> 臺灣交流電的頻率是多少.... 100ms 量一次 會不會太慢了? this post is quite old but i am not sure whether u still need comment or not.
the logic looks fine for me except the variable declaration part.
change the DOUBLE sensorvalue to INT might help.
use typecasting if u want to change INT to DOUBLE.
頁:
[1]