ACS712 30A current sensor

Hello all,

I’m having trouble with my current sensor. I have acs712 30A current sensor. And after uploading the code the serial monitor & serial plotter only shows a negative voltage and does change at all after turning on the power.

/*
 * 
 * Arduino Sketch for Allegro ACS712 Current Sensor 
 * this sensor can measure current at range of up to 30A
 * It operates with 5V
 * Please watch video instruction and explanation for this code.
 * 
 * Written by Ahmad Shamshiri on Sunday Jun 17, 2018 at 22:06 at Ajax, Ontario, Canada
 * for Robojax.com
 * View the video instruction at https://youtu.be/DVp9k3xu9IQ
 * This code has been downloaded from Robojax.com
 */
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const float VCC   = 5.0;// supply voltage is from 4.5 to 5.5V. Normally 5V.
const int model = 2;   // enter the model number (see below)

float cutOffLimit = 1.01;// set the current which below that value, doesn't matter. Or set 0.5

/*
          "ACS712ELCTR-05B-T",// for model use 0
          "ACS712ELCTR-20A-T",// for model use 1
          "ACS712ELCTR-30A-T"// for model use 2  
sensitivity array is holding the sensitivy of the  ACS712
current sensors. Do not change. All values are from page 5  of data sheet          
*/
float sensitivity[] ={
          0.185,// for ACS712ELCTR-05B-T
          0.100,// for ACS712ELCTR-20A-T
          0.066// for ACS712ELCTR-30A-T
     
         }; 


const float QOV =   0.5 * VCC;// set quiescent Output voltage of 0.5V
float voltage;// internal variable for voltage

void setup() {
    //Robojax.com ACS712 Current Sensor 
    Serial.begin(9600);// initialize serial monitor
    Serial.println("Robojax Tutorial");
    Serial.println("ACS712 Current Sensor");
}

void loop() {
  

  //Robojax.com ACS712 Current Sensor 
  float voltage_raw =   (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
  voltage =  voltage_raw - QOV + 0.012 ;// 0.000 is a value to make voltage zero when there is no current
  float current = voltage / sensitivity[model];
 
  if(abs(current) > cutOffLimit ){
    Serial.print("V: ");
    Serial.print(voltage,3);// print voltage with 3 decimal places
    Serial.print("V, I: ");
    Serial.print(current,2); // print the current with 2 decimal places
    Serial.println("A");
  }else{
    Serial.println("No Current");
  }
  delay(500);
}

how did you wire the sensor to your arduino (and which arduino).
how do you modify the current ?

what do you see (in the console set at 115200 bauds) if you run this:

#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
void setup() {
    Serial.begin(115200);// initialize serial monitor
    Serial.println("Robojax Tutorial");
    Serial.println("ACS712 Current Sensor");
}

void loop() {
  float voltage_raw =   (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
  Serial.println(voltage_raw);
  delay(500);
}

just noticed your images:

A

B

C:

the display does not match the code you have, there should be no new line before the 'A' since you said you print with

    Serial.print(current,2); // print the current with 2 decimal places
    Serial.println("A");

did you share your real code?

I made the changes and the only difference is that now I have a positive waveform. I apologize I did make adjustments to the code I can from another source. The first code is the one I used with a baud rate modification and the second is yours. I also have the vcc pin connected to 5v, the gnd connected to gnd, and A0 connected to out (on the sensor) of a arduino uno.

When I connect A0 to the out (pin of sensor) with my code the serial plotter outputs no current. Could there be an issue with my pin connection. When I disconnect it the serial plotter outputs image e. Image d is the output of your code. :o

Thank

/*
 * 
 * Arduino Sketch for Allegro ACS712 Current Sensor 
 * this sensor can measure current at range of up to 30A
 * It operates with 5V
 * Please watch video instruction and explanation for this code.
 * 
 * Written by Ahmad Shamshiri on Sunday Jun 17, 2018 at 22:06 at Ajax, Ontario, Canada
 * for Robojax.com
 * View the video instruction at https://youtu.be/DVp9k3xu9IQ
 * This code has been downloaded from Robojax.com
 */
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const float VCC   = 5.0;// supply voltage is from 4.5 to 5.5V. Normally 5V.
const int model = 2;   // enter the model number (see below)

float cutOffLimit = 1.01;// set the current which below that value, doesn't matter. Or set 0.5

/*
          "ACS712ELCTR-05B-T",// for model use 0
          "ACS712ELCTR-20A-T",// for model use 1
          "ACS712ELCTR-30A-T"// for model use 2  
sensitivity array is holding the sensitivy of the  ACS712
current sensors. Do not change. All values are from page 5  of data sheet          
*/
float sensitivity[] ={
          0.185,// for ACS712ELCTR-05B-T
          0.100,// for ACS712ELCTR-20A-T
          0.066// for ACS712ELCTR-30A-T
     
         }; 


const float QOV =   0.5 * VCC;// set quiescent Output voltage of 0.5V
float voltage;// internal variable for voltage

void setup() {
  // put your setup code here, to run once:
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  //Robojax.com ACS712 Current Sensor 
  Serial.begin(115200);// initialize serial monitor
  Serial.println("Robojax Tutorial");
  Serial.println("ACS712 Current Sensor");
}

void loop() {
  // put your main code here, to run repeatedly:
 digitalWrite(6, HIGH);
 digitalWrite(5, HIGH);
 delay(3000);

 
  digitalWrite(6, LOW);
  digitalWrite(5,LOW);
  delay(1000);

//Robojax.com ACS712 Current Sensor 
  float voltage_raw =   (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
  voltage =  voltage_raw - QOV + 0.012 ;// 0.000 is a value to make voltage zero when there is no current
  float current = voltage / sensitivity[model];
 
  if(abs(current) > cutOffLimit ){
    Serial.print("V: ");
    Serial.println(voltage,3);// print voltage with 3 decimal places
    Serial.print("V, I: ");
    Serial.println(current,2); // print the current with 2 decimal places
    Serial.println("A");
  }else{
    Serial.println("No Current");
  }
  delay(500);

}
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
void setup() {
    // put your setup code here, to run once:
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
    Serial.begin(115200);// initialize serial monitor
    Serial.println("Robojax Tutorial");
    Serial.println("ACS712 Current Sensor");
}

void loop() {
  float voltage_raw =   (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
  Serial.println(voltage_raw);
   digitalWrite(6, HIGH);
 digitalWrite(5, HIGH);
 delay(3000);

 
  digitalWrite(6, LOW);
  digitalWrite(5,LOW);
  delay(1000);
  delay(500);
}

Image D:

seems to show that you are at 2.5V, which means indeed no current is read from the sensor.

what are you measuring? what's connected to the board?

im powering a switched reluctance motor through the current sensor. Over 10amps is going through the sensor and motor is working.

How did you wire things up?

I have my phase current wire connected through my current sensor. Is it possible that the sensor will detect the current that will go through the sensor without even powering it. That sounds ridiculous, but I dont know why there is no change in the sensed current after power is turned on.

This device is a Hall Effect transducer. It should not be used near significant magnetic fields. Is your motor or the sensor protected ?

The motor power rating is 20v 12A. The motor just has coils on the stator no magnets.

Is it an AC motor?

No DC. Its a switched reluctance motor. Kind of like a stepper motor. Only windings in stator.

your images (seem both the same)

12A is huge.. be super careful with your wires hanging like this without any protection...

have you considered a faulty component? do you have another one to test against?

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Everything works fine i just cant get an accurate phase current waveform to show on serial plotter.

The diode should be in parallel with the motor, cathode (end with band) toward + (the ACS712), NOT in series with the transistor. I can't see how you are getting ANY current (unless something is breaking down or shorted).

The diode is probably blown.

@aarg: New makeup I see, :o

Hi,
A complete diagram please showing the controller and how you have got the controller, MOSFET and DC supply wired together.

The motor being on a different DC supply to the Arduino do you have a common gnd connection?


Tom.. :slight_smile: