Help with reading keywords from a .txt file to send to Arduino to turn into a tone


I’m trying to use Processing to read a .txt file from my computer, search for specific keywords from this file, and send information to Arduino via the serial port so that Arduino can turn the keyword into a specific tone output.

I have a bit of working code that I’m trying to adapt. I believe this is the relevant snippet from Processing:

      StringTokenizer st =
        new StringTokenizer(data, "\"<>,.()[] ");// break it down
      while (st.hasMoreTokens ()) {
        // each chunk of data is made 
        chunk = st.nextToken().toLowerCase() ;

        if (chunk.indexOf("keyword1") >= 0 ) // found "love"?
          love++;    // increment love by 1
        if (chunk.indexOf("keyword2") >= 0)   // found "peace"?
          peace++;   // increment peace by 1
        if (chunk.indexOf("keyword3") >= 0) // found "arduino"?
          arduino++; // increment arduino by 1

The code as it stands is finding these keywords and adding to a counter that Arduino is turning into different intensities of RGB light with LEDs. I would like Processing to search for the keywords in the .txt file, then communicate to Arduino that one (or two, or all) has been found. On the Arduino side, I’d like to turn that information into a tone. I think the code for that might look something like this:

if (keyword1 == true) {
tone(buzzer, 1000)

I guess my problem is, I don’t know how Processing and Arduino communicate. I would just like Processing to indicate to Arduino that a specific word (String?) was found in the file, and for Arduino to turn that information into something.

I greatly appreciate any suggestions and guidance on this.


You’ll have to use Serial in this case, so that the arduino can communicate with processing over a port.
Have a look at this page :
With this you can send and receive information from your arduino board and it is actually very straight forward and pretty easy to use.
Btw, you can also import an arduino library (it’s called i think) into processing to work with your arduino.