Go Down

Topic: php arduino please help (Read 4533 times) previous topic - next topic


i may sound a little dumb but please answer ...

1. I learnt about php serial and found that it could be used to communicate with arduino via serial port but i can't seem to figure out whether it is rs232 or usb port ... (please clarify )

2. i downloaded these  two php files from phpserial class website

php_serial.class.php and example.php

my question is are they standalone like just modifying example.php with the function we would need it to perform would allow communication to arduino?  

please reply..



a little info i downloaded the above two files ( prev post ) from here..

please help guys


I learnt about php serial and found that it could be used to communicate with arduino via serial port but i can't seem to figure out whether it is rs232 or usb port

The php serial class communicates with the serial port. Whether that serial port is a real RS232 serial port or a serial-to-USB conversion, only you can answer, as you are the one with the hardware.

my question is are they standalone

The example.php file uses stuff from the php_serial.class.php file.


thanks a lot for the reply i understood the example.php and php_serialclass.php from your explanation but one thing still is not clear...

let me put it this way to communicate with arduino using the serial class need i have to buy a rs232 converter to connect arduino to rs232 serial port in my computer or is the usb interface enough...

one more too
i found this link in google code where a guy has written code for read function in php serial class does this work?

the link is : http://code.google.com/p/php-serial/issues/detail?id=1#c0

thank you


How are you connecting your Arduino to the PC? Are you using a USB cable? If so, you can send serial data to the Arduino using the same cable (just like avrdude does).

does this work?

Ready? Set? Jump!

There's no better way to know than by trying.


thank you ! but i am collecting this information for my final year project so that i could go ahead and purchase stuff only after confirming that those works...

anyway  thank you..


PHP was originally developed on linux, and ported to windows. There are some features that work better on linux than on windows. Hardware access, like access to the serial port, is one of them.

You would be much better off, in my opinion, using a program language on the PC that works well with the operating system on the PC.

Now, I'm a big fan of PHP, and regularly use it. Just not for talking to my Arduino. For that, I use C#, because it is very simple to read from and write to the serial port, talk to databases, draw pretty pictures, etc. all in one language.

Don't let PHP's ability, or lack thereof, to communicate bi-directionally with the serial port, on your operating system, without any experience on your part, influence your project.


k, i understood one thing ... from your reply

my idea was to implement a rfid +arduino + webpage ( using php ) to implement a targeted advertisement....

but now i am clear that web page need not necessarily be written in php but i could use flash which which too could be interfaced with arduino easily... thank you

going with flash for website design...



going with flash for website design...

It's not gonna run on an iPad. :( LOL
This... is a hobby.


k i found one thing for sure php serial class is NOT BI DIRECTIONAL for windows............................ ( for until now atleast)

you can send data to arduino with EASE

but the reverse is not possible ( again until now)


Hi Cinnamon.
I had the same problem but after 4 days of trouble i find the solution.
i translate with my bad English.

I'll try the same php class but it's not useful form me and an allert tellt that is unbidirectional.
I find the solution for me.
I use webserver with php on win pc and i use Serproxy for connect with com port.
And i write a script that send signal to COM. This method it's bidirectional.
Here the method to put signals with fopen using fsockopen.
Before start php script you must start serproxy.

I use this serproxy for connect to my serial http://code.google.com/p/as3glue/ (this project is useful for connecting Flash)
This is the PHP code:

Code: [Select]


function invia_seriale($messaggio)&#123;
if (
$fp fsockopen ("localhost"5331$errno$errstr30);
 if (!
echo "$errstr ($errno)";
$string $messaggio;
fputs ($fp$string );
fclose ($fp);


//catch the variable by lik get example xxx.php?stato=value


//execute function
invia_seriale ($stato);


And this is arduino code:

Code: [Select]
int in = 0;
int ledPin = 13;
int st=LOW;
int sensorPin=A0;
int sensorValue=0;

void setup() {
Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps

void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue, DEC);
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
in = Serial.read();

// say what you got:
//      Serial.print("I received: ");
//      Serial.println(incomingByte, DEC);

For GUI i use this ajax script very beautiful.
http://papermashup.com/jquery-iphone-style-ajax-switch/ and change page on.html and off.html with myPhpToCom.php?stato="Value".

Now i'm searching method to read all string that Arduino put on serial because for example when i read analog in trigger 10K i read sometimes all value and sometimes value is truncate, i'm programming a function that take the serial value that pass on COM.

I think that use php to control Arduino can be intresting because u can use all web service and app that can be interfacing with php (Twitter, Google Calendar, reading and send email ecc..), and it can be possible use mysql db.

I hope thi is useful.
Good Work
8-) 8-) 8-)

Go Up