Anyone help please.
I'm trying to write code that will enable me to control a motor using stall current. I have an UNO and motor shield R3. Here's my code i'm working on. I'm trying to read the pin A1 and if the current is above.4amp i want to shut the motor down.
int Bbrake=8;//brake signal for motor B
int Abrake=9;//brake signal for motor A
int motorspdB=11;//PWM speed signal for motor B
int motorspdA=3;//PWM speed signal for motor A
int motorA=12;
int motorB=13;
//int limit=A0
void setup () {
// int sensorValue=analogRead(A1);
pinMode(A1,INPUT);//motor current monitor B
pinMode(A0,INPUT);//motor current monitor A
pinMode (13, OUTPUT);//motor B enable and direction HIGH or LOW
pinMode (12, OUTPUT);//motor A enable and direction HIGH or LOW
pinMode (8, OUTPUT);//Brake motor B
pinMode (9, OUTPUT);//Brake motor A
// int Current = 0; //Value of current
Serial.begin(9600);
}
void loop () {
int sensorValue=analogRead(A1);
int limit =100; //Value that triggers motor to shutoff once it has reached endpoint
analogWrite (motorspdB,255);
digitalWrite (motorB,HIGH);
digitalWrite (Bbrake,LOW);
delay(2000);
Serial.println(sensorValue);
if (sensorValue<limit);
{digitalWrite (Bbrake,HIGH);
delay(5000);}
// digitalWrite (Bbrake,LOW);
// delay(5000);
digitalWrite (motorB,LOW);
digitalWrite (Bbrake,LOW);
delay(3000);
digitalWrite (Bbrake,HIGH);
delay (1000);
// Serial.println(sensorValue);
}/code]
The motors running backwards and forwards for now but i want to develop the if statement to take into account current.