電流 - 檢測:20A 通道數:1 輸出:比率,電壓 靈敏度:100mV/A 線性度:±1.5% 精度:±1.5% 響應時間:5μs 電流 - 電源(最大值):13mA
const int analogInPin = A0;
// 樣本數量:樣本越多出來的數值越平均,但是要注意緩沖區溢出
const int avgSamples = 10;
int sensorValue = 0;
float sensitivity = 100.0 / 500.0; //每500mV 100mA = 0.2
float Vref = 2500; // 沒電流時模塊io的輸出電壓: ~ 2500mV or 2.5V
void setup() {
//初始化串口通信:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
for (int i = 0; i < avgSamples; i++)
{
sensorValue += analogRead(analogInPin);
delay(2);// 等待2微秒,緩沖時間
}
sensorValue = sensorValue / avgSamples;
// 內置ADC精度是10位 -> 2^10 = 1024 -> 5V / 1024 ~= 4.88mV
float voltage = 4.88 * sensorValue;
// 計算實際電流 (mA)
float current = (voltage - Vref) * sensitivity;
Serial.print(voltage); //打印電壓
Serial.print("mV");
Serial.print(current); //打印電流
Serial.print("mA");
Serial.print("
");
sensorValue = 0; // 重置讀數
}
!注意:請使用瀏覽器自帶下載,迅雷等下載軟件可能無法下載到有效資源。
歡迎加入EEWorld參考設計群,也許能碰到搞同一個設計的小伙伴,群聊設計經驗和難點。 入群方式:微信搜索“helloeeworld”或者掃描二維碼,備注:參考設計,即可被拉入群。 另外,如您在下載此設計遇到問題,也可以微信添加“helloeeworld”及時溝通。
EEWorld Datasheet 技術支持