trying to use one inturrupt to catch 27 pins

i have 27 reed switches, which can not be triggered simultaneously.
mybe i could use this snippet to use an interrupt to catch/rule them all.
and if so, what pull-up resistor scheme will work for that configuration.

//trying to use one inturrupt to catch 5 pins
// by connecting all 5 reed switches to the same Interrupt AND
// connecting them indevidually to digital pins.

volatile int state = LOW;
volatile int whichOne[]={0,0,0,0,0,0};

void setup()
  attachInterrupt(0, blink, RISING);
  //init pullup resistor
  for(int i=8;i<=12;i++){

void loop()

void blink()
  for(int i=8;i<=12;i++){

Well your wiring isn’t correct yet. The way you have it now, if any switch turns on you create a short circuit from +5 vdc to ground. Also pins 8 to 12 are directly wired to ground, how can they go high ever?


indeed, do u think this will work? is my logic totally flawed?

What else is the sketch doing? Is an interrupt really necessary? Polling 27 switches does not take long. How critical is catching precisely when a switch triggered? With the scheme you have in mind, but not wired correctly, you still need to poll each switch when the interrupt occurs, to see which one triggered the interrupt.

those reed switches take care of stoping a dc motor going off its rail. i have 6 dc motors (with several stops along the way) and 12 blinking LEDs.

those DC motors i use are slow (30RPM) so i think i can pull it off without the interrupts. but still. i would like to know if this can work. and any worng doings in the second circuit :)

The second circuit looks better, except that you need a diode between the switch and the interrupt pin. Otherwise, any switch closing will trigger the interrupt and set all the pins HIGH. Probably not what you want.

and any worng doings in the second circuit

It could work if each of the input pins including the interrupt pin have a pull-down resistor, say 10k ohm, wired to ground. Otherwise you will have floating input pins and flacky interrupts. And as Paul said each wire to the interrupt pin should be replaced with a diode, cathode towards the interrupt pin.


thank you guys, like this?

btw. to all the new guys, im using fritzing for the schematics, it easy and has tons of examples.

Not quite. Move the diodes to be between the interrupt pin and the switches, the resistors wire from ground to switches. Interrupt pin needs it's own pull-down resistor to ground. Also you show other end of resistors going to Aref, not ground pin.


hey Lefty, hope i got you right. cant i use the built in pull-up for PIN 12?

cant i use the built in pull-up for PIN 12?

That drawing is correct for postive logic, although you have still forgotten the pull-down resistor for the interrupt pin 2 to ground.

You can use the built in pull-up resistors for all the digital input pins and the interrupt pin, however you will have to change the switches common side (red wires) to go to ground instead of +5vdc. Then the interrupt will have to trigger on falling value and your software logic has to associate a 0 to switch activated and a 1 to switch not activated. If you use internal pull-up then all the diodes have to be turned around, anode to interrupt pin.


btw. i dont see a reason i cant use just one diode for all the wires going to the interrupt, correct? i hope thats it, i didnt know you can use the internal pullUp on an interrupt (why ever not actually).

I think you are going to need something like this when you are all done, as you don't have 27 inputs on a duemilanove or uno.

With some parallel load shift-in registers likes the 74HC166 (not the actual part pictured here) you will pull the inputs high. When the reed switch closes to ground, input pin & associated diode will go low, causing an interrupt, during which you send out a Load pulse to the '166s to capture the state of the input pins, which can then be read in via a shift-in command (27 switches, so 4 registers in series to bring in 32 bits). Bournes makes things like the network resister package. I don't know if anyone makes a netword diode package, that would be convenient :-)

btw. i dont see a reason i cant use just one diode for all the wires going to the interrupt, correct?

Well you do need a diode from each switch for proper isolation, this is called a diode 'wired or gate'. Without a diode for each switch, while you will get a common interrupt from any switch activated, once in your interrupt function you won't be able to tell which switch in on, as all would read low without all the diodes.

You finally have a correct functional drawing using two switches. If can be expanded to the number of avalible input pins you have free. Recall that you can also utilize the 6 analog input pins as digital input pins if you wish.


@retrofly, thanks for your patient support. @crossroads- do you know of a guide for using resistor networks. i went over the datasheet but couldn't really understand how it works. 10 legs in a single row. should i just treat them as pairs? shared ground ?

Look at the diagram in the middle of page 2. You want the "bussed resister" network. For pullups, pin 1 goes to +5V, and the individual resistors are then wired as shown in the schematic. Alternatively, get the Isolated resisters, and wire pisn 1,3,5,7... together to +5V, same as if you had a bunch of indidual resisters. The last option is intended to be used for terminating long runs of clock or datas line that have multiple things connected to them, to hold the voltage at a certain level. I would not use that one if you had the ability to use the bussed part instead.

These kinds of parts are also available in DIP packages such as this: The SIPs can be used where space is more limited.