How to play iTunes with Arduino & photoresistor


I am trying to create a project that will take the value of the photoresistor and use that value to command iTunes to play or pause, depending on the light level read by the photoresistor. I tried using Apple Script Proxy from TinkerIt!, but there was a delay between the Arduino’s serial communication and the Apple Script Proxy app. I can’t seem to figure out why it takes so long for the Script Proxy to read the print out from the Arduino. The serial monitor from the Arduino program displays the information immediately, so I don’t know what the problem is. If there is a better way to do this (possibly through the Processing 2 program?), please let me know. Thank you.

//Code to read voltage from photoresistor, and use that data to play or pause iTunes using serial port.

void setup(){
pinMode(13,OUTPUT); //Built in LED on pin 13 lights up whenever photoresistors voltage is high.

void loop()
int lightlevel=analogRead(0); //reads the light level from the photoresistor and assigns it to the variable called lightlevel
delay(500); //wait one second.
if (analogRead(0)>lightlevel+70) //if the light level is greater then photoresitors’s voltage, it plays music.
digitalWrite(13,HIGH); //turn LED on
Serial.print(“B”);//send signal to Apple Sctipt Proxy program through serial port, which interprets “B” as an applescript command.
if (analogRead(0)<lightlevel-30) //if the light level is less then photoresitors voltatage, it pauses the music.
digitalWrite(13,HIGH); //turn LED on
Serial.print(“A”);//send signal to Apple Sctipt Proxy program through serial port, which interprets “A” as an applescript command.

digitalWrite(13,LOW); //turns LED off.


Then it sounds like an issue with the Apple Script Proxy tool - you'd probably get a better response if you talked to them; your code is dead simple and straight off a tutorial, so it should work. It's possible that this delay is considered acceptable by most users of that tool, and they haven't bothered doing anything about it.

One thing that comes to mind... does doing println() instead of print() work? This is grasping at straws, but maybe it wants a newline to tell it you're done sending your command, and otherwise it waits a few seconds to be sure? This is a straight up guess, but it's trivial to test, so I figured I'd mention it.

It also looks like there are a couple different versions of the TinkerIt apple script proxy tool on various sites. Are you using the right/latest one?

Thank you DrAzzy,

It probably is a problem with Apple Script Proxy, but I guess what I'm hopping to discover is, is there a reason that the communication between the two over serial port is delayed? Is it just because the programs work that way, or is there sum variable that I'm overlooking?

I always worry when the comments in a program are wrong. You might have missed this but delay 500 delays for half a second not one second.

However if it works on a serial monitor it is not the arduino side that is the problem. What is wrong with the built in Apple script anyway?