# Problematic circuit with 2 switches @ 12V

Hi,
I’m a bit stuck on a preexisting circuit which I cannot get to work on a single Arduino interrupt.
Maybe someone could be so kind to give me a little guidance, I’m obviously missing something basic there.

I need to trigger (a change interrupt) whenever the signal is changing between:
[unconnected / +12V] and [GND].

“unconnected vs GND” is easy to realize in INPUT_PULLUP, however the third state, +12V, is problematic.

I’ve attached a picture to visualize the problem:
Normal operation is Switch to GND and Reed closed.

Whenever the switch is on +12V OR the Reed contact is open, I need to trigger the interrupt.

A few attempts with voltage dividers and transistors weren’t convincing, that’s why I’ve decided to ask if anyone has an idea how to make the circuit work with least parts.

Ok, so I’ve taken another look at the problem and I think I’ve been able to solve it with a p-Channel Mosfet.

Please take a look at the attached circuit - INT (INPUT mode) should be high unless either the reed contact is open or the switch is at +12V.

So I’m basically using the “differential voltage” at Source and Gate to trigger the Mosfet and use a voltage divider to get to get the Drain down to the Arduino’s 5V logic level.
I’ve also added a resistor between Source and Gate to make sure the Mosfet is resetting correctly.

daywalker313: Whenever the switch is on +12V OR the Reed contact is open, I need to trigger the interrupt.

As drawn in the current state, R2 will act as a pulldown for D3, and the mosfet will be off, as R3 will dump 12V on the base. Changing the state of the switch will do nothing, but closing the reed while the switch is still connected to (1) Gnd will pull the gate voltage to 0V, turning the mosfet ON, and in turn using R1 & R2 as a divider puts a high on D3.

Perhaps eliminate the mosfet altogether and run the switch pin 3 (12V) into the top of a voltage divider, with D3 in the center. Use the reed as a pulldown between another voltage divider, with the top connected to 12V source and the bottom connected to the D3 node.

That should give you a HIGH when the 12V switch is closed, and a HIGH if the reed is open, regardless of the switch position.

Only thing is, you are using that 12V to power the uC, so any time you have power to it, you will have a HIGH on D3, and with the switch open, there is no power to the uC, so a HIGH from the reed opening is somewhat moot

Thanks for your reply and for taking the time to look at the schematics.

The switch is a brake light pressure sensor, which is closed when the brake is pushed.
The reed contact is at the clutch pedal and is open if the clutch is pushed.

So I think the circuit works if I want to detect either braking or pushing the clutch pedal:

Switch GND and Reed closed == HIGH
Switch +12V (brake pushed) == LOW
Reed open (clutch pushed) == LOW

I’d prefer not to rewire the existing circuitry, so the mosfet solution doesn’t look too bad, right?
I’ve attached another drawing showing the car wiring.

daywalker313: I'm a bit stuck on a preexisting circuit which I cannot get to work on a single Arduino interrupt.

When problems like this come up, I always see the coders (which I'm not) ask: 1) Why use an interrupt. 2) Do you expect things like that to happen in microseconds.

Polling in a responsive loop can be done fast. Maybe faster than the debounce time of a switch. So why do you think you need interrupts. Leo..

The clutch and brake pedals act as a kill switch and immediately interrupt any actuation (e.g. releasing all vacuum valves). So debouncing isn't necessary here and due to the nature of the scheduler I've been implementing, the minimum guaranteed delay for polling would be >100 ms, which is not acceptable.

Did you measure voltage on the "braun" wire going to that module when the reed switch is open? Logic on that line should be HIGH if one of the switches is operated (I expect some pull up inside that module).

It seems a simple (~22k) resistor between the "brown" line and and the interrupt pin would be enough. 22k will protect the pin by limiting internal pin protection diode current. If you don't trust that (I would), add a schottky diode (1N5819) from Arduino pin to 5volt. Cathode to +5volt. Detect a HIGH going pulse. Leo..

daywalker313:
Hi,
I’m a bit stuck on a preexisting circuit which I cannot get to work on a single Arduino interrupt.
Maybe someone could be so kind to give me a little guidance, I’m obviously missing something basic there.

I need to trigger (a change interrupt) whenever the signal is changing between:
[unconnected / +12V] and [GND].

“unconnected vs GND” is easy to realize in INPUT_PULLUP, however the third state, +12V, is problematic.

I’ve attached a picture to visualize the problem:
Normal operation is Switch to GND and Reed closed.

Whenever the switch is on +12V OR the Reed contact is open, I need to trigger the interrupt.

A few attempts with voltage dividers and transistors weren’t convincing, that’s why I’ve decided to ask if anyone has an idea how to make the circuit work with least parts.

You need to bring the signal through a 15k resistor to an analog pin, also connecting the pin via 10k
resistors to GND and to +5V. Open circuit it will read 2.5V, +12V on the switch gives about +4.9V on the pin
and 0V on the switch gives about 1.9V on the analog pin.

And you're not already using the interrupt for something else more time-critical? 100ms is such a short delay for a human, you won't notice it.

MorganS: And you're not already using the interrupt for something else more time-critical? 100ms is such a short delay for a human, you won't notice it.

I'm pretty sure you'd notice if a car is hitting you because the stopping distance was around 1m longer than expected (which means an increase in the pure breaking distance of about 10%!).

This is for a model car [0-100km/h in 8.5s] at 40 km/h, full thrust with peak acceleration and a 100ms longer acceleration time just between hitting the pedal and brake pads applying full force.

So yes, this is tremendously time critical and polling at 10/s is just stupid.

Wouldn't you just put a voltage divider between the battery and the reed switch, to bring it down to 5v?

As for how to detect the states - you could attach an output pin via a resistor to the input pin. when that output is powered, it will act as a pull-up, allowing you to tell the difference between unconnected and grounded. When it is unpowered it will act as a pull-down, allowing you to tell the difference between unconnected and connected to 5v (vi the voltage divider).

So, put a resistor on a different pin, and use that to probe the state of the input. The resistance needs to be quite a bit higher than the resistance in the voltage divider.