شحن مجاني للأوردرات فوق
1000 ج
رمضان كريم
Hall-Effect Based AC/DC Current Measurement for Arduino Projects
The ACS712 is a hall-effect based current sensor that can measure both AC and DC currents up to ±5A. It provides analog output proportional to the measured current, making it ideal for energy monitoring, motor control, and over-current protection applications.
Measures both AC and DC currents
Analog output (66mV/A sensitivity)
2.1kV RMS voltage isolation
80mA output noise typical
| Current Range | ±5A |
|---|---|
| Sensitivity | 185-190mV/A (typical) |
| Zero Current Output | VCC/2 (2.5V at 5V supply) |
| Operating Voltage | 4.5V – 5.5V DC |
| Bandwidth | 80kHz |
| Isolation Voltage | 2.1kV RMS |
| Accuracy | ±1.5% at 25°C |
| Dimensions | 31mm × 13mm × 10mm |

| Pin | Function | Arduino Connection |
|---|---|---|
| VCC | Power Supply (5V) | 5V |
| GND | Ground | GND |
| OUT | Analog Output | A0 |
| IP+ | Current Input + | Load positive |
| IP- | Current Input – | Load negative |

// Basic Connections: // VCC → 5V // GND → GND // OUT → A0 // IP+ → Load positive // IP- → Load negative
const int sensorPin = A0;
const float mVperAmp = 185.0; // Sensitivity for 5A model
const float vRef = 5.0; // Arduino reference voltage
const int adcResolution = 1023; // 10-bit ADC
void setup() {
Serial.begin(9600);
}
void loop() {
float voltage = (analogRead(sensorPin) * vRef) / adcResolution;
float zeroVoltage = vRef / 2; // 2.5V at no current
float current = (voltage - zeroVoltage) * 1000 / mVperAmp;
Serial.print("Voltage: ");
Serial.print(voltage, 3);
Serial.print("V\tCurrent: ");
Serial.print(current, 2);
Serial.println("A");
delay(1000);
}
const int samples = 200;
float offset = 2.5; // Zero current voltage (VCC/2)
void setup() {
Serial.begin(9600);
// Calibrate zero offset
float sum = 0;
for(int i=0; i<samples; i++) {
sum += analogRead(A0);
delay(1);
}
offset = (sum / samples) * (5.0 / 1023.0);
}
void loop() {
float maxI = 0, minI = 0;
for(int i=0; i<samples; i++) { float voltage = (analogRead(A0) * 5.0) / 1023.0; float current = (voltage - offset) * 1000 / 185.0; if(current > maxI) maxI = current;
if(current < minI) minI = current;
delay(1);
}
float peakToPeak = maxI - minI;
float rmsCurrent = peakToPeak / (2 * sqrt(2));
Serial.print("RMS Current: ");
Serial.print(rmsCurrent, 2);
Serial.println("A");
}
void checkOverCurrent() {
float current = getCurrent();
if(current > 4.0) { // 4A threshold
digitalWrite(13, HIGH); // Alert LED
Serial.println("OVER CURRENT!");
} else {
digitalWrite(13, LOW);
}
}
float calculatePower(float voltageSupply) {
float current = getCurrent();
return voltageSupply * current;
}
#define FILTER_SIZE 10
float filterBuffer[FILTER_SIZE];
int filterIndex = 0;
float filteredCurrent(float rawCurrent) {
filterBuffer[filterIndex] = rawCurrent;
filterIndex = (filterIndex + 1) % FILTER_SIZE;
float sum = 0;
for(int i=0; i<FILTER_SIZE; i++) {
sum += filterBuffer[i];
}
return sum / FILTER_SIZE;
}
No account yet?
Create an Account
Recent Comments