I am using an ACS712 connected to an arduino mega and a 12V actuonix LAC motor control board, however the values of current it is giving me are ridiculous, I am getting a current of 1A from a 12V 0.5A power supply, any ideas how to fix it?
The ACS712 is connected with the ground to the LAC at the positive terminal and the connection to the power supply ground at negative.
float currentcheck(int pinused){
int adc = analogRead(pinused);
float voltage = (adc/1023.0)*5;
float current = (voltage-2.5)/0.185;
return current;
}
That is probably using PWM to control the motor. If this is correct so are your readings. They reflect the current at sample time. You will have to integrate several reads over 1 cycle period to get a good approximation. This link should help: AC Current Measurement with ACS712 Sensor Module and Arduino PWM is extremly difficult to measure accurately. Instruments that do this are expensive.
float currentcheck(int pinused){
int adc = analogRead(pinused);
float voltage = (adc/1023.0)*5;
float current = (voltage-2.5)/0.185;
return current;
}
Try
float currentcheck(int pinused){
int adc = analogRead(pinused);
float voltage = ((float)adc/1023.0)*5.0;
float current = (voltage-2.5)/0.185;
return current;
}
This will ensure a correct evaluation of what you are trying to calculate.
The constants used in this snippet make little sense because we don't know exactly what your circuit is.
Congratulations for posting the code in the correct way, many first time users don't get that.
So it looks like you have read this How to get the best out of this forum but look at it again to see what other information you need to post as well.
Words don't cut it for describing a circuit, from your word salad it sounds like you are creating a dead short between your 12 and ground. We need to see a schematic, hand drawn is fine, don't try using any of the physical layout diagrams programs you see, these are not helpful at all.
It will also be good to post all your code, along with links to the components you bought, like the LAC motor control board and the ACS712.