The simplest method is to use the Serial library and output to that. You can then capture the output to a text file using a terminal program. Hyperterminal is available on Windows, Teraterm on Linux and Z Term on OS X.
There are several ways to save data from a sensor attached to an Arduino. If you’re connected to a personal computer, you can simply send the data from the Arduino to the personal computer serially, and save it to a file. If you’ve got an SD card attached to the microcontroller, you can save the data to the card. Or, if you have access to the internet and a device that can connect to a server, you can save the data to a server. In the tutorial below, you’ll read a DHT11 temperature and humidity sensor and log data in three ways:
Serial transmission to a personal computer, and serial capture to a file.
Saving data to an SD card mounted on the Arduino.
HTTP upload to pachube.com via an Ethernet shield or Ethernet Arduino.
you can write the sensor data to the serial port using serial-lib and write a small processing program that reads the data from the serial port and writes it to a file.
in the arduino code initalize the serial lib in the setup method
Serial.begin(9600);
and write your sensor values to the serial interface using
Serial.println(value);
in your loop method
on the processing side use a PrintWriter to write the data read from the serial port to a file
import processing.serial.*;
Serial mySerial;
PrintWriter output;
void setup() {
mySerial = new Serial( this, Serial.list()[0], 9600 );
output = createWriter( "data.txt" );
}
void draw() {
if (mySerial.available() > 0 ) {
String value = mySerial.readString();
if ( value != null ) {
output.println( value );
}
}
}
void keyPressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}
please refer to the attachments for further detail.
You just send the data over the serial port using the serial.print() command and using PLX-DAQ program which writes the serial data to excel. No need for SD card. This is very effective and won't cost your precious time.... If you need any assistance please feel free to ask. I will be happy to help you regarding this matter. I can show you the process of saving the data.
You can use PLX-Daq is the best software for this. You will be able to sync to Microsoft Excel. More information: https://www.researchgate.net/publication/316172050_LaBoot_Photovoltaic-powered_Laboratory_Robot_for_Multidisciplinary_Educational_Application?_iepl%5BviewId%5D=c8ce2gLeNRoG9eYJPmaiTIUL&_iepl%5BprofilePublicationItemVariant%5D=default&_iepl%5Bcontexts%5D%5B0%5D=prfpi&_iepl%5BinteractionType%5D=publicationTitle
and https://www.youtube.com/watch?v=xzC4SDd6sJ0 (Channel that I found on the internet, with information.
Conference Paper LaBoot: Photovoltaic-powered Laboratory Robot for Multidisci...
I've tried running the code you've suggested but cannot understand where the file is located in my desktop? The code does not give a name or anything. How do I choose the name of the file and location?
Avishek Das, that version of PLX_DAQ is not suitable for newer versions of Windows e.g. Windows 10. I wanted to know about a way to prepare txt file for the Serial outputs directly from Arduino code. fstream() is a way to do it in C++ but I could not manage to use this command in Arduino or esp32. fstream library did not work. What to do about this?
You can use Arduino serial monitor and copy the data to save in a text file. Besides, you can use a SD card module as a datalogger and save the data both in a. txt and excel file.
Also, you can use PLX-DAQ software to save the data in excel file.