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.
How often do you suppose an if statement gets followed, meaningfully, be a semicolon? In reality, virtually never.
When you post code and have a statement like "I'm trying...", it's generally a good idea to then talk about what problems you are having. What does that code do? What do you want it to do? How do those two differ?
I'm very new to Arduino and programming, sorry if my post was vague. I'm building a Replica large scale lightning and am trying to design some lightweight retractable undercarriage. My previous tests with jets have led to them disintegrating in flight due to lose items entering the airstream at speed. I want to use secure screwjack undercarriage retracts. I have engineered the mechanical side of the undercarriage but now need to control the motor driving the gear up and down.
I've trawled the net and found various older topics on Arduino and retracts and have been trying to utilise the code in these posts but i could do with some simple pointers.
I can get the motor (just one connected at the moment) to run and brake and reverse, but i'm uncertain of the code i need to make to motor to stop at the end of it's travel. I was hoping you might correct my if statement i know it's not right but can't see where i've gone wrong.
if (sensorValue<limit);
{digitalWrite (Bbrake,HIGH)
delay(5000);}/code]
Is this correct. I've tried this but i get an error 'expected ';' before delay'. i'm trying to get the motor to stop for 5 seconds.