My project is a 24v mini linear actuator , two momentary push buttons, dual channel 5v relay, Arduino Uno, AC to DC 12v power supply 5A
a single press of Push Button 1 moves the linear actuator in one direction (forward) for 1 second.
a single press of Push Button 2 moves the linear actuator in the other direction (reverse) for 1 second.
The Relay code is
void setup()
{
pinMode(13,OUTPUT); // Relay output
pinMode(12,OUTPUT); // Relay output
pinMode(2,INPUT_PULLUP); // Button input
pinMode(3,INPUT_PULLUP); // Button input
Serial.begin(9600);
}
void loop()
{
static unsigned char relayState = LOW;
static unsigned char buttonState = LOW;
static unsigned char lastButtonState = LOW;
static unsigned long relayCameOn = 0;
// If the MOTOR has been on for at least 1 seconds then turn it off.
if(relayState == HIGH)
{
if(millis()-relayCameOn > 1000)
{
digitalWrite(13,HIGH);
delay(100);
relayState = LOW;
Serial.println("off");
}
}
// If the button's state has changed, then turn the MOTOR on IF it is not on already.
buttonState = digitalRead(2);
if(buttonState != lastButtonState)
{
lastButtonState = buttonState;
if((buttonState == HIGH) && (relayState == LOW))
{
digitalWrite(13,LOW);
relayState = HIGH;
relayCameOn = millis();
Serial.println("on");
}
}
{
static unsigned char relayState = LOW;
static unsigned char buttonState = LOW;
static unsigned char lastButtonState = LOW;
static unsigned long relayCameOn = 0;
// If the MOTOR has been on for at least 1 seconds then turn it off.
if(relayState == HIGH)
{
if(millis()-relayCameOn > 1000)
{
digitalWrite(12,HIGH);
delay(100);
relayState = LOW;
Serial.println("off");
}
}
else
// If the button's state has changed, then turn the MOTOR on IF it is not on already.
buttonState = digitalRead(3);
if(buttonState != lastButtonState)
{
lastButtonState = buttonState;
if((buttonState == HIGH) && (relayState == LOW))
{
digitalWrite(12,LOW);
relayState = HIGH;
relayCameOn = millis();
Serial.println("on");
}
}
}
}
This code does exactly what i want with the Relay and it's IN1 and IN2 pins to the Arduino. It's very simple.
But i need a driver that can handle more amps.
I bought a H-bridge 43A BTS7960 driver. And done an initial test with some basic test code, it runs fine and can handle my 24v linear actuator no problem.
My question is how do i modify the Relay code to the BTS7960 and it's 8 pins ? And do the same thing with the 2 buttons.
Thank you.