How to save Arduino Serial data in TXT, CSV and Excel file without using data logger shield?

How to save Arduino Serial data in TXT, CSV and Excel file without using data logger shield?

This entry is part 2 of 4 in the series How & Why

The use of data logger shield in Arduino is rather critical and everyone may not have the data logger shield readily available to create the log of readings in Arduino.

So this article explains how to save Arduino Serial data in TXT, CSV and Excel file without using data logger shield?

Also refer our Arduino Tips & Tricks and Arduino Tested Projects. Download all Library Files and Fritzing Parts file for better study with Arduino.

Now suppose we have create log of real time temperature and humidity, using DHT11 sensor with Arduino. For that we will use a simple code, as follows.

Simple Arduino code

To understand the process of saving Arduino Serial data in txt, csv and Excel file, we will use a simple Arduino code which uses Serial.print() commands. Let us see the code first.

/*
 * Code for the article:
 * How to save Arduino Serial data 
 * in TXT, CSV and Excel file 
 * without using data logger shield?
 * Vidyasagar Academy, Akola
 * www.vsa.edu.in
 */

#include <dht.h> 

int output=7; // connect output pin of DHT11 to pin-7
int readdata; // DHT data to store
int Temperature; // variable to store temperature value
int Humidity; // variable to store humidity value

dht DHT; // creating DHT object

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

void loop() 
{
  readdata = DHT.read11(output);

  Temperature = DHT.temperature;  // reading temperature
  Humidity = DHT.humidity;   // reading humidity

  Serial.print(Temperature);
  Serial.print(",");
  Serial.println(Humidity);

  delay(1000); // create reading log at every second
}

Note: To run this code in Arduino IDEWhat is Arduino IDE? Arduino IDE stands for Integrated Development Environment. It is also called as Arduino software in general language or Arduino compiler. It is used to convert high level programming language like C/C++ program into machine code i.e. into low level language. you will need DHT library. You can download it from this link. To add the downloaded zipped file, open Arduino IDE and click on “Sketch” menu. Then go to “Include Library” and then click on “Add .Zip Library, as shown below.

image 7 Vidyasagar Academy Akola

It is important to note the following piece of code used to print the Serial data. This is because we have to import the Serial data with comma delimited values in Excel file.

  Serial.print(Temperature);
  Serial.print(",");
  Serial.println(Humidity);

The first line in above code prints the “Temperature” value and the second line puts a comma (,) after the Temperature value.

Then the third line prints “Humidity” value. Since we used Serial.println() in this third line, due to carriage return, the next two values will be printed in next line and so on…

Download Data logging software

Now that you are ready with the code, follow these steps for data logging –

Signup or Login to view remaining content. It's Free!
Share on your network!
Dattaraj Vidyasagar
Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 35+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 17 books on electronics, robotics, programming languages and web designing... ➤➤

Leave a Reply

Your email address will not be published. Required fields are marked *