Current - Detection: 20A Number of Channels: 1 Output: Ratio, Voltage Sensitivity: 100mV/A Linearity: ±1.5% Accuracy: ±1.5% Response Time: 5μs Current - Power Supply (Max): 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; // 重置读数
}
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet