I am designing a linear translation stage that will be driven with a DC motor. When the circuit is powered the DC motor will start turning in either direction, which will move the linear stage towards one end. At that end the stage will activate limit switch #1 and the motor will turn the opposite direction until the stage activates limit switch #2. When limit switch #2 is activated the motor will turn in the original direction and send the stage back towards limit switch #1. This process will repeat until the circuit is powered off.
Does anyone have any ideas for how to build a circuit that reverses polarity to the motor using only a momentary pulse from a limit switch? I have built this circuit:
The circuit works great for its intended purpose, but it does not work for my needs because I need to be able to use momentary switches (limit switches). The circuit shown here will stop traveling as soon as the switch is released.
I have also tried to wire the circuit above through an Arduino. I used the momentary limit switches as inputs for interrupts. I had the same issue of the motor only moving while a switch was being actively closed. Here is the sketch that I came up with:
const int interruptPin = 2;
const int interruptPin2 = 3;
const int cwPin = 10;
const int ccwPin = 11;
void setup()
{
pinMode(cwPin, OUTPUT);
pinMode(ccwPin, OUTPUT);
pinMode(interruptPin, INPUT);
pinMode(interruptPin2, INPUT);
attachInterrupt(0, goCw, RISING);
attachInterrupt(1, goCcw, RISING);
}
void loop()
{
digitalWrite(cwPin, HIGH);
}
void goCw()
{
digitalWrite(cwPin, HIGH);
digitalWrite(ccwPin, LOW);
}
void goCcw()
{
digitalWrite(cwPin, LOW);
digitalWrite(ccwPin, HIGH);
}
I would appreciate any advice that anyone has on this issue. I am open to using any method to achieve the desired outcome. I attempted to use the Arduino because I thought that it would solve my problem, but I am not against eliminating it if there is a better way.