Hi im trying to make a servo motor stop if my current sensor gives X amperage output. Im using a ACS712-5 current sensor with and a MG99R motor. But I cant seem to figure out how to make the input from the sensor a stop sign to the servo.
i want the servo to turn towards a 148 degree but stop if resistance occours.
#define acs712 A0
float vpp = 0.0048828125;
float senstivity = 0.666; //mv
#include <Servo.h>;
const int buttonPin = 8;
const int servoPin = 9;
Servo servo;
int counter = 0;
void setup() {
servo.attach (servoPin);
pinMode(buttonPin, INPUT);
pinMode(acs712, INPUT);
Serial.begin(9600);
}
void loop() {
int counts = analogRead(acs712) + 1;
float voltage = counts * vpp;
voltage -= 2.5;
float amperage = voltage / senstivity;
Serial.println("amps:" + String(amperage));
int buttonState;
if (buttonState == LOW)
{
counter ++;
delay(150);
}
if (amperage > 0.2);
else if(counter == 0)
servo.write (0); // zero degrees
else if(counter == 1)
servo.write(148);
else
counter = 0;
}