help on interrupt use

Hello,

I'm new on this forum and with arduino I'm trying to devlop a small program where i want to use an interrupt, the problem is that once the interrupt is used the program is not returning to the loop function ( i think) who can help me out ?

Here is my code ...

const int camPin = 2;
const int flash1Pin = 7;      //octocoupler pin
const int ledPin = 13;        

//------------------------------------------------------------------------------------------------

void setup() {
  attachInterrupt(0, flashOn, FALLING);

  pinMode (camPin , INPUT);
  pinMode(flash1Pin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  digitalWrite (ledPin,LOW);

}
void loop() {
  delay(1000);
  digitalWrite (flash1Pin, LOW);
  digitalWrite (ledPin,LOW);
  Serial.println ("ledPin is LOW");
}


void flashOn(){

  digitalWrite (flash1Pin,HIGH );
  digitalWrite (ledPin,HIGH);
  Serial.println ("function exectued");

}

My led is of if pin 2 is HIGH if i put pin 2 LOW the led is on but stay on fore ever :astonished:

Do NOT use Serial.print() in an interrupt service routine.

What is connected to the interrupt pin - pin 2?

hello,

for testing i just connected a wire with 5V when i disconnect the interrut routine is fired when i reconnect the led stays on …

thx

when i disconnect

the pin is floating so

the interrut routine is fired

so

the led stays on ...

Connect a resistor from the interrupt pin to ground.

thank you that sound logic and it works ... somethimes :~ for some reason the arduino stops i have no serial feedback anymore it the led stays on ...?

If i restart the serial monitor it seems that the arduino reinitialize and the program functions again ?

any ID ? does should is use a specific value for my resistor ? I'm using a 57K

thx

found the error and it was mentioned in the answer ... :blush: i removed the Serialprint from my function and it is working now al the time thanks

someone can explain why the print function can't be used with interrupt ?

someone can explain why the print function can’t be used with interrupt ?

Because it writes data to a buffer. When the buffer is full, it needs to wait until there is room in the buffer.

Room is made in the buffer by interrupts happening, to shift the data out. Interrupts don’t happen when your ISR is running, so there is never going to be more room in the buffer, so print() will never return.

thank you for your help , up to the next question XD