Good day folks,
I would like to apologize in advance ... I'm new to coding with Arduino.
Here is what I would like to do:
Using a arduino uno, would like to read A0 input for 5v (coming from a USB device), convert the voltage to output and control a line actuator to extend when 5v is detected and retract when 5v is lost at A0 input.
What is working:
I can control the line actuator just fine with buttons to extend and retract the motor.
I can control the line actuator just fine with 5v trigger to extend and retract the motor when 5v is lost.
The Issue I'm having:
After 5v trigger has been activated, the actuator extends to its maximum position, the board continues to send trigger to power to the actuator. The same thing happens in reverse when the 5v trigger is lost, actuator is retracted but power to the actuator is still being send.
The questions:
Can I have both the 5v trigger and buttons working in parallel if desired ? (ex: if 5v trigger is not applied I should still use the button and vice versa)
Can I apply a timer for lets say 30 seconds for the 5v trigger to activate the actuator then cut power to it after the extension/retraction process is complete ?
Hardware Used:
BTS7960
Arduino Uno
DC Motor Polarity Reversing Rocker 3 Position DPDT Momentary Automatic Reset Switch.
byte mspeed=0;
int RPWM = 5;
int LPWM = 6;
int value = analogRead (A0); // read A0
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(A0, INPUT);
pinMode(RPWM,OUTPUT);
pinMode(LPWM,OUTPUT);
pinMode(13, OUTPUT); //BUILD IN LED
}
void loop() {
if( analogRead(A0) > 512 == HIGH & analogRead(A0) < 512 ==LOW ){
digitalWrite(13, HIGH); //write digital pin 13 high LED
mspeed = 255;
analogWrite(RPWM,0);
analogWrite(LPWM, mspeed);
}
else if ( analogRead(A0) > 512 == LOW & analogRead(A0) < 512 ==HIGH ){
digitalWrite(13, LOW); //write digital pin 13 low LED
mspeed = 255;
analogWrite(RPWM,mspeed);
analogWrite(LPWM, 0);
}
else {
analogWrite(RPWM,0);
analogWrite(LPWM, 0);
}
}
#Thank you very much for your time