Current sensor conversion to real value

I use analog read code to see the conversion of my current sensor, current sensor that used is ACS712 30 Amps. The power supply that I used is DC 12V 5 amps. From the picture is the result of the current sensor using the monitor, could you please help me to find a code for finding the formula for real value of current flowing in the system because I wanto to use the value for the feedback value to make a movement for motor DC

#define Current_sensor A0 //The sensor analog input pin

float i;

void setup() {

Serial.begin(9600);
pinMode(Current_sensor, INPUT);

}

void loop() {
i = analogRead(Current_sensor);
Serial.println(i);
delay(100);

Hi @homey123 , welcome. It would help if you read the forum guidelines about how to post code etc.

Google is your friend here. I did a quick search for acs712 current sensor arduino and found several videos and guides for this device.

I did a quick Google search and found this:

It shows how to apply an offset to calibrate the unit - and also gives a bit on feedback on the liniarity of that particular sensor being "not the best"; not sure if that'll be of any operational significance for you.

Also, it's really helpful if you can format your sketch and post it here using tags; you can easily do that by doing a ctrl+T in the IDE to format it - ctrl+A to select everything - ctrl+shift+C to copy it to your clipboard all ready for the forum ... then ctrl+V to paste it into your post.

So it ends up looking like this:

#define Current_sensor A0 //The sensor analog input pin

float i;

void setup() {

  Serial.begin(9600);
  pinMode(Current_sensor, INPUT);

}

void loop() {
  i = analogRead(Current_sensor);
  Serial.println(i);
  delay(100);
}

Hope this helps.

A diagram of your test circuit would be a big help as we dont know what the results represent; are they with zero current, or a test current and if so how is the test current controlled?

does not usually mean it will ALWAYS deliver 5 amps!

https://forum.arduino.cc/t/how-to-make-a-schematic-you-can-post/675103/11

Also its polite to give a link to any components you are using - as shown by @anon12459472; although this is perhaps more use

1 Like

The ACS712 sensors give an analog output between 0 and Vdd with an offset of 0.5*Vdd. So if you feed the ACS712 5V, a current of 0 amps will give an output of around 0.5V. Furthermore, the datasheet outlines the sensitivity, which for the 30A version is 66mV/A. Hence, a 1 A current flowing from IP+ to IP- should produce an output of ca. 0.566V. You can scale this back to the range of your ADC and Aref to get a fairly good ballpark estimate of the digital values you can expect using AnalogRead etc.

For more accuracy, there are two things you can do:

  • Determine the actual offset on startup by interrupting the current through the ACS712 and measuring its output, and storing that value as its offset for later calculations.
  • Calibrate the slope/sensitivity of your individual sensor (they may vary a bit from specimen to specimen) by measuring the current using your Arduino/uC setup as well as with a known-accurate current meter. The rest is basic arithmetic.

Since the offset on the ACS712 is dependent on its supply voltage, it makes sense to use a very stable and absolute supply voltage.

Make that 2.5volt.

Easier to forget about "volt", and convert directly from A/D value to current.
Just subtract (about) 512 from the returned A/D value, and multiply with a 'magic' number to give you the right current readout.

float current = (analogRead(sensorPin) - 512) * 0.07317;

Note that you only have about 410 A/D values spread over 30Amps from this sensor.

Serial.print(current, 1); // one decimal place is all you get
Leo..

Not relevant if you use a ratiometric A/D (an Uno/Nano/Mega).
Leo..

Sorry about the .5/2.5 mishap. I was mixing up the 712 and the 713 for a bit and forgot editing the 0.5V

Re the ratiometric A/D: as long as both the ACS and the A/D use the same reliable, stable reference it's fairly straightforward, yes.

Well it just has to be the same, and stable enough on a timescale of microseconds (ie decoupled). That's the great advantage of ratiometry, no special voltage reference needed.

thank you for the response, but how the magic number comes from?

30Amp spread over 410 A/D values.
30 / 410 = 0.07371
Leo..

why don't we use 1023 instead of 512?

If you're talking about this:

The offset of the sensor is at 0.5* Vdd. That's around 511-512 if you read it with an Arduino's ADC pin with the Arduino's Aref set at Vdd and the Arduino + current sensor sharing the same Vdd.

Everyone please read more carefully the forum guidelines before posting or commenting.
Read, understand then post your comment

Thanks; in case I went wrong somewhere, could you please point it out? Things easily get lost in translation and I may have missed something essential.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.