Arduino ACS712 Current Sensor
The ACS712 is a very easy to use bi-directional current sensor. It comes
in 5, 20, and 30 amp versions, and there's only one line of code that needs
to be changed depending on which unit you have. This sensor outputs a small
voltage that increases with current flowing through the sensor. It isolates the
current being monitored from the Arduino, so there's no risk to the Arduino.
Most breakout boards come with the needed resistors and caps already installed,
so physical hookup consists of +5vdc, gnd, and analog out to one of the
Arduino analog inputs. The polarity sensitive current sense pins connect in
series with one of the power wires to the device being monitored
(either production, or consumption).
In the picture above, looking at the lower right image, the left terminal is
the more positive terminal, and the right terminal is the more negative terminal.
If you reverse these, you will see negative current readings when you expect
positive current readings.
Alternative method, using a shunt!
Parts needed:
Arduino UNO
ACS712 5a (20a, or 30a options)
ACS712 Datasheet
Code:
/*
Measuring Current Using ACS712
*/
const int analogIn = A0;
int mVperAmp = 185;
// use 185 for 5A Module, 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
RawValue = analogRead(analogIn);
Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);
Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(RawValue);
Serial.print("\t mV = ");
// shows the voltage measured
Serial.print(Voltage,3);
// the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = ");
// shows the voltage measured
Serial.println(Amps,3);
// the '3' after voltage allows you to display 3 digits after decimal point
delay(2500);
}
http://henrysbench.capnfatz.com/henrys-bench/acs712-current-sensor-user-manual/
The ACS712 is a very easy to use bi-directional current sensor. It comes
in 5, 20, and 30 amp versions, and there's only one line of code that needs
to be changed depending on which unit you have. This sensor outputs a small
voltage that increases with current flowing through the sensor. It isolates the
current being monitored from the Arduino, so there's no risk to the Arduino.
Most breakout boards come with the needed resistors and caps already installed,
so physical hookup consists of +5vdc, gnd, and analog out to one of the
Arduino analog inputs. The polarity sensitive current sense pins connect in
series with one of the power wires to the device being monitored
(either production, or consumption).
In the picture above, looking at the lower right image, the left terminal is
the more positive terminal, and the right terminal is the more negative terminal.
If you reverse these, you will see negative current readings when you expect
positive current readings.
Alternative method, using a shunt!
Parts needed:
Arduino UNO
ACS712 5a (20a, or 30a options)
ACS712 Datasheet
Code:
/*
Measuring Current Using ACS712
*/
const int analogIn = A0;
int mVperAmp = 185;
// use 185 for 5A Module, 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
RawValue = analogRead(analogIn);
Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);
Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(RawValue);
Serial.print("\t mV = ");
// shows the voltage measured
Serial.print(Voltage,3);
// the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = ");
// shows the voltage measured
Serial.println(Amps,3);
// the '3' after voltage allows you to display 3 digits after decimal point
delay(2500);
}
http://henrysbench.capnfatz.com/henrys-bench/acs712-current-sensor-user-manual/
No comments:
Post a Comment