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 IDE 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

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 –

  1. Download CoolTerm data logger software from this link (File size: 20MB).
  2. After downloading, unzip the file and copy the folder inside the zip file on your PC.
  3. Open the folder and right click on CoolTerm.exe icon and create desktop shortcut on your PC.
image 8 Vidyasagar Academy
  1. Now connect your Arduino board through data cable to your PC and upload the code in Arduino UNO or Arduino nano.
  2. Do not open Serial Monitor or Serial Plotter. Just note down the COM port to which your Arduino is connected to. In my case, it is connected to COM3 port.
  3. Now open CoolTerm application.
  4. Click on “Options” menu and then click on “Port”. This field should show you the COM port number to which your Arduino is connected to. Then click OK. Here I am using the Baudrate as 9600.
image 9 Vidyasagar Academy
  1. Click on “Connections” in menu, go to “Capture to Text/Binary File” and click on “Start”, as shown below.
image 10 Vidyasagar Academy
  1. Now a new window will open where you have write the name of the file.
  2. Finally click on “Connect” button of CoolTerm application to start recording the data entries in the text file, as shown below.
image 11 Vidyasagar Academy
  1. Once you have sufficient data entries, click on “Connections”, go to “Capture to Text/Binary File” and click on “Stop”.
  2. Then click on “Disconnect” button.
  3. This will complete data logging process.

Import TXT file in Excel

  1. You must have the txt file, generated by CoolTerm either on desktop or in a folder.
image 12 Vidyasagar Academy
  1. Now open Microsoft Excel and click “Open” in its menu. Then click on “All files” in bottom right corner as shown below and select “Text Files (*.prn, *.txt, *.csv)”.
image 13 Vidyasagar Academy
  1. Now it will show you your text file generated by CoolTerm. Select the file and click “Open”.
  2. This will open text import wizard.
  3. Select “Delimited” button and then click “Next”.
  4. Now as shown below, deselect “Tab” option and select “Comma” option, then click “Next”.
image 14 Vidyasagar Academy
  1. Finally click “Finish” and now your TXT file will be converted into two columns in Microsoft Excel table, as shown below.
image 15 Vidyasagar Academy

How to create graph of the data entries?

  1. Since your data entries are imported into MS Excel in two columns, you can now create graph of the entries.
  2. Insert one row above the data entries and give headings to the two columns as Temperature and Humidity, as shown below.
  3. For that click on “Insert” menu and then select “Line” graph option.
image 16 Vidyasagar Academy
  1. Instantly the graph will be displayed as follows.
image 17 Vidyasagar Academy

Still More simple solution…

Just ignore all above methods and let us see the simplest possible method, as given below.

  1. Run the code of Temperature and Humidity sensor, given above.
  2. Then open the Serial Monitor in Arduino IDE.
  3. You will see the readings like this –

27, 22
27, 22
28, 20
27, 23
29, 20
30, 21
29, 20
28, 20
28, 21
29, 20
29, 20

  1. Now copy these readings from Serial Monitor and paste them in a filename.txt file.
  2. Then import this .txt file in MS Excel.
  3. Create a header row and give labels to the two quantities like Temperature & Humidity.
  4. The click on “Data” tab in MS Excel and import your .txt file with “Comma delimited” style, as shown below.
image 18 Vidyasagar Academy
  1. Then click on “Insert” tab in MS Excel and create graph.

That’s it…! You did it…!

Share on your network!
Prof. Dattaraj Vidyasagar
Prof. Dattaraj Vidyasagar

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x