I’m constructing an arduino based sytem that uses a SD card and I’m looking for a way to safely remove the card from the system during operation. One way would probably be to turn of the arduino before removal of the SD card, but that is not acceptable in this context.

The library I’m using: https://www.arduino.cc/en/Reference/SD

Is it possible to safely remove the SD card during operation? If no, how can I minimize the risk of damage to the SD card while inserting and removing it?


The physical construction of the card and socket are designed such that power to the card is cycled properly when the card is inserted and removed. The only thing the firmware has to do is to stop writing to the card before it is removed.

Unexpected removal can cause a problem in "larger" systems (e.g. cellphones or PCs) because they may have structures open on the card that are not yet complete, but small embedded systems typically do not have the capability to do so and so once all writes are completed the card can be removed.

Detection of non-presence of a card is another issue though, and the firmware will have to be designed to not fail in such a situation.


In my early days of computing, the computer used to turn on a led when writing to cassette tape or floppy disk. If you wanted to remove the tape or disk, you had to wait for the led to turn off. I think that could be your easiest solution.


An SDCard is very much like a hard disk drive. Both in how it is made and how it is treated by the host. As such there are critical times where interrupting the communication to the SDCard can cause corruption.

To avoid problems it is advisable to finish all transaction before removing the SDCard. In a perfect situation all data will be flushed from the host's buffers (cache) and the files being accessed closed. So research the flush() and the close() function calls in the library you are using.

In order to accomplish the above, it is obvious the host device needs to be told the SDCard is about to be removed. In most cases this is accomplished using a switch (human interface) and some code to flush and close any open files.

All this said, often people pull SDCards with out any obvious problems. This is likely because SDCard transactions are fast and completed in fractions of a second. Also pulling an SDCard when periodically reading a file is far safer then when writing to a file or altering any information on the SDCard (for example the name of a file). If you can suffer the possibility of corruption, it may be that the added effort is not worth it. However if you stand lose a great deal, I would advise you to do some research into the best ways to avoid SDCard corruption.

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.