I have a pump that is turned on and off by either a float switch in a water tank or a low voltage disconnect (LVD) on a solar charge controller. The two switches are in series. I would like my A-Star 32U4 Prime SV (Pololu item #: 3115) to know when either of these switches are opened or closed. How should I connect these switches to my input pins (ignoring any switch bounce)? Obviously I’d also like to prevent the MCU being fried by any back EMF from the motor or whatever but I don’t know enough about that to know if that will be an issue here.
The circuit in your second diagram exposes your microcontroller pins to 24V and lots of current, so I would not use it. There are a few ways you could more safely detect the switches. You could connect to the right of each switch with a voltage divider that limits the voltage on the microcontroller’s pins to 5V. Another somewhat safer approach would be to use a transistor with the base connected to the right of the switches that pulls the microcontroller pins to ground when triggered. You can see an example of a transistor being used like that on the RCIN pin in the schematic of one of our RC switch boards. Yet another approach would be to take the switches out of the motor circuit, connect them just to the microcontroller, and then use the microcontroller to trigger a MOSFET or relay to power the motor.
By the way, adding a flyback diode in parallel with your motor would be a good way to limit the impact of back EMF on the rest of your circuit
The 3rd option would be ideal but the existing system already has these switches installed. So I think I’ll try using transistors as suggested. Would the below circuit work? Or maybe there is an better/easier way?
It looks like you might have accidentally drawn one of your transistors connected to the wrong side of S2, since where it is now it will always be connected to ground and always be off. Even with that fixed though, the new circuit you posted will not be able to tell you if S1 is open or closed when S2 is open.
I see three options. One is pulling the node between the switches high (like you have it now), which means you can’t determine the state of S1 when S2 is open. The second is pulling the node between the switches low, which means you can’t determine the state of S2 when S1 is open. Lastly, if neither of those two options work for you, you could use an output on the A-Star to allow you to switch between pulling that node high and pulling it low; then you should be able to get all the states.
There are a few other things to consider as well. The ATmega32U4 on the A-Star already has Schmitt triggers built into its I/O pins, so you probably do not need to add external ones. Also, you might need to experiment with the value of your base resistor. The 7.5MΩ resistor seems too large to fully turn on the transistors, but if you use too small a resistor it would create a current path for the motor through the transistors.
Sorry, I’m obviously a novice at this so thank you for your patience with my abundance of stupid questions. I’ve updated the schematic so S2 is on the correct side of the switch. I’ve also update where S1 is in the schematic, which better represent where it is in reality. I think all state would be captured this way. What do you think?
So to fully saturate the transistor isn’t it dependent on the expected current through the collector? So with a 10k pull-up resistor the current through the collector would be
Then the minimum required base current would need to be
So the base resistor would need to be
This seems fishy to me. Is this correct?
Thanks for the input on the schmitt trigger.
Your new circuit is still not going to be able to tell you the state of S1 when S2 is open. As for your calculations for R1 and R2, they seem okay, but hFE can vary a lot, and the 9.3MΩ that you calculated is the maximum resistor size that could possibly work. I recommend using something a good amount lower like 100k.