Hello, I'm pretty new to electronics and loving my arduino journey. I'm currently exploring the external interrupt input pins on an arduino pro mini. I understand these are digital pins 2 and 3 which I plan on using both for a project.
I am planning on having three external inputs to wake the board. I will have a PIR sensor to trigger pin 3 and want two switches to trigger pin 2. The issue I'm facing is that depending on which switch I trigger I want specific code to run on wake up. What would be the best way to achieve this on a pro mini?
I'm thinking of using two more additional digital inputs for pin 2 and somehow isolating them but I don't know if I'm on the right track.
I have a attached a basic schematic of my thinking. I'm not too familiar with diodes. Could something like this work?
D1,D2,D4 are all held HIGH
When switch1 is pressed -> D2 == LOW && D1 == LOW
When switch2 is pressed -> D2 == LOW && D4 == LOW
Hopefully you guys can see the general idea. Any advice would be greatly appreciated. Thank you in advance.
the real first question is "do you need interrupts at all?"
You have indeed the two external interrupts on pin 2 and 3 but your arduino pro mini supports also pin change interrupt, so you could use 3 pins, one for each switch
Nothing in what you have said suggests you need an interrupt for the inputs. There are a number of tutorials that help with this, here are the ones I usually suggest but there are others:
Yes, your diodes will work. But pick a replacement for D1. D0 and D1 are the serial Tx and Rx pins, and it's best to leave them alone if you can. Configure all three pins as INPUT_PULLUP, and make the interrupt FALLING. Then of course you need to consider switch bouncing which would cause multiple interrupts from the same button press.
Also note that you really only need D2 plus one other pin and diode. Connect D2 to one switch, and D4 to the other switch, plus a diode from D2 to D4. If the interrupt triggers but D4 is still high, then it was the D2 switch that triggered the interrupt. Unless D4 is bouncing.
Thank you! Yes I'll only use D2 and D4 and ditch D1 - totally makes sense. The circuit works with a 1N4004 diode. Would this diode be a bit overkill for this purpose? What sort of diode would be best?
As Paul_B said, traditionally you would use a "signal diode" like the 1N4148 for this.
But again I suggest you consider how you might deal with switch bounce. Mechanical switches bounce. It can be dealt with in hardware or software or both. There are a number of helpful Youtube videos on "switch bounce".