How to Make SD Card to Store Sensor Data File using Arduino
The SD memory card comes in large storage capacities from 1 GB up to 32 GB are available. They are used mostly in costly devices like digital camera, media players etc. They are also found in low cost and simple micro-controller based systems. The SD memory cards are interfaced in high end devices using SD bus which provides very high speed data transfer between the device and the memory card. They also can be interfaced with a device using the low speed and comparatively simple SPI bus and that is the reason why the micro-controller system developers are interested in it. Due to their large storage capacity the SD card can be used to continuously store data bytes which may be read by the system from a sensor since a long period of time. The data can be directly written in the storage locations of the SD card or it can be written into a file inside the SD card. Keeping the data inside a file and that also in the text format is mostly preferred since the SD card can be removed from the system later, transport it to a distant place and can read the data using a computer.
This project demonstrate how to store the data continuously from an analog sensor into a memory card for predefined period of time and display the same data in a Serial monitoring software. In this particular project the variable pin of a potentiometer is connected to provide analog voltage for the Arduino board to read and store in the SD card which can be easily replaced with a real sensor in future projects.
This particular project uses the Arduino pro-mini board which has a very small size and can be connected with bread board compatible connectors. The Arduino pro-mini board has digital pins marked as 2, 3, 4 up to 13. Among the digital pins four pins namely 10, 11, 12 and 13 can be configured as SS, MOSI, MISO and SCK. The MISO of the memory card should be connected to the pin number 11, the MOSI should be connected to the pin number 12 and the SCK should be connected to the pin number 13 of the Arduino pro-min. The SS of the SD card should be connected to the pin which is defined as the SS pin of the Arduino in the code written. The image of the Arduino pro-mini board and the Arduino IDE version 1.0.3 for windows used in this project are shown in the following image;
Since the arduino pro-mini board has no circuitary for interfacing it with the serial port or the USB port of the PC, an external USB to TTL converter board is required to connect it with the PC. This hardware helps in programming the arduino board and also helps in the serial communication with the PC through the USB port of the PC.
It is assumed that the reader has gone through the project how to get started with the arduino and done all the things discussed in it. The memory card used in this particular project is a 2 GB SD card from Transcend but the code is supposed to work with SD card from all vendors. The SD card operates on 3.3V logic and hence to interface it with a microcontroller which runs on 5V logic one should use a Logic Level Converter. Since the memory card is interfaced using the SPI bus the four channel Logic Level Converter modules which are commonly available in the market can be used. The image of the Logic Level Converter module used in this project is shown in the following image;
The SD memory card and the low voltage side of the Logic Level Converter should be provided with the 3.3V power supply and for that one can use any 3.3V regulator IC. A bi-color LED is suggested to connect across the 3.3V positive and MISO and MOSI lines of the SD card. The image of the memory card and the required circuitry that has been built for this particular project is shown in the following image. In the image one can see a potentiometer which is actually forms the circuit with an SMD variable regulator IC LM117 underneath it. It is recommended to use LM1117 which is a 3.3V regulator and which does not require other components to set the voltage as shown in the circuit diagram of this project.
The Arduino IDE provides a library called <SD.h> which has lot of functions to access the SD memory card. The library is able to access the FAT16 or FAT32 filesystem of the SD card using the AVR microcontroller of the Arduino board so that the files can be read, modify or write. The functions used in this particular project are SD.begin(), SD.open(), file. println(), file.read(), and file.close() from the library <SD.h> and the details regarding them are explained in a previous project on how to interface SD card with Arduino.
The Arduino board has several digital pins which can be configured as digital I/O pins and among them some can also be used as analog output pins. There are dedicated analog input pins also in most of the Arduino boards. The Arduino pro-mini board has 8 analog input pins marked as A0, A1 up to A7. In this particular project the variable pin of a potentiometer is connected at the analog input pin A0.
The Arduino IDE provides functions to access analog input and analog output of the board. The code written for this project uses the built-in function provided by the Arduino IDE namely analogRead() and analogWrite(). The functions are already used in the previous projects on how to use analog input and analog output of Arduino board, how to use Arduino to display sensor values, how to make dynamic sensor display using Arduino, how to save sensor values in the EEPROM of the Arduino.
The code create or open a file “sensor.txt” and store 50 sensor values which has been read with a delay of half a second between them. Once the 50 values are read the code reads the entire file and displays it in the Serial monitor. The data is transferred from a file from the SD card and is monitored using the Serial monitor window with the help of the serial communicating functions written in the code. The functions used in this projects are namely Serial.begin(), Serial.println() and Serial.write(). The details of these functions and similar functions for the serial communication are already discussed in previous projects on how to do serial communication with the Arduino, how to send and receive serial data using arduino, how to do serial debugging with the Arduino.
When the coding is finished one can verify and upload the code to the Arduino board as explained in the project how to get started with the Arduino. The code will initialize the SD card, create a file “sensor.txt” and store 50 sensor values in it and read back the entire file. One can observe the data read from the file with the help of Serial monitor as explained in the project on how to do serial debugging with the Arduino.
Resistor is a passive component used to control current in a circuit. Its resistance is given by the ratio of voltage applied across its terminals to the current passing through it. Thus a particular value of resistor, for fixed voltage, limits the current through it. They are omnipresent in electronic circuits....
Light emitting diodes (LEDs) are semiconductor light sources. The light emitted...
Arduino Pro Mini
The Arduino Pro Mini is an ATmega168 based microcontroller board. The board comes with built-in arduino bootloader. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 8 analog inputs, an on-board resonator, a reset button, and holes for mounting pin headers....
Free TI Design & Simulation Tools
WEBENCH Design Environments are unique and powerful software tools that deliver customized power, lighting, filtering, clocking and sensing designs in seconds. These easy-to-use tools help you generate, optimize and simulate designs that conform to your unique specifications. They allow you to make value-based tradeoffs at a design, system and supply chain level before your design is committed to production.
Design & Simulation Tools
Sensors, Filter, Clock and Amplifier Design
Download Tools, Models and Symbols