My Cart

MicroSD Module for Arduino

Difficulty Level: Beginner -

Introduction

Ingredients:

Preparation Time: 45 minutes

Step 1: The microSD module

With this microSD module for Arduino, we add a really big amount of data storing space. This module lets us plug a microSD card (Standard Flash memmory card) and write / read data in it.

The main idea of this module is that an Arduino with this SD "expansion" is able to store a big amount of data.

The SD card is connected to Arduino SPI port, analog pins, digital (0-7) pins and UART are available.

For this application we'll use an example created by Ingo Korb (ingo [@] akana [dot] de) adapted by David Cuartielles. See the link below.

Step 2: Powering the module

In the image below we see the module and the jumper to select the power for the card.

The connection is very easy, the module can be connected to Arduino in two places:

If the board is connected on the Arduino's ICSP connector, it is needed to wire the SS pin in the SD board to Arduino's digital pin 8 (without that it will not work).

Step 3: Using the microSD module

For using the microSD module we'll use the Arduino library incorporated in the Arduino IDE. This library include some examples that will help us to start using the microSD module.

We must plug the card into the slot and we connect the module to arduino and arduino to a PC via USB.

The program we use for arduino is very simple, we connect to arduino with a serial port terminal (9600 bps) and we can read / write data in the microSD card.

Arduino code (example):

Code:
/*
 SD module example
 
 This example shows how to read and write data to and from an SD card file
 and how to create and destroy an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 10
 
 created   Nov 2010
 by David A. Mellis
 updated 2 Dec 2010
 by Tom Igoe
 
 This example code is in the public domain.
      
 */
 
#include <SD.h>

// define the pin that powers up the SD card
#define MEM_PW 8


File myFile;

void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
 
  // on my MicroSD Module the power comes from a digital pin
  // I activate it at all times
   pinMode(MEM_PW, OUTPUT);
   digitalWrite(MEM_PW, HIGH);
  
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
  //delete old file
    SD.remove("example.txt");
   
  // Check to see if the file exists:
  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
   
  }
  else {
    Serial.println("example.txt doesn't exist.");
  }
 
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("example.txt", FILE_WRITE);
 
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to example.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening example.txt");
  }
 
   // Check to see if the file exists:
  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  }
  else {
    Serial.println("example.txt doesn't exist."); 
  }
 
  // re-open the file for reading:
  myFile = SD.open("example.txt");
  if (myFile) {
    Serial.println("example.txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
        Serial.write(myFile.read());
    }
   
    //Delay to enable the user to stop the secuence
    Serial.println("if you want disconnect SD card ");
    delay(10000);
   
   
    // close the file:
    myFile.close();
  } else {
      // if the file didn't open, print an error:
    Serial.println("error opening example.txt");
  }
  // delete the file:
  Serial.println("Removing example.txt...");
  SD.remove("example.txt");

  if (SD.exists("example.txt")){
    Serial.println("example.txt exists.");
  }
  else {
    Serial.println("example.txt doesn't exist."); 
  }
}

void loop()
{
    // nothing happens after setup
}
                

Step 4: Using the microSD module with XBee shield

The SD module needs an extensor for the pin connector.

Step 5: Video-Tutorial

Here's an explanatory video, which shows the whole process developed in this tutorial:

Fritzing Libraries

microSD Module for Arduino is a small shield that you can connect to your Arduino board, once the shield is connected, you add SD flash memory to Arduino.

You can download our Fritzing libraries from this area.