Replacing a Microswitch with non-human event

Hi all,

I’m currently working on a project where I want to replace physical button presses with a process that runs via Particle device. I have an electron and a few original cores, I’m not too worried which Particle device I’m using.

For some context, I have an old drinks vending machine that has a series of customer facing push buttons. These buttons each have a microswitch. I want replace the microswitch entirely, so that the “button presses” are actually done via HTTP requests to the electron/device.

It may seem strange to simulate the button press rather than not interfacing with the machine at another level. The reason I’m doing this is because I want to make minimal changes to the machine and this way I get to take advantage of the function of the motherboard on the machine, that are triggered by the button press. The motherboard is rare and documentation no longer exists, so I can’t afford to make guesses at controlling it directly.

My electronics knowledge is incredibly limited. My current idea is to replace the microswitch with a relay (I have the original core relay shield). I intend to just swap the NO/NC from the microswitch to that of the relay. This seems a little overkill for what I’m trying to do, so may questions are:

  1. Is a relay the right way to go about this?
  2. Do I need to worry about the amp to the current microswitch if I do replace with a relay (am I likely to blow something in the machine?)

I’ve attached a picture of the microswitch I intend to replace. And by replace, I mean “work-around”… I will be leaving the existing switches in place, albeit disconnected, incase I need to reverse later.

Any ideas/warnings would be appreciated.


Hey Happy!
I’m a hobbyist in all this, and my first instinct would be to do the same as you are proposing: use a relay to replace that switch.

I think you are right here. You need to worry about the volts and amperes the switch is handling so you are sure that the relay is not going to blow after few tries.

I know you are not too worried, but the cores I still have around have a tendency to restart or disconnect easily from wifi, so if stability in your project is important, you may want to use the electron or at the end a photon.

I hope that helps!


Further to @gusgonnet replies - looking at the picture I can see 1/4" spade terminals on the switches. If you are going to replace the switches with relays controlled by a Core or an Electron then you need to think about developing a small circuit board with easy-on spade terminals. The relays then need to be selected to handle the voltage and current. Also, depending upon the load switched you may need in-rush current tolerant relays. The control of the switching power to the relays must be done via a MOSFET or similar transistor to ensure that the pin on the Electron is not overloaded and when there is no power or signal the switch/relay is open. Depending how many switches you need to replace with relays and what else you are using pins for you may need to drive the relay MOSFET with a GPIO expander via I2C bus. The power supply to switch your relays will need to be considered as well as this cannot come from the Core or electron.

1 Like

@Happy, can you be more specific about the functions of the buttons. My suspicion is that the micro-switches are not carrying a great deal of current but were selected for durability. Nonetheless, perhaps a photo of the control board would be helpful in understanding more. I have a feeling that the relay board is up to the task and I agree with @armor on the need for a small board with spade connectors. I also agree with @gusgonnet in regards to the reliability of the old Core. You would be better off with a Photon and a newer Particle Relay Board.

BTW, the picture seems to suggest a second connector just below the micro-switch which is most likely driving a bulb as an indicator. Will you need to control these as well?


Thanks gusgonnet, armor & peekay123, I appreciate the replies and your time.

@peekay123 @armor I will put a multimeter on the existing microswitch tomorrow to work out the current voltage going through it. What do you see the small circuit board with spade connectors doing? If I’m using a relay shield, does the shield not handle provide enough access? Happy to add the extra board, just not sure what it I need to be creating there.

@peekay123 When you press an existing button, there is an LCD screen that shows a price associated to the button. If credit exists within the system covering the price, a drink is vended - I’m not worrying about the price function as my plan is set everything to free-vend and then control the price/credit system via the Electron/Photon.

The second connector you mention, peekay, controls a small LED to show the instock/out of stock status attached to the button. As I’ll be maintaining the inventory functions of the motherboard, I don’t need to do anything with this.

I’ve attached a picture of the buttons from the front and the motherboard they feed into (although I can’t take the casing off until tomorrow so not sure how useful this is)

I take your points on the old cores/old relay shield… I’ll try and mock using those old parts and replace with newer components once I have the concept nailed - Thanks again for your time.

I have an old relay shield running with a photon and that is been ok for many years now :crossed_fingers:
@peekay123 what do you see unreliable in the old relay shield?

@gusgonnet, I too use the old relay shield with a Photon. I just like the board layout of the new shield better! :wink:

1 Like

The “extra” board is to allow you to take the existing bayonet connectors and connecting them onto this board. You could also create a small harness with bayonets on one end and the other end connecting directly to the screw terminals on the relay board. You could also build a mounting board to which you would mount the relay board and other intermediate connectors that you would mount inside the machine.

Is there a specific reason you want to disconnect the manual buttons? Your application (which we don’t have many details on) may be different, but I usually try to augment the original functionality of a machine when automating it, rather than disabling the original. Like I said, though, your application may be different than what I am thinking of.

1 Like

@peekay123 That makes sense, great idea… thanks.

@picsil I’ve written an application that connects our company slack account to the machine… every member of the team has a balance and can trigger the vend event from their desk/phones via slack rather than actually pushing the buttons…so the buttons become redundant. Because the machine is so old, the parts very rare, no documentation exists on how the motherboard works (vending operations, temperature control, mother control, lighting) and my electronics knowledge is so limited, I figure simulating the buttons at the highest level is the safest and easiest route. This way I can control pricing/write free-vend schedules etc using the remote application I’ve created, rather than trying to manipulate/communicate with the motherboard.

I’ll publish the remote code on Github when it’s finished.


1 Like

Pretty cool application. That makes sense. How far is it from workers’ desks to the machine? Is there a possibility that they might vend a drink from their desk only to find that someone else has taken it when it “magically” dropped?

Here’s an idea, albeit a little more complicated than your original one. From the photos it looks like there is another pole on the vending switches. Could you interface each of those to a GPIO pin? That way, when someone selects a drink through Slack, it could tell them which “secret” button to press on the machine to get their drink. That way it doesn’t actually dispense the drink until they’re at the machine. Nobody can take their drink, and if more than one person happened to vend a drink at the same time they’d each get the one they wanted by pressing different “secret” buttons.

1 Like

@picsil I like that idea. We’re in a small open plan office, I don’t think drinks will go missing but I think I’ll try and work that in too, why not!

@picsil, @Happy, if those switches are switching AC voltage you will not be able to interface to GPIO directly. If the voltage is DC but anything higher than 3.3v (most likely), you will need to add level shifting to interface to GPIO. Also, the extra pole is typically the opposite switch action - NC or NO which may not serve your intended purpose.

Thanks @peekay123 I was just about to add some more commentary to that effect. What I had in mind was actually just disconnecting the buttons from the main board and using them only for GPIO inputs. @Happy can still interface to the original wire in the same manner as discussed earlier, but also use the button as low voltage GPIO since it is disconnected from the rest of the machine.