limited motor control for 3d printer

i have built 2 linear actuators which i want to control with my arduino but i would like to both have 2 stop swithces at either end of both actuators so when it reaches the end it would prevent the motor from turning any firther in that direction , how would i have this code running for both motors at the same time wiht my controlling code running too. any help would be much appreciated , ill post some pics of the finished 3d printer when its done

EDIT PLEASES READ: The motors are conrolled just like servos , infatc just forget theres motors and just prteend there servos ;D ;D ;D ;D ;D ;D ;D ;D

You've got several different choices. Depending on how many pins and how much program space are free on your 'duino, you can:

(Assumes each motor has its own switch pair, and is controlled independently)

1) Wire the switches in series, and have one pin simply watch for either of them to open/close (depending on switch type). 2) Wire each switch to a pin, and watch those pins in code. Respond as needed.

The second choice lets you "home" the actuator to a known, fixed position AND know when it hits its travel limit.

You could conceivably use a single analog input pin for all four switches by having a different values of resistors in series with a "reference" value (see Eagle schematic at http://sites.google.com/site/adifferentlemming/Home/projects/arduino).

Are you asking what you would use so sense the limits of travel, or are you asking how you would set up your code to run everything at once?

For the first thing, I would just use some limit switches. There are a number of ways you can wire them up depending on if you want to know the specific switch that was hit, ie which end your print head is at, or you could just wire the two switches on each print axis up in parallel so you would know that a switch on a specific axis was hit. This would save you a couple pins.

As for the code structure, we would need to know a little more about your project, how is it getting its input?

Your probably just going to need something like this for each axis.

If your print head is not at the given location, and the limit switches are open, Continue to run the motor.

Else stop

i want to control it by serial, so i would sedn "1-200" to move actuator 1 200 , inbetween 1 -1000 , but i need it to stop itself as it hits the limit switvhes on the actuator.

actuator 1 is controlled by : pin 9 for servo control analouge pin 1-2 limit switches

actuatoir 2 is controlled by : pin 10 for servo control alalouge pin 3-4 limit switches

I would mount one DPDT switches at both ends of travel. Wire the actuator power source through both switches using one of the normally closed contacts on each switch. I would have to see your motor driver wiring drawing to show how to kill power in each direction but still have power available to reverse the travel. This would cut power if either stop is reached.

The other set of contacts of both switches could be wired in series using the other normally closed contacts, but wire this loop to a Arduino digital input pin, ground on end of the switch loop and wire the other to the input pin and activate the soft pull-up feature. Reading a high will tell your program that you have reached a stop condition.

Lefty

this wasnt my problem lol , i need some help with the code