Hello guys I am new to arduino programming so I will like some help on a project i am doing. I will like to ask that if AttachInterrupt can use any delay in the void part. Thanks.
You can make it work but really you shouldn't. If you want a specific thing to occur X milliseconds after an interrupt, use the interrupt handler to record the millis() and return control to the main loop. The main loop has the responsibility for checking when it's time to do the specific thing.
Remember the Arduino can execute 16,000 instructions in each millisecond so a delay of only one millisecond is throwing away thousands of processor cycles that might have been useful for something else.
There is no void part! - void is the return type of the function and means that the function returns nothing ie void.
Your a newb so - Never use delay
Read up on interrupts - this time do it properly!
Keep ISR's Short and sweet!
You must not ever call any function such as delay or anything that uses, directly or in indirectly an interrupt from with in an ISR!
Or in short NO
Can I use my PIR sensor as an interrupt to start my programme? If yes can i put my GSM programming in the ISR?
KappaRino: Can I use my PIR sensor as an interrupt to start my programme? If yes can i put my GSM programming in the ISR?
You could have code in setup() that runs in an endless loop until it detects the PIR signal. There is no need for an interrupt.
NO you can't put GSM programming in an ISR. First, GSM programming needs to use interrupts and interrupts are switched off during an ISR. Second, the code would take too long. You should consider an ISR very long if it takes more than 100 microsecs to complete. The aim should be to make every ISR as short as possible.
As you were advised earlier you can use an ISR to set a flag variable which your main program can use to determine that it is time to do the GSM stuff.
However I doubt if even that is necessary. Interrupts are for detecting very short-lived events or things that happen very frequently. By comparison humans work at a snail's pace.