1

I am trying to run a linear actuator with a BTS7960 motor driver and an Arduino UNO.

The code seems fine, wiring seems fine but after uploading the code, the linear actuator does not start.

I am using two push buttons to extend and retract the actuator.

The code is shown below:

byte mspeed=0;
int RPWM = 5;
int LPWM = 6;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(13, OUTPUT);

pinMode(RPWM,OUTPUT);
pinMode(LPWM,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if( digitalRead(2) == LOW & digitalRead(4) == HIGH ){
mspeed = 255;
analogWrite(RPWM,0);
analogWrite(LPWM, mspeed);
digitalWrite(13,HIGH);
}
else if( digitalRead(2) == HIGH & digitalRead(4) == LOW ){
mspeed = 255;
analogWrite(RPWM,mspeed);
analogWrite(LPWM, 0);
digitalWrite(13,LOW);
}
else{
analogWrite(RPWM,0);
analogWrite(LPWM, 0);
}

}

See the circuit diagram which i am following

JRE
  • 67,678
  • 8
  • 104
  • 179
Muskaan
  • 23
  • 2
  • 2
    your program contains no debugging code, so you don't actually know if it is doing what you think it is doing .... add a bunch of `Serial.print()` statements throughout your code and watch the execution progress on the serial monitor – jsotola May 22 '21 at 17:52
  • 1
    Hint: understand the difference between & and &&. Look at one of your if statements. As @jsotola suggests, perform some debugging. Don’t expect to write a lump of code and have it work perfectly. Debugging is an essential skill. – Kartman May 22 '21 at 22:53

0 Answers0