Go Down

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


Hello everybody,



I have programmed the website as follows:

1st file "Serial.php":

// declare port



2nd file "SerialTest.php":

 //open port com1


 if (!$fp) {

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

    fwrite ($fp, $data );

fclose ($fp);


 <title>Serial port connection</title>
   <br />
   <br />
   <br />


the 2nd file gives this error


Might anyone help me with this issue?

Thank you very much in advance.







Greetings everybody!













Hello, I have the same problem, I try send commands (Serial port) to arduino using PHP, but first I need open the SerialMonitor of IDE Arduino. what the solution for this?


I get this example https://condtec.com.br/arduino/arduino-e-php-conexao-via-html-controle-remoto-do-arduino-via-servidor-web/85, and modified the fopen for execute in Windows  - "$port = fopen("COM6", "w+");". But run just when I open the SerialMonitor (IDE Arduino) and close the program.

I think that has a service that need run for acept commands in the serial port.


If you using PHP, on a Windows platform.. you will only be able to WRITE to the serial port natively.
If you want to READ...  you will need to use another OS... or use some sort of man-in-the-middle PROXY


Yes, I do this using:

Code: [Select]
if ($_POST['estado']=="Amarelo")
echo "Ligou o Amarelo";
fwrite($port, "a");

this work in my windows, but just when open and close the SerialMonitor, I think when execute the serialmonitor, it's execute a process that permite the arduino receive commands in the serial port.


I'm still not following..

what is your Arduino code to take this incoming serial data and parse it for use?


I solved my problem, I needed execute this command in the prompt command: "mode COM6: baud=9600 parity=N data 8 dtr=on xon=off odsr=off octs=off rts=on idsr=off".

When I execute this, I can send commands via PHP.


Not sure whether this will work with website or not but you can surely control your Arduino using PHP.

Step 1: Install a -AMP Webserver
Step 2: (Debian Only) Add Permissions for Serial Port
Step 3: Get PhpSerial
Step 4: Finally! Write Your Arduino Code
#include "USBSerial_main.h"

int incomingByte = 0; int pin = 2;

void setup() {

Serial.begin(9600); //Starts the serial connection

pinMode(2, OUTPUT); //Sets pin 2 to be output


void loop() {

if(Serial.available() > 0){

Serial.read(); /Removes the message from the serial cache

digitalWrite(2, true); //Enables the led on pin 2

delay(100); //Waits 100 ms

digitalWrite(2, false); //Disables the led on pin 2


Step 5: Creating Your Webpage

$comPort = "/dev/ttyACM0"; //The com port address. This is a debian address

$msg = '';


$serial = new phpSerial;







sleep(2); //Unfortunately this is nessesary, arduino requires a 2 second delay in order to receive the message

$serial->sendMessage("Well hello!");


$msg = "You message has been sent! WOHOO!";





<title>Arduino control</title>



<form method="POST">

<input type="submit" value="Send" name="hi">





I hope this solves your problem!



its (was) about the permissions when using WINDOWS..   not a linux/unix based OS..

Go Up