1

I have an annoying problem with my Arduino and PHP server. I want send a value using PHP to port COM with Windows using a simple serial communication.

  1. I tried everything , even deleting the fclose of the PHP code, or change the value send of '1' > "1" or 1. But the communication of the Arduino never activated

  2. I put another LED for trying "debug" and that LED works but other doesn't.

The PHP code.

<?php
$fot = fopen("com1", "r+");
sleep(3);
fwrite($fot, '1');
?>

The arduino code

int numero = -5;
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}

void loop() {
if(Serial.available() > 0){
numero = Serial.read();
digitalWrite(11, HIGH);  
}
if(numero == "1"){
digitalWrite(12, HIGH);
}
Serial.println(numero);
delay(1000);
}
  1. the led on pin 11 works. And the entire code work on the serial monitor but with data send from php only the led 11 works.
15
  • I don't know if Arduino is different, but in C if(numero == "1") will not work, since you cannot compare the content of a string directly. Try if(numero == '1'). Commented Jul 16, 2016 at 14:15
  • Yeah youre right , but i already try, '1', "1" and 1. And dont work too, the correct way is '1' but no efect :(. Thanks for the answer man :D Commented Jul 16, 2016 at 14:18
  • Where do you configure the com port being used by PHP? What value gets sent back by Serial.println(numero);? Commented Jul 16, 2016 at 14:31
  • In the console, the println on loop with normal execution return a lot of -5, the 2 leds works the console return the number of 1 after return a lot of "10 10 10 10 10 10 " Commented Jul 16, 2016 at 14:38
  • The console works everything fine the code. Strage is in php , the led 11 works but the comparation of the led 12 dont. I think was something like the type of number in php, but i try everything e do not work. Commented Jul 16, 2016 at 14:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.