Jump to content

Experiment 6: Data Logging Using Arduino and Excel (Serial Communication)

From cognifront

Experiment 6: Data Logging Using Arduino and Excel (Serial Communication)

Objective

To log real-time sensor data from Arduino to a computer using PLX-DAQ or Python and visualize it.

Task

  1. Write Arduino code to send temperature data from LM35 over serial.
  2. Use Excel + PLX-DAQ or Python to capture and save the data.
  3. Plot data over time (optional).

⚠️ Disconnect your Arduino from the computer while making or removing component connections.

With PLX-DAQ(parallax)

PLX-DAQ Software

Circuit Diagram

Circuit Diagram

Board Connections

Board Connections

Connections

LM35 Connect To (UNO)
GND GND
VCC (5V) 5V
DATA A0

Code

// © 2025, Cognifront. Member of The IoT Kits Family.

//Experiment 6: Data Logging Using Arduino and Excel (Serial Communication)

const int lm35_pin = A0;

void setup() {
  Serial.begin(9600);

  // PLX-DAQ required startup commands
  Serial.println("CLEARDATA");  
  Serial.println("LABEL,Date,Time,Temperature(C)");
}

void loop() {

  int temp_adc_val = analogRead(lm35_pin);
  float temp_val = temp_adc_val * 4.88;    // convert to mV
  temp_val = temp_val / 10.0;             // convert mV → °C

  // Send data to PLX-DAQ
  Serial.print("DATA,");
  Serial.print("DATE,");
  Serial.print("TIME,");
  Serial.println(temp_val);

  delay(2000);
}

Without PLX-DAQ(parallax)

Circuit Diagram

Circuit Diagram

Board Connections

Board Connections

Connections

SD Card Pin Connect To (UNO)
GND GND
VCC (5V) 5V
CS D10
MOSI D11
MISO D12
SCK D13

Code

// © 2025, Cognifront. Member of The IoT Kits Family.

//Experiment 6: Data Logging Using Arduino and Excel (Serial Communication)

// Include libraries to use SD card (uses SPI interface internally)
#include <SD.h>
#include <SPI.h>

// Define chip select pin for SD card module
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 10;

// Define analog pin for LM35 temperature sensor
const int lm35Pin = A0;

/*
   SD Card wiring reference for Arduino UNO:
   -----------------------------------------
   | SD Card Pin  | Connect To (UNO) |
   | ------------ | ---------------- |
   | GND          | GND              |
   | VCC (5V)     | 5V               |
   | CS           | D10              |
   | MOSI         | D11              |
   | MISO         | D12              |
   | SCK          | D13              |
*/

void setup() {
  Serial.begin(9600);  // Start serial communication for debugging

  // Initialize SD card module
  if (!SD.begin(chipSelect)) {        // Check if SD card is detected and can be initialized
    Serial.println("SD init failed!"); // If initialization fails, print error message
    while (1);                         // Stop program execution
  }
  Serial.println("SD init done.");     // Confirm SD initialization
}

void loop() {
  // Read LM35 sensor output (0–1023)
  int adcValue = analogRead(lm35Pin);
  
  // Convert ADC value to temperature in Celsius
  // LM35 gives 10 mV per °C → 5V/1024 = ~4.88 mV per ADC step
  // temperature (°C) = (ADC value * 5.0V * 100) / 1024
  float temperatureC = (adcValue * 5.0 * 100.0) / 1024.0;

  // Open (or create) "data.csv" file in write mode (append data)
  File dataFile = SD.open("data.csv", FILE_WRITE);
  
  if (dataFile) {
    // Write timestamp (in seconds since power-up)
    dataFile.print(millis() / 1000); 
    dataFile.print(",");             // Separate values with comma
    
    // Write temperature data
    dataFile.println(temperatureC);
    
    // Close file to save data properly
    dataFile.close();                

    Serial.println("Data saved.");    // Confirm data written to SD
  } else {
    Serial.println("Error opening file!"); // If file could not be opened
  }
  
  delay(1000); // Wait 1 second before next reading
}

Observation

  • The Arduino successfully reads temperature data from the LM35 sensor.
  • Data is stored in a CSV file on the SD card at one-second intervals.
  • Using PLX-DAQ or Python, data can be visualized in real time in Excel.

Conclusion

This experiment demonstrates how to log real-time sensor data from Arduino to a computer using serial communication. Storing data in CSV format enables easy analysis and plotting in Excel or any other data-processing tool.

Real Life Example

Condition Monitoring in Machines and Data Logging: Sensors collect data such as vibration, temperature, or pressure from mechanical systems, which is logged and analyzed in Excel for predictive maintenance and fault diagnosis. Also this data can be fed for trainng a machine learning model.