0
\$\begingroup\$

I'm using the switch below as a replacement boor bell switch. The LED requires 12V AC/DC and the switch has change over contacts. Datasheet.

illuminated switch

For aesthetic reasons I have to reuse the existing wiring which is only two cores and ~11m long. So the way I see the switch operating is:-

  1. Normal case - LED lit and current (~10mA) flowing through wires.
  2. Button pressed - LED off and no current flow.

The above means of operation is possible as you can wire the LED via the switch terminals. Clearly though it's not just a simple case of the traditional pull up resistor on the input pin to a micro controller. I'd like the circuit to be resistant to EMI spikes as well as hardware debounced. I think that I can handle over voltage spikes with a couple of Schottky diodes plus resistor. I looked through a guide on debouncing (Fig.2) and some application specific debounce ICs but they don't seem appropriate for a two core LED style switch. Plus I can't do surface mount. Does this require some form of current detection? An on-board ADC is available. A belt and braces approach will keep my granny happy not having to run to the door every time a car passes by or it thunders.

I think that this might be an original question as others utilise enough cores to separately light up the LED such as:-

Read the state of a 12v illuminated switch from an Arduino Uno

Using a 12V lighted toggle switch with an Arduino

\$\endgroup\$
5
  • \$\begingroup\$ it would help if you gave us a clue of what this switch is supposed to be driving. \$\endgroup\$
    – Trevor_G
    Dec 22, 2017 at 1:50
  • \$\begingroup\$ @Trevor It's just a front door bell button. So it feeds into a micro controller that's ~11m away through an old house. It doesn't drive anything like a bell. \$\endgroup\$
    – Paul Uszak
    Dec 22, 2017 at 2:07
  • \$\begingroup\$ Ya but is that something you are putting together or an existing package? \$\endgroup\$
    – Trevor_G
    Dec 22, 2017 at 2:12
  • \$\begingroup\$ @Trevor I'm sorry, I don't understand your question. What's an existing package? Do you mean am I programming the micro controller? Yes, I am. It's all from scratch. Except the wiring which I have to reuse unfortunately... \$\endgroup\$
    – Paul Uszak
    Dec 22, 2017 at 2:18
  • \$\begingroup\$ Then do the debounce in code. It's a lot easier and more reliable than messing around with filters and things. @Transistors solution is one way to hook it up, I'll post another. \$\endgroup\$
    – Trevor_G
    Dec 22, 2017 at 2:20

2 Answers 2

2
\$\begingroup\$

schematic

simulate this circuit – Schematic created using CircuitLab

Figure 1. Illuminated switch, opto-isolator and GPIO with internal pull-up enabled. Note separate ground symbols: the remote circuit can be completely isolated from the micro-controller for added noise immunity.

In button released position the opto-isolator will be on and the GPIO will be pulled low.

D2 will be infra-red type and will decrease the voltage to the LED by about 1.4 V and about 1.4 mA or so. It shouldn't be noticeable without a direct comparison.

Debounce can be done in software or by adding a capacitor between GPIO and ground. \$ C = \frac {\tau}{R} \$ where \$ \tau \$ is the desired debounce time and R is the internal pull-up value.

\$\endgroup\$
1
  • \$\begingroup\$ +1 Might need a little ESD protection in there too. \$\endgroup\$
    – Trevor_G
    Dec 22, 2017 at 2:11
0
\$\begingroup\$

You should do your debounce in code. It is much easier to do it that way especially for something as slow as a doorbell. You can also filter out a lot of noise in code too.

The following circuit will work though does not have the isolation that Transistor's answer does.

Basically as long as the switch is closed current will flow through the LED back through the base of Q1 which pulls the GPIO low. When the button is pressed Q1 will be turned off by R5 and the GPIO line is pulled high.

R2 and R3 give a little isolation to the long line and the XSORBS give you some ESD protection.

schematic

simulate this circuit – Schematic created using CircuitLab

Button monitoring is best done using a timer interrupt with two states, waiting for press and waiting for release. The following flowchart shows a typical de-bounce and noise ignoring method.

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ Do you see the soft approach more reliable than hardware debounce (even like the MAX6816)? You say simpler, but code still requires effort to research, architect, write, test and debug. It's a soldering iron /keyboard trade off. I realise that this isn't for NASA, but I'd like to impress gran. \$\endgroup\$
    – Paul Uszak
    Dec 22, 2017 at 4:31
  • \$\begingroup\$ @PaulUszak if the switch is not driving as a clock edge there is no benefit to adding cost and reducing reliability using extra external components, especially with such a slow function. Granted you add in a coding effort to get the code right, but that is a one time effort. For multiple higher speed switches, or in a micro that is already busy controlling a servo or something, it might be a different story though. "Horses for courses" and all that. \$\endgroup\$
    – Trevor_G
    Dec 22, 2017 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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