# Reading motor limit switches with Arduino

I'm building a window blinds system. I have an arduino powering a motor via a DRV8833 Dual-H bridge controller. At the limits of each direction of motion, I have limit switches that kill the power to the motor in that direction. I also want the arduino to read when the limits are hit, but I can't feed the raw power from the limit switch into an input pin as it will exceed the 3.3V logic inputs.

I've got what I'm calling forward working with an NPN transistor to feed 3.3V logic when its corresponding limit switch is hit. However I'm really struggling figuring out the wiring to determine when the reverse limit switch is hit. In that case you end up with a negative voltage in a sense coming from the limit switch. I've had a couple of random configurations that seemed to work, but not consistently. I'm attaching diagram of what I have in place currently. In this diagram, I'm representing the reverse and forward directions separately with reversed voltage sources even though in practice, the two limit switches are next to each other between the DRV8833 and the motor (represented by lamp). I have diodes across the limits to allow motion in the opposite direction when a limit is hit. I have Q8 being activated when SW7 is hit and the arduino pin reads the switch activation. I need help getting SW5 to indicate to the arduino when it's been hit. Note resistors are just default ratings in diagram.

• With the current circuit, pin3 is always connected to 3.3V. If Q6 turns ON, what limits the current through Q6 ?
– AJN
Commented Jul 27, 2020 at 15:40
• Why not use the same scheme as SW7 ? input to Q8 is low when motor is running and input to Q8 is high (8V) when motor is not running. If you use the same scheme for SW5 also, only difference is that you will get high when motor is running and low when motor is not running. Just do a logical inversion inside the arduino code.
– AJN
Commented Jul 27, 2020 at 15:54
• Are the BJTs necessary? Can this not be done with voltages dividers? Commented Jul 27, 2020 at 17:37
• I'm a total newb at circuitry so there is possibly a better way to do this than BJT. I hadn't thought about voltage dividing but I just felt like there were too many variables to ensure I get a clear an accurate and safe voltage into the input pin. I don't know at this point what voltage I'll need to run the motor at (it's on a buck converter so I can set voltage) and PWM may also come into play and I don't under stand how PWM affects things. It's possible I don't have a grasp of how VD works and it may be viable. I just don't have the knowledge or experience under my belt. Commented Jul 27, 2020 at 17:51
• Voltage converters feeding motors are generally a very bad idea Commented Jul 28, 2020 at 16:00