How to wire limit switch safely and read switch status

I want to control a 5V motor with an Arduino. The motor needs to run until it hits a limit switch then wait until the Arduino sends a signal to run in the other direction. I also want the system to fail safe.

My thinking is to use the limit switches to cutoff the control signal coming from the Arduino. This would prevent the motor running without limits in case of a switch being absent or due to an error in the code.

I also need to know the current position of the motor (left, right or in-between)

I was thinking I could use the NO pins of the limit switches to read their states, but I haven't been able to figure out a way to do it.

Can I achieve this using the hardware as shown on the schematic?

I'm also open to solutions involving changing the driver IC or adding switches or other types of sensor or components.

Thank you!

  • Your circuit requires software to stop the motor.
    For fail safe operations, the motor current should be physically removed.

  • For fail safe you could add crash stop switches too.
    You can add a TIMER to the code to limit the time the motor runs also.

  • Here is a relay schematic option.

Then you need to actually measure how much time the motor needs to stop when the limit switch is hit. Is the motor moving as your text indicates or is the motor moving something that hits the switch? In this world, you need to be specific if you want help.

Thank you for your suggestion. Although, my circuit does not require software to stop the motor. Then L9110S will not activate the motor if no signal are present on the input pin.

I think I have found another solution : An active “LOW” Tri-state Buffer between with the Switch-NC as enable/disable and the arduino as signal would work.

  • Yes you’re correct, didn’t look close enough.

  • Whenever possible removing power at a CRASH position should be considered.
    Perhaps a lockout too if personal injury can happen. i.e. a drop out relay would need to be manually re-enabled.

Fail safe means exactly what it says.
Any part of the system that fails, must fall back to a safe condition.
Take a relay.
If configured to supply power through it's contacts, the normally open pair would be used.
If the system power fails, the relay goes to the open state.
For extra safety, switch both power lines, live and neutral for example, so an error in wiring is catered for. Use a 2-pole relay in that case.

If it was me, I would have the switch going to a idiot switch relay on the motor power line, and also to a MCU input, so it can stop the motor signal, and cut power. You could put high resistance across the motor lines if you need a hacky “brake” though that is arguably not going to work well. You can get braked motors if safety is important, which apply a brake to the spindle when power is lost…