# Vending machine motor and switch circuit

I have a project using vending machine motors, arduino, pi etc. The motors have a NC microswitch that is OFF when motor spinning and ON when returning to the original / start point, to detect 1 full revolution. It is 6 pins, and I wanted to know how to wire this up to send it on a 360 revolution

[![enter image description here][2]][2]

simulate this circuit – Schematic created using CircuitLab

simulate this circuit – Schematic created using CircuitLab

Figure 1. Partial solution.

Since you say that SW1 is open in the home position it appears to be a 'park' switch, rather like a car window wiper motor. A short pulse on SW2 will get the motor running through D2, SW1 will close and maintain current through D1 until the motor reaches the home position. SW1 will then open and the motor will stop.

I'll think about the diode on pin 6 for a bit. Can you think of any reason why the motor might need to run in reverse?

• awesome, thankyou! No idea on reversing, I guess that it might allow things to be loaded from the front, or prevent main board damage from some failure, accidental misconnection - but anyway your answer & diagram solves - thankyou :) – mdk Sep 9 '18 at 17:48
• Thanks. I recommend that you unaccept my answer and give time for the Earth to rotate once or twice so that everyone on the planet has a chance to answer. This would encourage other answers and even if you don't get a complete answer you might get some different perspectives or tips. Then come back and accept the best and upvote any other useful ones. – Transistor Sep 9 '18 at 17:51
• Sorry to bother, I have figured out (after much melting of components) that SW1 is actually push to break - active in the park position. Have spent a while in circles - I think it's something to do with Pin 6 and maybe earthing 5 as negative logic but... amateur. :/ @transistor – mdk Dec 16 '18 at 17:23
• the Diode next to SW1 was round the wrong way in my diagram also. Have updated and clarified pictures above – mdk Dec 16 '18 at 18:02
• – mdk Dec 16 '18 at 18:19

I think it's more like this-- note that I've flipped all D3 from your diagram to the actual orientation shown on the photo of the PCB.

D2 is a flyback diode across the motor coil. Don't forget that GND connection on 4 or the other diodes may be damaged when SW1 opens or if SW2 is released before SW1 closes.

simulate this circuit – Schematic created using CircuitLab

SW1 is open when the motor is in the park position, so no power is on the motor.

SW2 is held long enough, powering the motor through D3, for SW1 to close, powering the motor through D1.

When the motor reaches the park position, provided SW2 is still released, it stops because SW1 opens.

D2 is a flyback diode as discussed above.

It's not obvious to me why they bothered with diodes D1 and D3 at all.

• Thanks for this @spehro, the circuit runs this way but interestingly the switch SW1 still behaves as a push to break - in that the motor runs on 6 High, then the important bit: does not run when the switch is depressed yet runs through what should be the parked status. I cannot work out how this works where SW1 is clearly a PTB :/ – mdk Dec 17 '18 at 14:33