To read text file from PC using Arduino UNO

const int buttonPin = 2;
int buttonState = 0;
int counter=0;
int subtext [11];

void readData(String myFileName);

void setup() {
// initialize the LED pin as an output:
//pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH)

if((counter < subtext)){

else {


void readData(String myFileName){
FILE *file;
file = fopen(const myFileName, “r”);
BufferedReader br=null;

br=new BufferedReader(new FileReader(file));
String text=null;

/* keep reading each line until you get to the end of the file /
Spilt each line up into bits and pieces using a comma as a separator */
subtext = splitTokens(text,",");
}catch(FileNotFoundException e){
}catch(IOException e){
try {
if (br != null){
} catch (IOException e) {

We’re getting error in the highlighted line. Please suggest a solution.

Please post the full error message.

I would think that at the very least the fopen() function would work better if it was to be passed a filename but as the Arduino cannot open a file on the PC anyway you are barking up the wrong tree.

What you could do is to run a program on the PC to send the contents of the file to the Arduino over the serial link and read it on the Arduino.

We're getting error in the highlighted line. Please suggest a solution.

The Arduino can NOT read a file on your computer. The Arduino can listen to the serial port, where some application on the PC is reading the file and sending the data.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

This Python - Arduino demo may also be of interest. The Python code could be extended to open and read a file on the PC and send the contents to the Arduino.