My FALLING edge is not detected at first

Hi,

I use an Arduino Uno. A falling edge on pin 4 should implicate a call of an ISR. I used the following template: http://arduino.cc/playground/Main/PcInt I wired pin 4 to +5V with a 220 Ohm resistor in between. So pin 4 is pulled up to 5V. I have an external device that uses the same ground as my Arduino board. The external device can pull down pin 4 to ground. My problem is that the board detects the pull down not the first time but all the following ones. If I unplug the wire from pin 4 at startup, plug it in again after initialization, the first pull down gets recognized. How can this be? I tried to let Arduino pull it up or down at startup but it didn't work out.

Thanks for your help!

volatile long secs = 0;

void isr1(void) {
  secs += 5;
  digitalWrite(13, HIGH);
}

...

void setup()
{
  Serial.begin(9600);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  ...
  pinMode(13, OUTPUT);
  delay(1000);
  digitalWrite(13, LOW);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  PCattachInterrupt(4, isr1, FALLING);
  PCattachInterrupt(5, isr2, FALLING);
  ...
}

void loop()
{
}

That template looks quite complicated and is an extension of the standard Interrupt support. My advice is that if you don't need PCINT (pin change interrupt) on ALL pins, ignore that and just hook your device up to Pin 2 (hardware interrupt 0).

Then change your code to attachInterrupt(0, coin1Detected, FALLING) to see if that works.

Thanks. The problem is that I need to detect at least four falling edges later.

you allready set the internal pullup resistor - digitalWrite(4, HIGH); - which is 10K (IIRC) and you put a 220 in parallel of that ==> 215.6 ohm effective.
At 5 Volt that gives ~23mA ==>0.1W

in short, remove the 220 resistor, and give it a try

The way you have configured your interrupt, it detects transitions from high to low. Since the initial input state is low, there is no transition.

If you need to know the initial state I suggest you simply read it.

robtillaart: you allready set the internal pullup resistor - digitalWrite(4, HIGH); - which is 10K (IIRC) and you put a 220 in parallel of that ==> 215.6 ohm effective. At 5 Volt that gives ~23mA ==>0.1W

in short, remove the 220 resistor, and give it a try

No, sorry, this didn't work out. I "fixed" it by not using the +5V power source but by using D12. I write LOW first and then HIGH permanently.

PeterH: The way you have configured your interrupt, it detects transitions from high to low. Since the initial input state is low, there is no transition.

If you need to know the initial state I suggest you simply read it.

The initial input state was high because of the wiring to +5V.

zzzz: The initial input state was high because of the wiring to +5V.

You said that it worked correctly when you left the wire disconnected during powerup.

By your sketch, that would be pulled high.

For the connected wire to have made a difference, it follows that your external circuit must have been pulling it low.