3

I would like to read the output of an on-off-on switch with my Leonardo board, but I have very little knowledge of electronics and don't know how to wire it up.

This is the switch in question: E-Switch 200MSP4T1B1M1QE

The switch has three pins. Generic three-pin SPDT wiring diagrams I've found suggest that the two outer pins should be connected to separate lights and the middle pin should be connected to the power source. Those lights also have a ground connection.

I don't want to power anything in a literal sense, I only want to have the Leonardo read the output of the switch. The end goal is to have the two ON positions read as separate button presses (eventually using a joystick library, in case that changes how the switch needs to be wired).

My questions are:

  1. Is the above wiring example correct for my use case?
  2. Is the output of the switch considered digital or analog?
  3. Is a wire from the switch to GND not required?

One final note - I'm not using a breadboard, but connecting the wires directly from the switch to the board.

1
4

You talk about wiring a switch to control lights directly. Instead, you want to use your switch to send information to your Arduino.

You link to an SPDT (single pole, double throw) switch. When flipped one way, it connects the center pin to one of the outside pins, and when flipped the other way, it connects the center pin to the other outside pin.

If you want the Leonardo to read the state of the switch as 2 separate switches/button presses, wire the 2 outer pins of the switch to 2 separate digital inputs on the Arduino.

You need to force each input to either ground or +5V when it's not connected to anything, or it will "float" and you'll get semi-random high and low readings.

I suggest setting the Arduino input pins to INPUT_PULLUP mode. That connects the inputs internally through a resistor to +5V. If you don't connect anything to the pin, it reads as HIGH. When the button is pressed/switch is closed, it reads LOW. That might seem a little confusing, but it means you don't need external resistors.

You'd then attach those to pins to the two outer pins of your switch, and attach the center pin to ground (GND).

If you flip the switch one way, it would connect one outer pin to the center pin. That would connect that Arduino pin to ground, and the reading on the pin would drop from HIGH to LOW. Flip the switch the other way and it would connect the other pin to ground, at that other pin would drop from HIGH to LOW.

It is also possible to wire your switches using INPUT mode, not INPUT_PULLUP, and have them read LOW when the switch is open, and HIGH when closed, but to do that you'll need external pull-down resistors. (And wiring it will be a little painful without a breadboard or PC board.)

To answer your questions:

  1. Is the above wiring example correct for my use case?

You don't show a wiring example. You talk about how to wire a switch to switch power to a pair of lights directly, without using a microcontroller. That's not relevant here.

  1. Is the output of the switch considered digital or analog?

It would make sense to use it as a digital input, since you need it to give you 2 states, open and closed.

  1. Is a wire from the switch to GND not required?

You need to connect the center pin to either ground +5V, as discussed above.

3
  • See the diagram in Edgar's answer. A picture is worth a thousand words.
    – Duncan C
    Sep 18 '20 at 19:31
  • This is exactly what I was looking for, thank you! I would say this is the better answer. Not that the diagrams were bad, necessarily, but for someone with little wiring/circuitry experience the diagrams only confused me more. Sep 18 '20 at 23:36
  • If you feel this (or Edgar's) answer answers your question you should accept it. (Accepting the first/best answer that answers your question is expected on Stack Exchange sites.)
    – Duncan C
    Sep 19 '20 at 14:52
4

I suggest this simple circuit:

schematic

simulate this circuit – Schematic created using CircuitLab

Set both inputs to INPUT_PULLUP. If the input reads LOW, that means it has been grounded by the switch.


Edit: Per Duncan’s request, here is the alternative circuit with the polarities inverted. With the switch’s common connected to Vcc, the inputs should be set to INPUT_PULLDOWN. However, most Arduinos do not support this mode, for lack of internal pull-downs. Then one has to use external pull-downs instead, and set the pins to INPUT.

schematic

simulate this circuit

With this circuit, a pin reads HIGH when it is connected to +5V by the switch.

9
  • I didn't notice Duncan C posted an answer just while I was preparing mine. Both answers are the same: one with words, the other with an image. Sep 18 '20 at 19:29
  • I haven't used CircuitLab very much. A diagram is soooo much clearer. (voted.) Could you also show the alternate circuit with the switch connected to +5V, with pull-down resistors? Some newbies find LOW == switch on confusing.
    – Duncan C
    Sep 18 '20 at 19:34
  • @DuncanC: OK, edited as per your request. Sep 18 '20 at 20:56
  • Why not save an input and use the != and == to determine which way the switch is positioned. less code less hardware.
    – Gil
    Sep 18 '20 at 21:58
  • 1
    @Gil: I don't understand. Did you notice it's a 3-positions switch? Would you post an answer expanding on your idea? Sep 18 '20 at 23:09
-1

Alternative Circuit

For the on-off-on switch, the MSP-3 and MSP-4 operate as follows:

Operation of MSP-3 and MSP-4 switches

Figure 1 – Operation of MSP-3 and MSP-4 switches.

POS Connection MSP-3 MSP-4
1 Terminal 2 to Terminal 3 ON (ON)
2 Terminal 2 to open circuit OFF OFF
3 Terminal 2 to Terminal 1 ON (ON)

Here is an alternative way to connect the SPDT to the MCU which is useful when running out of pins because it only requires one input pin. It does however require more complicated software to interpret the input e.g., hysteresis and debounce could be implemented with thresholds such as:

  • > 90% Vcc for > 50 ms means high.
  • < 10% Vcc for > 50 ms means low.
  • > 45% Vcc and < 55% Vcc for > 50 ms means OFF.
  • anywhere in between means no change.

Connecting SPDT switch to MCU

Figure 2 – Connecting SPDT switch to MCU.

Throw vs Stop vs Contact

In normal parlance, a throw describes a physical action that moves a mechanism to a new mechanical stop; and throws are distinct from stops and contacts. As such, a switch is a transducer that converts physical movements (throws) to an electrical signal via a system of mechanical stops and electrical contacts.

From Figure 1, the totals are 2 throws, 3 positions, 2 contacts and 1 pole.

However, matters have been confused by a minority of people erroneously metamorphosing the term “throw” to mean “mechanical stop” or “electrical contact.” As you can see in this example—as is often the case—the number of throws equals the number of contacts, but that is not always the case. For example, if there were a centre contact for the centre stop, there would be three contacts, but still only two throws. Perhaps the fact that throws and contacts are often equal in number has led some people to conflate and confuse the separate entities. And perhaps that the number of stops can sometimes equal the number of contacts has led some people to conflate and confuse them too. For this kind of switch, the number of throws is always one less than the number of stops.

Matters are not helped by the E-Switch 200MSP4T1B1M1QE datasheet showing an incorrect schematic for the MSP-3, 4 and 5 that omits the centre mechanical stop that should be labelled OFF.

I’ve re-annotated the datasheet, Figure 3, and modified the following prose to comply with the common-sense approach of Figure 1, being mindful that a minority of people use “throw” to mean “contact,” and added the correct schematic for MSP-3, 4 and 5. (The original annotated version and prose was an attempt to use the datasheet’s own erroneous nomenclature and schematic.)

Annotated datasheet v2

Figure 3 – Annotated datasheet.

MSP-1, 2 and 6 are actually single-throw switches despite what the datasheet implies which conflates its description of its SPST with its SPDT switches (which caused some confusion in the comments about the intent and variety of the switch).

The switch required for the above example is the MSP-3 on-off-on. Or to simulate momentary button presses, the MSP-4 (on)-off-(on). Both of these are single-pole double-throw switches (SPDT), not because they have 2 electrical contacts, but because they have 2 physical throws.

In the context of the erroneous datasheet, throws and contacts are erroneously synonymous. In normal parlance, neither throws nor positions are electrical contacts/terminals/pins (though the datasheet has conflated them as well). However, each mechanical stop does have an associated electrical connection/disconnection that should be explained in the datasheet. Unfortunately, in this case, the table in the datasheet has conflated SPST with SPDT and used the term “NONE” to indicate that a position doesn’t exist for the SPST types (MSP-1, MSP-2, and MSP-6). For MSP-3, 4, and 5, notice how POS 2 doesn’t have an associated contact/terminal/pin in the green schematic, Figure 3.

From experience, the only way to be sure is to buzz out the switch with a multimeter (continuity test). So, keep Figure 1 in your mind and a multimeter in your hand, and you won’t go far wrong.

Conclusions

  1. Throws are physical.
  2. Stops are mechanical.
  3. Contacts are electrical.
  4. Claims such as, “My contact is a throw.” are delusional.
  5. Conclusions can be lyrical.

Phantom Scroll-By Downvoter

This answer has a attracted a phantom downvote with no comment expressing why this is warranted.

Does the phantom think:

  1. the alternative circuit is wrong?
  2. the thresholds are wrong?
  3. the errant use of the English language and dodgy schematics in the datasheet are acceptable?

Bear in mind that the terms “throw,” “stop,” and “contact” (their meanings and usage) are taught by schoolteachers to millions of school children every year; and used by billions of English speakers every day. Is the global education system (which isn’t perfect) wrong on this particular point? On what grounds and exceptional circumstances is a datasheet allowed to use such terms in an inappropriate manner?

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Juraj
    Aug 15 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.