SD card interrupt

i am using a SD card module with arduino mega, and i want to get an interrupt each and every time when the SD card is inserted into the sd card module. how could it posible to do that??

Typically, there is a card detect switch, connected to a pin. That pin is not usually connected to the Arduino. But, you could connect it, to an interrupt pin.

Since you didn't mention which SD card reader you have, or how it is connected, you're going to be on your own here.

i am using this sd card module
can u help me with the code??
when using interrupts the serial communication is blocked??? is that true??

Well, it looks like the Card Detect line is connected to pin 6 on J2. You could wire that up to an interrupt line on your Arduino and that should set you up just fine.

I would test it with a simple digitalRead() prototype first to make sure it's going to work. Plug it into Arduino INT0 (pin 9) and write a program that blinks or sends a Serial.Print() when the digitalRead() toggles. See if it goes LOW or HIGH when you plug a card in. Once you know that, you'll know how to do the attachInterrupt().

when using interrupts the serial communication is blocked??? is that true??

Serial data output relies on interrupts,,,, which are disabled while the interrupt service routine is running....

So,,,, serial output in an ISR is not a good idea.... Too much of it can cause the Arduino to hang....

Does the extra punctuation help????

Is it a good thing to connect CD pin directly to Arduino digital pin? or do It needs to connect 10K resister between CD pin and digital pin ? what is the proper way to use this pin?

Adafruit says :

There's one more pin CD - this is the Card Detect pin. It shorts to ground when a card is inserted. You should connect a pull up resistor (10K or so) and wire this to another pin if you want to detect when a card is inserted. ...

The pullup goes between the +5V and the and the Arduinos pin. Or you could just turn on the internal pullup, look in the reference section.

Mark

Do you mean like this?