Hello everyone.
I am trying to measure the current drawn by brushless motor using current sensor ACS712 30A and arduino. I am generating PWM signals using arduino but I am getting no pattern in the current values. Can someone please guide me about this?
I am attaching my code and the circuit diagram.
If you are appliying pwm pulses to the motor its not really a surprise you are seeing strange results from the current sensor. Especially as you dont seem to have any flyback protection.
float vpp = 0.0048828125;
//where did this silly number come from? the ADC has a max resolution of 0.1%
float sensitivity = 0.066; //mv
This is how you should include your code
// type servo position 0 to 180 in serial monitor
// for IDE 0022 and later
String readString;
#define acs712 A0
#include <Servo.h>
Servo myservo; // create servo object to control a servo
float vpp = 0.0048828125;
float sensitivity = 0.066; //mv
void setup() {
Serial.begin(9600);
pinMode(acs712,INPUT);
myservo.attach(9); //the pin for the servo control
Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}
void loop() {
int counts = analogRead(acs712);
float voltage = counts * vpp;
voltage-=2.5;
float amperage = voltage/sensitivity;
Serial.println("Amps: " + String(amperage));
delay(1000);
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured string
int n = readString.toInt(); //convert readString into a number
// auto select appropriate value
if(n <= 500)
{
Serial.print("writing Angle: ");
Serial.println(n);
myservo.write(n);
}
readString=""; //empty for next input
}
}
Also I am generating the PWM signal through the code. By entering a value I can increase or decrease the on time of the PWM signal and thus I can control the speed of the motor.
Can you guide e about the flyback protection?
The value you read from the adc has around 3 diigit precision (eg 9.99)
you CANT get more. So this 0.0048828125; would more sensibly be 0.00488;
Also I am generating the PWM signal through the code. By entering a value I can increase or decrease the on time of the PWM signal and thus I can control the speed of the motor.
Make this simple = measure voltage on 0.1 ohm (or smaller, made from non copper/ aluminium wire ....) resistor, connected between ground and motor, to protect arduino and eliminate the noise feed A0 trough 1k resistor also connect to A0 zener diode 5V and 1uF capacitor.
Sounds like you need to troubleshoot this one a bit, just break it down into parts and make sure those are working.
Start with simple code that just sets the servo to a value and display the value read from the ACS712. Don't worry about calculations or inputting data thru the serial monitor, that only complicates things. I would start with a servo value of 0, which I assume is off for the motor, and note the readings from the ACS712, which should be nothing. Then try a servo value of 90, which I would assume would be half throttle. What are the ACS712 readings? Set the servo to 180, which should be full throttle, and check the ACS712 readings again. If the ACS712 is functioning correctly, you should see some relationship between the values of the reading at 0 throttle, half throttle, and full throttle. Once this is working, then you can move on to calculations and such.
Of course, having a multimeter hooked up to measure current would also be useful.