user27437: My Arduino Uno will not work without the Serial Monitor opened. I have a PHP script to send data to the board. When I send the data, the TX and L LEDs light up, but the action is not executed. It is only executed when the Serial Monitor is opened. Can you please help me?
Code in Arduino:
int const RED = 2;

int status = 0, temp =0;

void setup() {
  pinMode(RED, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  if(Serial.available() > 0) {
    temp = Serial.read();
    if(temp != -1)
      status = temp - '0';

    Serial.print("status: ");
    Serial.println(status);

    if(status == 1)
      digitalWrite(RED, HIGH);
    else
      digitalWrite(RED, LOW);

    delay(1000);
  }

}

PHP script:
<!DOCTYPE html>
<html>
    <head>
        <title>Alarme</title>
    </head>
    <body>
        <form action="#" method="post">
            <input type="submit" name="alarme" value="ON">
        </form>

        <form action="#" method="post">
            <input type="submit" name="alarme" value="OFF">
        </form>
    </body>
</html>

<?php

$port = fopen("/dev/ttyUSB0", "w");
fwrite($port, ($_POST['alarme'] == 'ON') ? 1 : 0);
fclose($port);

My circuit is simple, it only consists of one LED and a 220 ohm resistor.

user27437: The problem was the auto-reset of the Arduino, I disabled it.
To disable, I connected a 10uf capacitor on the GND and RES. As in the image below:


27437: <p>My Arduino Uno will not work without the Serial Monitor opened. I have a PHP script to send data to the board. When I send the data, the <code>TX</code> and <code>L</code> LEDs light up, but the action is not executed. It is only executed when the Serial Monitor is opened. Can you please help me?</p>

<p>Code in Arduino:</p>

<pre><code>int const RED = 2;

int status = 0, temp =0;

void setup() {
  pinMode(RED, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  if(Serial.available() &gt; 0) {
    temp = Serial.read();
    if(temp != -1)
      status = temp - '0';

    Serial.print("status: ");
    Serial.println(status);

    if(status == 1)
      digitalWrite(RED, HIGH);
    else
      digitalWrite(RED, LOW);

    delay(1000);
  }

}
</code></pre>

<p>PHP script:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Alarme&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;form action="#" method="post"&gt;
            &lt;input type="submit" name="alarme" value="ON"&gt;
        &lt;/form&gt;

        &lt;form action="#" method="post"&gt;
            &lt;input type="submit" name="alarme" value="OFF"&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;

&lt;?php

$port = fopen("/dev/ttyUSB0", "w");
fwrite($port, ($_POST['alarme'] == 'ON') ? 1 : 0);
fclose($port);
</code></pre>

<p>My circuit is simple, it only consists of one LED and a 220 ohm resistor.</p>
 27437: <p>The problem was the auto-reset of the Arduino, I disabled it.</p>

<p>To disable, I connected a 10uf capacitor on the GND and RES. As in the image below:</p>

<p><a href="https://i.stack.imgur.com/DcO7E.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DcO7E.jpg" alt="enter image description here"></a></p>
