I am using a Arduino ,Servo motor(360degreee), a current sensor(ACS712,ACS758 LCB 050B),to measure the current drawn by the servo , i am trying it from many days unable to match current value by current sensor and DC power supply.
code i used
#include <Servo.h> // Includes the Servo library for controlling the servo motor
Servo myServo; // Creates an instance of the Servo class named myServo
const int servoPin = 7; // Digital pin connected to the servo
void setup() {
Serial.begin(9600); // Initializes serial communication at a baud rate of 9600
myServo.attach(servoPin); // Attaches the servo on pin 7 to the myServo object
}
void loop() {
static float sumCurrent = 0.0; // Variable to accumulate sum of current readings
static int count = 0; // Counter for number of readings
int adc = analogRead(A0); // Reads the analog value from pin A0
float voltage = adc * 5.0 / 1023.0; // Converts the ADC value to voltage
float current = (voltage - 2.5) / 0.066; // Converts the voltage to current (ACS712 sensor)
if (current < 0.16) {
current = 0; // Sets current to 0 if it is below a certain threshold
}
sumCurrent += current; // Accumulates current readings
count++; // Increments the count of readings
if (count == 40) { // After accumulating 40 readings
float averageCurrent = sumCurrent / count; // Computes the average current
Serial.print("Average current of 10 readings: ");
Serial.println(averageCurrent + 0.16); // Prints the average current
delay(20); // Waits for 20 milliseconds
sumCurrent = 0.0; // Resets the sumCurrent variable
count = 0; // Resets the count variable
}
myServo.write(180); // Sets servo speed to rotate continuously in one direction
// Uncomment the line below if you also want to print individual current readings
// Serial.println(current);
}
please tell me what to do to match the current values