Can Arduino write to a text file?

Is there an easy way to save variables to a text file? I am hoping to write sensor data to a text file that will eventually be used in a web app.



There is no file system available to the (native) Arduino environment, so in a nutshell the answer is "no". If you need permanent data storage, you will have to use the on-board EEPROM (512 bytes) or add one of the many external storage options (see Alternatively, concoct a system to transmit data to a PC with a file system (


Do you want the file to be on the computer or on the arduino ? If it's on the computer, you could use any programming language that can write files (processing, C++, java, python, ....) to establish a serial connection with the arduino, read the values from serial and write it to the text file. If you want the file to be on the arduino (GPS datalogging, for exemple), you might consider writing to an SDcard. Not sure if you can output a .txt file directly readable by your computer, though.

Thank you both. I am planning on saving the information in a text file on my Mac. I'll look into using Processing to pull the data from the Arduino. Any pointers or suggestions would be greatly appreciated. If my Arduino code has a snip that looks like:

char message[6] = "hello";

will I be able to have Processing access that using something like:


and see it output "hello"?

Thanks again.

You would need Processing (or whatever language you choose) to establish a serial connection to Arduino.

Then either send a message to Arduino to command it to send back the required data, or you could have Arduino just send data when apropriate and in the Processing app. continously check the serial port for incoming data.

Check the Processing forum there's probably tons of info on doing what you need.

I don't know Macs well, but would be VERY surprised if they don't have some Hyperterminal-like program (HLP).

That could be "fired up", connected to the Arduino (and the Arduino connected to the Mac) and then the HLP would put up on the Mac screen the stuff coming from the Arduino. From time to time, the human could save what had been sent to the Mac since the last save.

Of course, this entails a human being at the keyboard, but if that's not impossible, it saves you a bunch of issues.

Some Mac person: Please jump in with the name of the Mac equivalent of Hyperterminal?

=== Another issue: There are various ways to connect two computers. If you can endure a "crude" solution, you will have less hassle. By crude, I'm meaning a non-handshaked solution in which the Arduino "talks" without taking any notice of whether anyone is listening.

tkbyrd asked for a Mac equivalent to HyperTerminal. That would be Terminal (found in /Applications/Utilities/).

Now to jcole:

You will, of course, need to tell the Arduino to print something to serial. There's a lot out there on doing that.


If what you want to do is simply write serial data from the Arduino to a text file you can do this very simply by entering the following command in a Terminal window: cat /dev/cu.usbserial-(there is a string here that will vary from device to device) > /path/to/filename.txt

This command will run until you tell it to stop, so watch out, your log file will get big quick.

Google arduino-serial.c for some great blog posts.

Be sure to read the comments.

It looks like i've the same problem, but still can't find simple solution.

I need to use some data from arduino in VB - should i write it on Eprom, than load it (how in VB) ?, or should i send it on PC some other way (f.e with processing) ?

What do You suggest ? (I'm quite newbie with arduino, so excuse me :))

thanks in advice for your help.

On the receiver (PC) side, in VB, you can use a class that deals with the serial port. An instance of that class will wait for data on the specified serial port, then read it in. On the sender (arduino) side, your sketch will send out data on the serial port, using Serial.print.

No need for eprom, processing etc.

This is the case when you want to write your own, specific, code. Otherwise, if you just want to get/read/record the data coming from arduino on your PC, there are many solutions: GoBetwino, Processing, Arduino IDE, VB scripts etc.

cat /dev/cu.usbserial-(there is a string here that will vary from device to device) > /path/to/filename.txt

I'm trying to save the data from a serial port on my mac to a text file and this command doesn't work and worse seems to leave the serial port in an odd state which requires a restart.

i have no problem using screen to view the incoming data so i know its there but i'm at a loss as to why i can't find a good command to save it to a text file.


@mattkime - I know this is from over a year ago but here is the syntax:

DesktopG4:~ Intenzity$ cat /dev/cu.usbserial-A800etC0 9600 >> MyTextLog.txt

You might be missing the port speed of 9600 (match whatever the port speed is you have set in the sketch of course).

To see the exact name of your ports type: ls /dev/

Then copy/paste if you want to in order to get the exact name right.

I get a nice text file in my home directory with the output from the serial monitor with the above command.

Yes: With a microSD sheild from spark fun!

I am saving an XML file for a project using...

I chose an XML file, because it is really easy for a .NET program to read. However, it is possible to write any type of program you like! (*.txt, *.xml, *.c, *.cpp, ...)

The way you create a file is -> open "file.txt" (or whatever you like) -> write ....

... and it copies what you have in an array to a file.

You can then open the file on the card and read it back!

And at any time, you can take the microSD card out and put it into your computer (which is what I'm doing) for easy data transfer.