Accurate and effective data logging is essential in the field of electronics and data gathering.
This project shows how to assemble an Arduino UNO, a micro SD card, an IC 7809 voltage regulator, and an IC LM35 temperature sensor to create a simple data logger.
With this configuration, you may store temperature data over time onto a micro SD card for analysis at a later time for a variety of uses, including environmental monitoring, gathering data for experiments, and teaching.
Code with Explanation:
#include <SPI.h>
#include <SD.h>
const int chipSelect = 10; // SD card select pin
const int tempPin = A0;
void setup() {
Serial.begin(9600);
Serial.println("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("Card initialized.");
// Create a file on the SD card
File dataFile;
dataFile = SD.open("temperature.txt", FILE_WRITE);
// Write a header to the file
dataFile.println("Time, Temperature (Celsius)");
dataFile.close();
}
void loop() {
// Read the temperature from the LM35
int sensorValue = analogRead(tempPin);
float temperature = (sensorValue * 5.0) / 1023.0 * 100.0; // Adjust formula as needed
// Get the current time
DateTime now = DateTime.now();
// Write the data to the file
File dataFile;
dataFile = SD.open("temperature.txt", FILE_WRITE);
dataFile.print(now.hour());
dataFile.print(":");
dataFile.print(now.minute());
dataFile.print(":");
dataFile.print(now.second());
dataFile.print(",");
dataFile.println(temperature);
dataFile.close();
// Print the data to the serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" degrees Celsius");
delay(1000); // Delay for 1 second
}
Explanation:
- To communicate with the SD card module, use the SPI library, which is included using #include.
- The SD library is included for SD card operations by using #include .
- The pin number (10) associated with the chip select (CS) pin of the SD card is defined by const int chipSelect = 10;.
- const int tempPin = A0;: Defines the pin number (A0) attached to the analog input of the LM35 temperature sensor.
- Serial.begin(9600);: For debugging reasons, this initializes serial communication at a baud rate of 9600.
- The SD card module is attempted to be initialized if (!SD.begin(chipSelect)).
- The SD.begin() method returns true if it is successful.
- Otherwise, an error message is shown.
- dataFile = SD.open(“temperature.txt”, FILE_WRITE);: This opens the “temperature.txt” file on the SD card available for writing.
- dataFile.println(“Time, Temperature (Celsius)”);: This prints the data format as a header line to the file.
- The file is closed with dataFile.close();.
- The LM35 temperature sensors analog value is read using the formula int sensorValue = analogRead(tempPin);.
- The temperature is converted from the analog value to a degree Celsius using the formula float temperature = (sensorValue * 5.0) / 1023.0 * 100.0;.
- Based on the features of your particular sensor, modify the formula as needed.
- DateTime now = DateTime.now();: Uses the DateTime library to obtain the current time.
- The “temperature.txt” file is opened for writing when dataFile = SD.open(“temperature.txt”, FILE_WRITE);.
- dataFile.print(now.hour()); dataFile.print(“:”); dataFile.print(now.minute()); dataFile.print(“:”); dataFile.print(now.second());: Writes the current time (hour, minute, and second) to the file.
- dataFile.print(“,”);: This prints the temperature and time values separated by a comma.
- The temperature reading is written to the file by using dataFile.println(temperature);.
- The file is closed with dataFile.close();.
- Serial.print(“Temperature: “); Serial.print(temperature); Serial.println(“degrees Celsius”);: This prints the temperature to the serial monitor for troubleshooting.
- delay(1000);: Prevents the loop from iterating again for one second.
Circuit Working:

Parts List:
Component | Quantity |
---|---|
Arduino UNO | 1 |
Micro SD Card Module | 1 |
IC 7809 Voltage Regulator | 1 |
IC LM35 Temperature Sensor | 1 |
A well-liked and adaptable microcontroller board for a range of electronic applications is the Arduino UNO.
It interfaces with the other components to gather and analyze data, acting as the projects central control unit.
For data logging, the micro SD card offers an extendable and practical storage option.
The LM35 sensors temperature measurements will be stored in this project.
This voltage regulator maintains a steady 9V output.
Powering the parts of this project that need controlled voltage in order to function properly is crucial.
The LM35 temperature sensor is a precise temperature sensor that yields an analog output that varies in direct proportion to the measured temperature.
Its purpose is to take the outside temperature and send the data to the Arduino.
How to Build:
To build a Simple Micro SD Card Data Logging Circuit with Arduino UNO following are the steps for connections:
- Gather all the components as mentioned in the above circuit diagram.
- Connect a regulated IC 7809 to provide a regulated 9V DC to the Arduino board as per the above circuit diagram
- Connect the Vcc pin of the IC LM35 to the 5V pin on the Arduino board.
- Connect the Ground pin of the IC LM35 to the Ground pin on the Arduino board.
- Connect the Vout pin of the IC LM35 to an analog input pin A0 on the Arduino board
- Connect GND pin of Micro SD Card Module to GND pin on Arduino board.
- Connect Vcc pin of Micro SD Card Module to 5V pin on Arduino board.
- Connect MISO pin of Micro SD Card Module to pin 12 on Arduino board.
- Connect MOSI pin of Micro SD Card Module to pin 11 on Arduino board.
- Connect SCK pin of Micro SD Card Module to pin 13 on Arduino board.
- Connect CS pin of Micro SD Card Module to pin 10 on Arduino board.
Conclusion:
The framework for developing more complicated data recording systems is provided by Simple Micro SD Card Data Logging Circuit.
It may be expanded to include longer data storage durations, various sensor monitoring, and system integration for analysis and display.
Understanding the projects guiding principles will enable you to design customized data logging solutions for a range of uses.
Leave a Reply