superturis
Published © GPL3+

Make your own SD shield

Here is how I built my own "SD shield" for another project I was working on, using a solder iron and a MircoSD adapter.

IntermediateFull instructions provided707
Make your own SD shield

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Flash Memory Card, SD Card
Flash Memory Card, SD Card
×1
5 mm LED: Red
5 mm LED: Red
×3
5 mm LED: Green
5 mm LED: Green
×1
Tactile Switch, SPST-NO
Tactile Switch, SPST-NO
×4
Through Hole Resistor, 1 kohm
Through Hole Resistor, 1 kohm
×4
Through Hole Resistor, 2 kohm
Through Hole Resistor, 2 kohm
×3
Through Hole Resistor, 3 kohm
Through Hole Resistor, 3 kohm
×3
Through Hole Resistor, 10 kohm
Through Hole Resistor, 10 kohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Breadboard

Prototype

Code

SD card I/O

Arduino
// include the SD library:
#include <SPI.h>
#include <SD.h>

// Enable button at pin 6
const int Enable  = 6;
int Data_Counter = 0;

// Input buttons at pin 5, 4, 3
const int Input_1 = 5;
const int Input_2 = 4;
const int Input_3 = 3;

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 10;

// Create a file to store the data
File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Initialize inputs
  pinMode(Enable, INPUT);
  pinMode(Input_1, INPUT);
  pinMode(Input_2, INPUT);
  pinMode(Input_3, INPUT);

  // setup for the SD card
  Serial.println("Initializing SD card...");
 
  if(!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  Serial.println();

  //open file
  myFile = SD.open("DATA.csv", FILE_WRITE);

  // if the file opened ok, write to it:
  if (myFile) {
    Serial.println("File opened ok");
    Serial.println("Waiting for inputs");
    Serial.println();
    // print the headings for our data
    myFile.println("Entry,Input_1,Input_2,Input_3");
  }
  myFile.close();
}

void loop(void) {
  if (digitalRead(Enable) == 1) {
    // Write to terminal for debugging
    Serial.print("Reading data entry ");
    Serial.print(Data_Counter); // The first is 0
    Serial.println(":");
    Serial.print("Input_1 = ");
    Serial.println(digitalRead(Input_1));
    Serial.print("Input_2 = ");
    Serial.println(digitalRead(Input_2));
    Serial.print("Input_3 = ");
    Serial.println(digitalRead(Input_3));
    Serial.println(" ");
    // Write to SD card
    myFile = SD.open("DATA.csv", FILE_WRITE);
    if (myFile) {
      myFile.print(Data_Counter);
      myFile.print(",");
      myFile.print(digitalRead(Input_1));
      myFile.print(",");
      myFile.print(digitalRead(Input_2));
      myFile.print(",");
      myFile.print(digitalRead(Input_3));
      myFile.println(",");
    }
    myFile.close();
    Serial.println("Data written to SD");
    Serial.println();
    Data_Counter++;
    delay(5000); // 5000 = 5 seconds
  }
}

Credits

superturis

superturis

0 projects • 0 followers

Comments