problem with code

i have PHP code

<?php if(isset($_GET['action'])){ require("php_serial.class.php"); $serial=new phpSerial(); $serial->deviceSet("COM1"); $serial->confBaudRate(9600); $serial->deviceOpen(); if($_GET['action']=='1') { $serial->sendMessage("0\r"); print($_GET['action']); } else if ($_GET['action']=='0') { $serial->sendMessage("1\r"); print($_GET['action']); } $serial->deviceClose(); } header("Location: index.html"); // Return to frontend (index.html) ?>

and have arduino code

int ledpin=13;
int incomingbyte;
void setup(){
void loop(){
if(Serial.available()) {;
Serial.write( incomingbyte );
else if(incomingbyte==‘1’) {



When i click on, the light turns off, but when i click off it doesnt turn off. What could be the problem

What’s the point of reporting your own post to the moderators?

Please use code tags.

What kind of data are you actually receiving?

I suspect the problem is that you are not allowing time for the Arduino to reset after your PHP code opens the serial port. Also, your code closes the serial port. It should leave the serial port open until you are completely finished communicating with the Arduino.

The Python code (and the Arduino code) in this demo illustrates one way to do this. It should be easy to transfer the concepts to PHP.