I’m trying to turn on a relay when a limit switch is activated. However when the limit is activated it will need to energize the relay for a certain amount of time, then the relay needs to cut out . When the relay cuts out it will deactivate the limit switch mechanically
Always show us a good schematic of your proposed circuit.
Show us good images of your ‘actual’ wiring.
What kind of Arduino do you have ?
In the Arduino IDE, use CtrlT or CMDT to format your code then copy the complete sketch.
Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.
if the limit switch is just driving a digital input, can't that input simply be ignored. A common issue is that a limit switch should stop travel in one directoin but not the other. so conventional logic might be
if (CW == dir && Active == digitalRead (PinLimitCw))
stop();
However, if you are using a relay for the situation where a limit switch is activated but you want to override it so a moving device can go back in the other direction, off the switch, the conventional way to do this is to put a reverse diode across the limit switch. The diode allows current to flow only in the direction that would let a motor move away from the limit.