2

I have an Arduino Uno R3. I have a paddlewheel waterspeed sensor that I use on an ISR on pin 2. The power supply is approximately 8v stepped down to 4.92v with a circuit yanked from the phone charger. I have also tried this with the arduino 5v.

The pin returns the correct values with digitalRead(), so it's cycling between 1 and 0.

The ISR works fine on pin3. Why does it work on pin 3 and not pin 2 ISR?

void itest() {
    Serial.println( "test" );
}

void setup() {
    attachInterrupt(0, itest, FALLING);
}
  • Have you compared the disassembled code when using each pin? – Ignacio Vazquez-Abrams Mar 31 '14 at 1:21
  • Can you show us the code of the ISR and how you registered it? – jfpoilpret Mar 31 '14 at 5:19
  • Where do you set pinMode() of pin 2 to INPUT? – jfpoilpret Mar 31 '14 at 11:18
  • @jfpoilpret it doesn't need pinMode() and the ISR is hidden by the arduino code in the attachInterrupt – Lesto Mar 31 '14 at 19:48
  • I hope you haven't forgotten to change attachInterrupt(0,itest,FALLING); to attachinterrupt(1,itest,FALLING); – explorer Apr 24 '15 at 8:48
3

never use Serial inside an interrupt handler, increment a (volatile) variable and print it in the loop().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.