php with arduino

hello, im new with arduino and im trying to cotrole a arduino with php - i whon turn on/off pin 2, from serial monitor all work but from php not . can some one help with php?

sory about bad eng…

<?php if (!$_GET['caracter']) { $val = 50; } else { $val = $_GET['caracter']; } $fp = fopen ("COM6", "w"); if (!$fp) { echo "Port not opened."; } else { $string = chr($val); echo "caracter: ".$string; fputs ($fp, $string); fclose ($fp); } ?>



arduino code :

int mainigais;
int pin2 = 2;
int pin7 = 7;

void setup()
pinMode(pin2, OUTPUT);
pinMode(pin7, OUTPUT);

void loop() {
if (Serial.available() > 0)
mainigais =;

if (mainigais == ‘1’)
Serial.print("pin2 on , mainigais : ");
digitalWrite(pin2, HIGH);
else if (mainigais == ‘2’)
Serial.print("Manigais : ");
digitalWrite(pin2, LOW);
if (mainigais == ‘3’)
Serial.print("pin7 on , mainigais : ");
digitalWrite(pin7, HIGH);
digitalWrite(pin7, LOW);


What is the problem with the php script? Is the port opened? If so, it appears as though you are sending '1' and '2' with no delay.

In the future, use the # button above to post code. And, don't change the color. That green was very hard to read.

the port is opened , php send to arduino , but pin2 not work - from serial monitor it work when i send 1 or 2

In the php script, you should add some code to read what is written by the Arduino to the serial port, and show it in the browser.

Then, in the Arduino script, add some Serial.print statements to echo what was read from the serial port. If it isn't obvious what is wrong, post the output, and we'll offer more suggestions.

mybe yo can help with code add ?

when i write arduino code like this - if (mainigais != '1') i can turn pin 2 on from php but cant turn pin 2 off...

Well, that would imply that you are not sending the Arduino (just) a '1'.

that i know - but where is error in php ?I've tried many versions but nothing works ... :( what am I doing wrong?

how do I know which number Arduino get? What could look Arduino and the PHP code?