Go Down

Topic: Arduino Windows PHP (Read 2067 times) previous topic - next topic


Hello everybody,

I am trying to get an arduino uno to work with PHP through the serial port using the USB cable of Arduino.

I have used the codes that are available in internet that allow you to make this communication between PHP and Arduino without having to install any additional software, library or whatever.

I have programmed the website as follows:

1st file "Serial.php":

// declare port

 `mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;


2nd file "SerialTest.php":

 //open port com1

 $fp = fopen ("COM1:", "w+");

 if (!$fp) {

    echo "Error while opening COM1.";
} else {

    $data = escapeshellcmd($_REQUEST["data"]);
    fwrite ($fp, $data );

fclose ($fp);


 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Serial port connection</title>
 <form method="get" action="SerialTest.php">
   <br />
   <button type="submit" name="data" value="1">ONE</button>
   <br />
   <button type="submit" name="data" value="2">TWO</button>
   <br />

The first file seems to work although I am not 100% sure but the leds of the card blink.

the 2nd file gives this error

Warning: fopen(COM1:) [function.fopen]: failed to open stream: Permission denied in <filepath>\SerialTest.php on line 5

Might anyone help me with this issue?

Thank you very much in advance.


Well, I don't understand this witchery very well, but it looks like the matter is that the first file doesn't do it's job well.

To make it to work I had to start the port COM1 from the Arduino's IDE. And looks like not all ports work, I didn't try it but I found somewhere that just port COM1 to COM4 can be used.

So if you have to change the number of the port because you got something like port COM6 you may change it to COM1 or COM2, COM3, COM4 with the "device manager".

there has to be any other better way using just PHP and Windows for sure.

if you know it please let me know if you got the same problem I may try to help you as soon as I can.

Greetings everybody!


Well i think i've seen this done before by someone using IOT core arduino c++in visual studio IDE... this code was communicating to a IP based device... i'm not extreemly familiar w/ network IP hardware systems communicating to interfaces but i'm sure this was communicating directly to a dynamic remote server for two way communication which had the .exe... i think i have the link w/ the IOT core just keep in mind windows group policy local/remote or user hosts restricts this type of behavior... so this is strictly for appliances running on a server somewhere w/ full administrative access....


Go Up