Serial PHP communication locks up everything...

Hi guy's. I started to mess with the perfect pixel example and use PHP to communicate with my arduino. It seems that once all the code is properly setup and I trigger the communication, it loads endlessly and locks up the arduino software/serial monitor. any ideas? attached is my code...


    $serial = new phpSerial(); 

    //Set the serial port parameters. The documentation says 9600 8-N-1, so 
    $serial->confBaudRate(9600); //Baud rate: 9600 

    //Now we "open" the serial port so we can write to it 
    //Issue the appropriate command according to the Arduino source code 0=Green On, 1=Green Off, 2=Red On, 3=Red Off.

    if ($_GET['action'] == "redon") { 
        //to turn the RED LED ON, we issue the command  
    //We're done, so close the serial port again 

Arduino Code

int incomingByte;      // a variable to read incoming serial data into
void setup() {

  Serial.begin(9600); // initialize serial communication
  pinMode(19, OUTPUT);  // initialize the red LED pin as an output
void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    incomingByte =; // read the oldest byte in the serial buffer
    if (incomingByte == '2') {
      digitalWrite(19, HIGH); // turn the LED on (HIGH is the voltage level)
      digitalWrite(19, LOW); // turn the LED on (HIGH is the voltage level)


Why are you sending '\r' when you code doesn't look for it?

Keep in mind that each time you open the serial port,the Arduino resets. You might want to add a 2 second delay in your PHP code to make sure the Arduino is ready to receive the character.