Advice for adding SPDT slide switch to project

In building a Photon powered device, I’ve realized it would be desirable to be able to easily switch the device between WiFi ON and WiFi OFF modes with a physical switch. Has anyone tried this and can recommend a best path forward? I was thinking something like this.

Any suggestions would be appreciated. Maybe there is a way to do this without the switch?

Well a switch gives a a nice visual indicator of the setting, you could also use an illuminated push button. Other methods would depend on what your device is doing and why you want to turn off WiFi but any sensor input, timer or even a command sent over serial could be put to use.

1 Like

Thanks! The reason is because from time to time, we like to use these devices in areas where WiFi is not an option…most of them are strewn across Delhi and acceptable WiFi can be hard to come by.

I’ve tried attaching the switch to an interrupt, but it’s hard to tell whether or not it is working. It doesn’t look like is working (LED still shows it’s connected).

Thats strange, because I use; in one of my apps and the led turns white when I run that.

It would help to see your code, and a wiring diagram of your setup.

I was able to get it working by just reading the state of the DI pin I was using (WKP); the code is more or less as follows:

volatile bool WIFI_STATE = true;

void setup() {
  attachInterrupt(WKP, wifiToggle, CHANGE, 5);

void loop() {
  if (WIFI_STATE == true) {
  else {;

void wifiToggle( void ) {

Previously, I was trying to use both a RISE and FALL interrupt so I could determine the position of the switch (ON v OFF), but that seemed to have problems. I was able to successfully catch the FALL, but not the RISE to turn the WiFi bakc on!

I conceivably see a few issues

  1. By toggling the state using an interrupt, the position of your physical switch is meaningless to the user.
  2. The switch probably doesn’t switch from on HIGH to LOW cleanly, so its is quite possible that interrupt gets multiple changes very close together.
  3. The use of an interrupt is neither suitable nor necessary, by definition your code is running if that switch does anything so you can pick up on the switch state like any other button/input.