Hi, I'm trying to use the ACS 712 sensors to measure current.
ACS712ELC-30A
I got the 30 amp version to make the current testing rig future proof.
Most of what I'm currently measuring though will be under 1 amp.
I didn't know that the analog values represent a certain set of mV values which are different based on each sensor model.
I changed the mVperAmp value to the value used for the 5 amp version of the sensor.
Although I don't think this is a practical fix I wanted to try it out.
Based on surfing the web and looking at other forum posts the values below are used to measure the current on the respective sensor models:
//use 185 for 5A Module, 100 for 20A Module, and 66 for 30A Module
I have 2 main issues:
-
My current ratings are not fluctuating on the serial monitor when the cycle is turning on.
I've offset the ACSoffset value to get an initial current rating of ~ 0 amps, but even with the ports on
and one solenoid attached to it, the current does not fluctuate. -
I'm turning on and off 8 relays at the same time.
With my current code setup when the cycle count is over the relays turn off.
However, with the code setup like shown below my cycle count is off by 1.
If I start the cycle count with the port on then the count is right but it won't turn off after the cycle is
over. I tried placing a port off code outside of the for loop and it still wouldn't turn off. So basically the
relays stay on and I don't want that after the cycle is complete.
PORTA = B00000000;
delay(TOff); //delay between turning off each relay
PORTA = B11111111;
delay(TOn); //delay between turning on each relay
#include <LiquidCrystal.h>
#include <MenuBackend.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
// read the buttons
int read_LCD_buttons() {
adc_key_in = analogRead(8);
// read the value from the sensor
// my buttons when read are centered at these values: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
/****************************************************************************/
int TOn = 1000; //analogRead(1)*4; // Adjust delay time in milliseconds to turn relay on/off
int TOff = 200; //analogRead(2)*4;
/* Measuring DC Current Using ACS712 */
double mVperAmp = 185; // use 185 for 5A Module, 100 for 20A Module, and 66 for 30A Module
float ACSoffset = 2470.345;
double RawValue1 = 0;
double RawValue2 = 0;
double RawValue3 = 0;
double RawValue4 = 0;
double RawValue5 = 0;
double RawValue6 = 0;
double RawValue7 = 0;
double RawValue8 = 0;
double V1 = 0;
double V2 = 0;
double V3 = 0;
double V4 = 0;
double V5 = 0;
double V6 = 0;
double V7 = 0;
double V8 = 0;
double Amps1 = 0;
double Amps2 = 0;
double Amps3 = 0;
double Amps4 = 0;
double Amps5 = 0;
double Amps6 = 0;
double Amps7 = 0;
double Amps8 = 0;
const int S1 = A0; // Analog input pin that sensor is attached to
const int S2 = A1;
const int S3 = A2;
const int S4 = A3;
const int S5 = A4;
const int S6 = A5;
const int S7 = A6;
const int S8 = A7;
void setup () {
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.setCursor(0, 0); // set printing position on lcd screen, currently that is row 0, column 0)
lcd_key = read_LCD_buttons(); // read the buttons
Serial.begin(9600);
pinMode(S1, INPUT);
pinMode(S2, INPUT);
pinMode(S3, INPUT);
pinMode(S4, INPUT);
pinMode(S5, INPUT);
pinMode(S6, INPUT);
pinMode(S7, INPUT);
pinMode(S8, INPUT);
DDRA = B11111111; // set PORTA (digital 22-29) to outputs
int maxnumber = 10; // set cycle count
for (int count = 0; count < maxnumber;) //Counter will stop counting after certain amount of cycles
{
PORTA = B00000000;
delay(TOff); //delay between turning off each relay
PORTA = B11111111;
delay(TOn); //delay between turning on each relay
RawValue1 = analogRead(S1);
RawValue2 = analogRead(S2);
RawValue3 = analogRead(S3);
RawValue4 = analogRead(S4);
RawValue5 = analogRead(S5);
RawValue6 = analogRead(S6);
RawValue7 = analogRead(S7);
RawValue8 = analogRead(S8);
V1 = (RawValue1 / 1023.0) * 5000; // Gets you mV
V2 = (RawValue2 / 1023.0) * 5000;
V3 = (RawValue3 / 1023.0) * 5000;
V4 = (RawValue4 / 1023.0) * 5000;
V5 = (RawValue5 / 1023.0) * 5000;
V6 = (RawValue6 / 1023.0) * 5000;
V7 = (RawValue7 / 1023.0) * 5000;
V8 = (RawValue8 / 1023.0) * 5000;
Amps1 = ((V1 - ACSoffset) / mVperAmp);
Amps2 = ((V2 - ACSoffset) / mVperAmp);
Amps3 = ((V3 - ACSoffset) / mVperAmp);
Amps4 = ((V4 - ACSoffset) / mVperAmp);
Amps5 = ((V5 - ACSoffset) / mVperAmp);
Amps6 = ((V6 - ACSoffset) / mVperAmp);
Amps7 = ((V7 - ACSoffset) / mVperAmp);
Amps8 = ((V8 - ACSoffset) / mVperAmp);
Serial.println("Amps1 = "); // shows the voltage measured
Serial.println(Amps1, 3); // the '2' after voltage allows you to display 2 digits after decimal point
Serial.println("Amps2 = ");
Serial.println(Amps2, 3);
Serial.println("Amps3 = ");
Serial.println(Amps3, 3);
Serial.println("Amps4 = ");
Serial.println(Amps4, 3);
Serial.println("Amps5 = ");
Serial.println(Amps5, 3);
Serial.println("Amps6 = ");
Serial.println(Amps6, 3);
Serial.println("Amps7 = ");
Serial.println(Amps7, 3);
Serial.println("Amps8 = ");
Serial.println(Amps8, 3);
Serial.println("");
lcd.clear(); //clears lcd before incrementing to next number
count++;
lcd.print(count);
}
}
void loop() {
}