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
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.
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!
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.
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..
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.
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.
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.