How can I log the data of sensor connected to Arduino to a text file on my PC ?

Good morning,

I am connecting an LDR (light dependent resistor) to a digital pin on Arduino (digital pin 8 ). I am receiving digital values from this sensor (1 for sensing light, and 0 for darkness). I am trying to log this data of the LDR sensor to a text file on my computer (Microsoft vista). I can view the values using the serial monitor in the Arduino IDE, but I want to log it to a text file also. I tried to use processing language and IDE to read data from the serial port and write it to a text file and I downloaded the processing IDE and got some code but all I got was an empty text file in the same directory.

Please tell me how can I log this sensor's data to a text file on my PC. My Arduino is connected to port "COM4".

This is my Arduino code:

note: in this code I used an LED and pin 13 to just give me a visual output. When it is light, the LED shines, when it is dark, the LED is off.

// Digital Output pin
const int led = 13;

// Digital Input pin
const int D8 = 8;

int lightSensor = 0;

void setup()


pinMode(led, OUTPUT);

void loop()
lightSensor = digitalRead(D8);
if (lightSensor == HIGH)
digitalWrite(led, HIGH);
digitalWrite(led, LOW);



This is the processing code I found, but it only gives me an empty 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 );

Please help me, I really tried but it is not happening ! Thank you.

GoBetwino can do it for you:

or create your own serial program using c# / / c++ / pyhton /
python is free, for the others there exist express editions who are also free
python with the right library added to it, is most likely the essayist program to use since its a much higher language.
on modern PC the slowness of higher programs isnt a big problem.

Serial.list() returns a list of COM port names that the Arduino might be connected to. You can print this list:


Doing so will allow you to confirm that your Arduino is connected to the 1st port n the list.

If it isn’t, the Process sketch won’t work. Let’s make sure that that assumption is correct first,

Here's a pretty good option. Serial Data Logger. Advanced Serial Data Logger software - serial and RS232 port data collection and acquisition software .There's a demo period, which may be enough time to do what you want to do.

I would recommend to output some special character after your value. For example, CR or LF. In this case the program on the PC side will know how to extract data from a common data flow.

or you may use my program for free
as a bonus it also does speak :)) (voice tested under win 7, i asume works also on xp but not sure)

its not completely foolproof written, and asumes a directory c:\temp ,… you can change it but be sure the folder does exist, or programs stops.
it also asumes you use serial.printline

SimpleSerial.exe (12.5 KB)

I wrote a small program so you can used it. FOR XP ONLY
Small note:pay attention when you choose the programm speed, if your arduino runs at 100ms a loop choose for the program just the half -->50ms

when you choose the “overwrite option” take “true”

at least the file appears after you close the program.

here is the program

here is the code that you can modify

have fun if you have questions , just let me know

For only $29, you might check out the below for data logging.

GoBetwino can do it for you:

From what you’ve said so far, this does everything you need and seems like the most obvious solution.