I have a linear actuator with limit switches and wired as follows:

I wish to wire up inputs on my arduino mega to SW1 and SW2 to use the status of each limit switch in my arduino program but I am unsure of the best way to do this.
I would appreciate any guidance.
Search for any arduino push button sketch and wiring in google. Choose an unused Dxx pin, set pinMode to INPUT_PULLUP, connect one side of the switch to Dxx pin and the other side to ground. When the input is LOW, the switch is closed.
Good luck.
! Beat me to It!
ok,
First, you need to determine whether the switch contacts are Normally Open’, or Normally Closed.
Most often Normally Open
Then you need to tell us how you’re gong to wire that switvpch to the Arduino...
Recommended to be between the input pin and ground/0V.
Then we can show you simple code.
First hint...
For most use-cases, Don’t just check if the switch is on or off...
Test for the change of state which is usually a lot more useful.
Thanks for the replies, but the thing that worries me is that 12V is flowing through those switches (delivering current to the motor) and in different directions, so I wonder if the suggested approaches would be advisable under those circumstances? I don't think connecting 12V to the input pin would be such a great idea.
ok, it’s time to provide your schematic/wiring diagram
You’re right, but why would the switches be connected to BOTH the motors AND the Arduino?
This is a picture of the actuator:
This is the schematic of the wiring in the actuator
My idea was to use the switches as both a failsafe to prevent the actuator from crashing (say if there is a software problem) and as a way to detect in software whether the switch is open or not. That is in response to your question "why would the switches be connected to BOTH the motors AND the Arduino?"
If this is not possible then I would have to rewire to remove the diodes, direct the power straight to the motor, and use the switches exclusively for the arduino inputs. The downside of this approach is if there is some bug in the software, there is no hardwired failsafe to prevent the activator from crashing if the limit is exceeded.
OK, now I see what youre up against.
If i don’t get back to you first, I know there’s a couple of guys that will also respond.
Simple voltage dividers, some protection and current limiting (easy), will let you know what voltages are present.
You can poll those nodes, and determine the motor and switch states very easily.
In your diagram, are those 12V points both +V, or is there a 0V point not marked?
Those 12V points are either + or - as upstream there will be an H-bridge arrangement to change the direction of the motor, which complicates things as the polarity changes depending on the direction
Hi,
What is the application?
What is your actuator controlling, would it be possible to add an extra pair of micro-switches on another part of the actuator mechanism.
What is the output, rotary or linear?
Thanks.. Tom.. 
That h-bridge...
is it +/- or +/0 switching alternately as needed?
Of course any negative voltages would have to be isolated.
(optos etc)
lastchancename:
That h-bridge...
is it +/- or +/0 switching alternately as needed?
Of course any negative voltages would have to be isolated.
(optos etc)
As personal preference, I use optos to keep any non-5V signal from flowing towards my controllers inputs (instead of voltage dividers). It helps me not forget there is (microcontroller) deadly voltage on those particular lines.
I have seen that circuit before. Typical. Except the motor is usually between the diode/switch pairs.
This is for a solar energy application:
As you can see there is room for an extra set of switches that I can rig up, except I like the neatness of the switches nicely housed in the actuator.
Perhaps I am too hung up on the failsafe for exceeding the limit of travel and should rely only on the software to control that. Any thoughts?
You could leave the actuator as it is, working with the control system, and have a completely separate (independent of the control system) pair of N/C limit switches in series as a fail-safe to cut power to the actuator if either one is tripped. Nothing will get past that !
That is how his circuit works. The power is cut if the limit switch trips.