Stufin
Home Quick Cart Profile

SD Card Module

Buy Now on Stufin

Interface

SD/MMC

Voltage

3.3V to 5V

Power Consumption

10mA to 50mA

Storage Capacity

1GB to 1TB or more

File System Support

FAT16, FAT32, NTFS

SPI Interface

Up to 50MHz

Operating Temperature

-40C to 85C

Dimensions

Typically 15mm x 15mm x 2mm (L x W x H)

Conclusion

The SD Card Module is a versatile and widely used IoT component that provides a convenient and cost-effective way to add storage capacity to IoT devices. Its compact design, low power consumption, and support for various file systems make it an ideal choice for a wide range of IoT applications.

Pin Configuration

  • SD Card Module Documentation
  • Overview
  • The SD Card Module is a microSD card adapter that allows you to read and write data to microSD cards using a microcontroller or a single-board computer. It is a popular accessory for IoT projects, robotics, and other applications that require data storage.
  • Pinout
  • The SD Card Module typically has 6 pins, which are explained below:
  • 1. VCC (Power Supply) Pin
  • Function: Provides power to the SD Card Module
  • Voltage: Typically 3.3V or 5V, depending on the module's specification
  • Connection: Connect to the power supply of your microcontroller or single-board computer
  • 2. GND (Ground) Pin
  • Function: Provides a ground reference for the SD Card Module
  • Connection: Connect to the ground of your microcontroller or single-board computer
  • 3. CS (Chip Select) Pin
  • Function: Used to select the SD card as the active device
  • Logic Level: Active low (i.e., a low voltage level selects the SD card)
  • Connection: Connect to a digital output pin of your microcontroller or single-board computer
  • 4. SCK (Clock) Pin
  • Function: Used to clock data into and out of the SD card
  • Frequency: Typically up to 25 MHz, depending on the module's specification
  • Connection: Connect to a digital output pin of your microcontroller or single-board computer
  • 5. MOSI (Master Out Slave In) Pin
  • Function: Used to transmit data from the microcontroller or single-board computer to the SD card
  • Data Direction: Output from the microcontroller or single-board computer, input to the SD card
  • Connection: Connect to a digital output pin of your microcontroller or single-board computer
  • 6. MISO (Master In Slave Out) Pin
  • Function: Used to receive data from the SD card
  • Data Direction: Input from the SD card, output to the microcontroller or single-board computer
  • Connection: Connect to a digital input pin of your microcontroller or single-board computer
  • Connection Structure
  • Here is a general connection structure for the SD Card Module:
  • Connect VCC to the power supply of your microcontroller or single-board computer
  • Connect GND to the ground of your microcontroller or single-board computer
  • Connect CS to a digital output pin of your microcontroller or single-board computer (e.g., GPIO pin)
  • Connect SCK to a digital output pin of your microcontroller or single-board computer (e.g., GPIO pin)
  • Connect MOSI to a digital output pin of your microcontroller or single-board computer (e.g., GPIO pin)
  • Connect MISO to a digital input pin of your microcontroller or single-board computer (e.g., GPIO pin)
  • Important Notes
  • Make sure to check the datasheet of your specific SD Card Module for any specific connection requirements or restrictions.
  • Use a level shifter if your microcontroller or single-board computer operates at a different voltage level than the SD Card Module.
  • Ensure that your microcontroller or single-board computer is capable of handling the maximum clock frequency of the SD Card Module.
  • By following these pin connections and guidelines, you can successfully integrate the SD Card Module into your IoT project or application.

Code Examples

SD Card Module Documentation
Overview
The SD Card Module is a widely used IoT component that enables microcontrollers to read and write data to SD cards, greatly expanding their storage capacity. This module is compatible with most microcontrollers, including Arduino, Raspberry Pi, and ESP32/ESP8266.
Pinouts and Connections
The SD Card Module typically has the following pinouts:
VCC: Power supply (3.3V or 5V)
 GND: Ground
 SCK: Serial Clock
 MOSI: Master Out Slave In
 MISO: Master In Slave Out
 CS: Chip Select
Example 1: Reading and Writing Files using Arduino
In this example, we will use the SD Card Module with an Arduino Uno to read and write files to an SD card.
Hardware Requirements
Arduino Uno
 SD Card Module
 SD Card (at least 1GB)
 Breadboard and jumper wires
Software Requirements
Arduino IDE (version 1.8.x or later)
Code
```c++
#include <SPI.h>
#include <SD.h>
// Set the chip select pin for the SD card
const int chipSelect = 5;
void setup() {
  Serial.begin(9600);
  
  // Initialize the SD card
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    while (1); // Wait forever
  }
  Serial.println("Card initialized.");
}
void loop() {
  // Create a file on the SD card
  File dataFile = SD.open("data.txt", FILE_WRITE);
  
  if (dataFile) {
    dataFile.println("Hello, World!");
    dataFile.close();
    Serial.println("Data written to file.");
  } else {
    Serial.println("Error opening file.");
  }
  
  delay(1000);
  
  // Read the file from the SD card
  dataFile = SD.open("data.txt", FILE_READ);
  
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
  } else {
    Serial.println("Error opening file.");
  }
  
  delay(1000);
}
```
Example 2: Logging Sensor Data using Raspberry Pi
In this example, we will use the SD Card Module with a Raspberry Pi to log sensor data from a temperature and humidity sensor.
Hardware Requirements
Raspberry Pi
 SD Card Module
 DHT11 temperature and humidity sensor
 Breadboard and jumper wires
Software Requirements
Raspbian OS (version 10 or later)
 Python 3.x
Code
```python
import os
import time
import Adafruit_DHT
# Set the pin for the DHT11 sensor
DHT_PIN = 17
# Set the file path for the log file
LOG_FILE = "/mnt/sdcard/log.csv"
while True:
    # Read the temperature and humidity data from the DHT11 sensor
    humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, DHT_PIN)
    
    # Create a string to write to the log file
    log_string = f"{time.strftime('%Y-%m-%d %H:%M:%S')},{temperature},{humidity}
"
    
    # Write the log string to the file
    with open(LOG_FILE, 'a') as f:
        f.write(log_string)
    
    # Print the log string to the console
    print(log_string)
    
    # Wait 1 minute before logging again
    time.sleep(60)
```
These examples demonstrate the basics of using the SD Card Module with different microcontrollers. You can modify the code to suit your specific requirements and applications.