SD Card Module with Arduino & ESP32, Arduino Data Logger, ESP32 Data Logger

(Last Updated On: September 12, 2021)

 

SD Card Module with Arduino & ESP32:

SD Card Module

SD Card Module with Arduino and ESP32- There are times when you need to store the sensor’s values in a text file for later processing. In order to save the values in a text file, you will need an SD card module like the one you can see in the image given below.

SD Card Module

In this tutorial, you will learn how to interface this low-cost and commonly used SD card Module with Arduino to make an efficient Arduino Data Logger. We will also use the Micro SD card Module with the ESP32 for logging or storing the Sensor Data in a text file.

SD Card Module

In this tutorial, I will also explain how to use this Micro SD card Adaptor with the ESP32 Wifi + Bluetooth module if in case you don’t have this SD card Module.

As this is a very basic getting started tutorial on how to use the Card module and SD card adaptor with the Arduino and ESP32 so, I have tried my best to keep things simpler so that you guys can easily follow each and every step. I will use the potentiometer as the sensor for the data logging which of course you can replace with any other sensor as per your requirement.

Without any further delay let’s get started!!!



Amazon Purchase Links:

Arduino SD Card Module

8GB Micro SD Card

Micro SD Card Adaptor

ESP32 Wifi + Bluetooth Module:

12v Adaptor:

Arduino Uno

Arduino Nano

RTC DS3231 Real Time Clock:

DHT11 Temperature and Humidity Module:

Other Tools and Components:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

SD Card Module Pinout and technical Specification:

SD Card Module

This is the SD Card Reading and Writing Module which can be easily interfaced with Arduino and other embedded boards and microcontrollers. With a very basic program, you can read and write to the SD card over the SPI interface. This card module is provided with the onboard 3.3V voltage regulator due to which it can be interfaced with 3.3V compatible controller boards like ESP32 and ESP8266, etc. In order to use the micro SD card with this module, you will need a micro SD card adaptor.

This SD card module is provided with male headers which are clearly labeled as

GND

3.3V

5V

CS

MOSI

SCK

MISO and

GND

If you are planning to use this Card Module with the Arduino then connect the 5v pin with the Arduino’s 5V, and if you are planning to use this Card module with the ESP32 then connect the 3.3v pin with the ESP32 3.3V pin. Never use 5 volts when using this SD card module with 3.3V compatible controller boards.

While performing the initial tests, I powered up the SD card module using 3.3V and it didn’t work. Then I powered up this module using the Arduino’s 5V and it worked. So, in a nutshell, if you are using the Card Module with the Arduino then use 5volts, and if you are using the Card Module with the ESP32 or ESP8266 then use 3.3V. For more details read my article available on electroniclinic.com. I will provide a link in the description. So, first, let’s start with the Arduino and Card Module.




SD Card Module, Description:

This SD Card Reader/Writer is ideal for many Micro-controller projects (Arduino, Pic, Versalino, etc…) Including (but not limited to) projects involving sensor and other data logging activities. Audio playing and/or recording. Video, Image, and other multimedia storage and retrieval for advanced embedded applications. Processing large quantities of data with a robot, or storing/retrieving items larger than the limited memory available on your microprocessor. This can be used for a broad range of applications from scientific data collection for biological/geological and other statistical studies in the field, to storing map data for your robots surroundings in and outside the home.

Technical Specifications:

Working Voltage: 3.3 & 5V(DC Both required) Requires SPI Capable Microprocessor Size limitations are library dependent, but most microprocessors have libraries pre-coded that will support sizes upward of 1GB 7 wires required (including power and ground) Fits standard size SD Cards Package Contents: 1*SD Card Reader/Writer

Arduino Uno and Arduino Mega SPI pins:

SD Card Module

ESP32 SPI Pins:

For the complete ESP32 Pinout read my article.

SD Card Module Interfacing with Arduino:

SD Card Module

The rightmost and leftmost legs of the Potentiometer are connected with the Arduino’s 3.3V and GND. The 5V and GND pins of the SD Card Module are connected with the Arduino’s 5v and ground. CS is connected with pin 10, MOSI is connected with pin 11, SCK is connected with pin 13, and MISO is connected with pin 12 of the Arduino.

Next, I connected the Card Module and the Potentiometer with the Arduino as per the circuit diagram already explained. Now, let’s take a look at Arduino programming.


Arduino SD Card Module Programming:

SD Card Module Arduino Code Explanation:

For this program, there is no need to download any libraries. The SPI.h and SD.h libraries are already included in the Arduino IDE. The purpose of this program is to read the potentiometer and then store the value in the DATA.txt file. One more thing that I would like to mention over here is that, format your micro SD card using the FAT32 file system and then make a txt file with the name DATA and the rest Arduino will take care of. So, anyhow, LoggingVresistor() function is a user-defined function and this is the only function I am using inside the void loop() function. This function is called after every 5 seconds, reads the potentiometer, store the data in variable Vrdata then the Arduino opens the DATA.txt file to write the Potentiometer value and then close the file. I have already uploaded this program; let’s watch this Arduino Data Logger in action.

SD Card Module

As you can see we successfully stored the Potentiometer values in the DATA.txt file. Now, I am going to explain how to interface the SD Card module with the ESP32.

As explained earlier, the card Module also supports 3.3V. So, it can also be easily interfaced with the ESP32 module.


SD Card Module interfacing with ESP32:

SD Card Module

The potentiometer’s rightmost and leftmost legs are connected with the 3.3v and GND pins, while the middle leg is connected with the VP pin of the ESP32 which is the GPIO36 and this is the ADC0.

The SD Card Module 3.3V and GND pins are connected with the ESP32 3.3V and GND pins. CS is connected with D5, MOSI is connected with D23, SCK is connected with D18, and MISO is connected with D19.

SD Card Module

Next, I connected the Card Module with the ESP32 as per the circuit diagram already explained. Now, let’s take a look at the programming.

ESP32 SD Card Module Programming:


SD Card Module ESP32 Code Explanation:

In order to use the SD Card Module with the ESP32 first, you will need to install the ESP32 board. I have a very detailed tutorial on this which explains how to add the board manager url link for the ESP32. This time you can see I added another library FS.h, you will get this library when you install the ESP32 board. So there is no need to download this library.

The purpose of this program is to read the potentiometer and then store the value in the txt file. This code automatically creates the txt file. I have already uploaded this program let’s watch this ESP32 Data Logger in action.

SD Card Module

As you can see we successfully stored the Potentiometer values in the text file. You can connect and store values of multiple sensors.

Micro SD card Adaptor Interfacing with ESP32:

SD Card Module

If in case you do not have this Card Module then you can also interface this Micro SD Card Adaptor with the ESP32.

SD Card Module

Follow these connections. These are the same exact connections that we used for the SD Card Module.  For easy interfacing, I started by soldering the male headers. Now using these male headers I can easily interface this Micro SD Card Adaptor with the ESP32 and other 3.3V compatible controller boards.

SD Card Module

I connected the Micro SD Card Adaptor with the ESP32 as per the interface connections, the Potentiometer connection with the ESP32 remains exactly the same.

We will be using the same program. Now let’s watch this Micro SD Card Adaptor and ESP32 based Data Logger in action.

SD Card Module



Arduino Temperature Data Logger using SD Card Module:

I covered the basics now let’s make a temperature data logging system using the Card Module and Arduino which saves the temperature in a text file with the date and time information. For this project, you should have a basic understanding of how to use the DHT11 Temperature and Humidity Sensor and you should also know how to use the Real Time Clock DS3231. So, I highly recommend reading these two articles, if you really want to learn how to use the DHT11 and DS3231 modules.

Arduino Temperature Data Logger Circuit Diagram:

SD Card Module

Arduino Temperature Data Logger Programming:


Watch Video Tutorial:

 

 

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

%d bloggers like this: