How would I monitor individual switches but waking if any are triggered?

I would like to be able to put a nano to sleep, and wake on D2/Interrupt. The interrupt should fire if ANY of four switches are triggered (two are shown for simplicity), but it should also be able to detect which switch or switches are in an alert state upon waking. (D4, D5)

Does this look correct or am I wildy off?

A clever solution :slight_smile:

Yep , looks good .

You could also just use a diode OR gate into d2 , and also connect the switches to other digital inputs to see which input created the interrupt .

This was my first idea as well, but a single transistor (RTL) is cheaper and easier to build than one diode for each switch.

Both are fine , just offered as an alternative for viewers .
IN4148 are cheap , about the same price as a resistor! Not that I expect it’s that important …
You can also buy resistors and diodes in multiple DIL packages , which might help a neater solution.

You don't need to connect one of the buttons to an Arduino pin. This will save you one potentially precious arduino pin. If the other buttons were not pressed, you know by process of elimination that the unconnected button must have been pressed.

Personally I would use diodes. Your transistor circuit still requires a resistor for each button. Diodes are pretty much the same size and there's no significant difference in cost unless you plan to manufacture millions of these circuits.

But it only one of these other buttons is pressed, the state of the unconnected button is unknown.

Each input requires a resistor in all circuits.

Perhaps the internal pull-ups could be used?

For sure! In all mentioned circuits.

It's not off but totally un-necessary.

You can wake a 328P with an interrupt on pin change on ANY pin or multiple pins.

3 Likes

It's not off but totally un-necessary.
You can wake a 328P with an interrupt on pin change on ANY pin or multiple pins.

That's useful information. I had read that the Nano can only be woken by pin change one of two interrupts pins which were stated as being D2 and D3.

Yep , looks good .

You could also just use a diode OR gate into d2 , and also connect the switches to other digital > inputs to see which input created the interrupt .

Thank you for that, Hammy. I appreciate the alternate solution as well.
With the OR gate, I'd be putting pulldown resistors on d4, d5, and d6, correct?

The UNO and Nano use the ATmega328P micro and there are a lot of things you can do with it for which there are no Arduino functions.

It has 6 different sleep modes. It can be woken by INT0/1, any Pin change, the WDT, Timer2 , I2C slave address match and in some modes even the ADC.

To use many of the capabilities you need to do some "Bare Metal Programming". Basically you use C code to access the 328 registers.

Here is a good example.

But the inputs are floating

Yes .. forgot that !! You can turn it all around tho and use the internal pull-ups instead . ( active low )

But won't the active pullups activate the diodes and keep D2 stuck high?

+1 for using pin change interrupts on the four lines, with internal pullup resistors. Then you can save D2 for something else. When the interrrupt occurs, you can just poll the lines until you find the one that's low. Put all four on the same port. No external parts needed beyond the switches.

Does the nano have internal pull-ups? I thought it lacked them.

Like this :

Use interrupt “low” on D2 , then check which of the others is low . Think that works and is cheapest yet !!

Best yet. Hope @B3njamin sees it

1 Like