Try to do password to the arduino

new to arduino. im trying to make the light turn on and of according to my orders, but after i put only one order it turn on but doesnt do anything afterwards. help?

Blink.ino (2.92 KB)

What do you think this will do?

       if (digitalWrite == LOW) {

But there are other problems with your code. I changed it a little to follow the execution of the if blocks:

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Serial.begin(115200);
  while (!Serial);
}

char inputSeveral[31];
byte maxChars = 12;
int count = 0;
// the loop function runs over and over again forever
void loop() {
  inputSeveral[0] = 0; // makes inputSeveral an empty string with just a terminator
  byte charCount = 0;  // the number of characters actually received - some may be lost
  byte ndx = 0;        // the index position for storing the character

  if (Serial.available() > 0) {

    while (Serial.available() > 0) { // keep going until buffer is empty
      if (ndx > maxChars - 1) { // -1 because arrays count from 0
        ndx = maxChars;     // if there are too many chars the extra ones are
      }                     //   dumped into the last array element which will
      //   be overwritten by the string terminator
      inputSeveral[ndx] = Serial.read();
      ndx ++;
      charCount ++;
      delay(250);
    }

    if (ndx > maxChars) {  // to make sure the terminator is not written beyond the array
      ndx = maxChars;
    }
    inputSeveral[ndx] = 0;
    Serial.println(inputSeveral);


    String msg = "";
    int num = 0;
    int num2 = 0;
    int eror = 0;

    if (strcmp(inputSeveral, "ON"))
    {
      Serial.println("received ON");
      if (digitalWrite == HIGH) {
        count = 0;
        digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
        Serial.println("LOW");
        delay(1000);
      }
      digitalWrite(LED_BUILTIN, HIGH);
    }
    else if (strcmp(inputSeveral, "OFF"))
    {
      Serial.println("received ON");
      if (digitalWrite == LOW) {
        count = 0;
        digitalWrite(LED_BUILTIN, HIGH);    // turn the LED off by making the voltage LOW
        Serial.println("HIGH");
        delay(1000);
      }
      digitalWrite(LED_BUILTIN, LOW);
      num2 = 0;
    }
    else
    {
      Serial.println("NOTHING"); 
      count = count + 1;
      eror = 0;
      if (count == 5) {
        if (digitalWrite == LOW) {
          for (int i = 0; i < 10; i++) {
            digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
            delay(1000);                       // wait for a second
            digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
            delay(1000);
          }
          if (digitalWrite == HIGH) {
            for (int i = 0; i < 10; i++) {
              digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level)
              delay(1000);                       // wait for a second
              digitalWrite(LED_BUILTIN, HIGH);
              // turn the LED off by making the voltage LOW
              delay(1000);
            }
          }
          digitalWrite(LED_BUILTIN, LOW);
        }
      }
    }
  }
}


// this reads all the characters in the input buffer
// if there are too many for the inputSeveral array the extra chars will be lost

// add a zero terminator to mark the end of the string

Here is what I get on the monitor:

10:34:27.442 → ON
10:34:27.442 →
10:34:27.475 → received ON
10:34:32.795 → OFF
10:34:32.795 →
10:34:32.795 → received ON
10:34:43.529 → OFF
10:34:43.529 →
10:34:43.529 → received ON

When I input OFF, it still goes through the ON case:

    if (strcmp(inputSeveral, "ON"))

I changed the ifs like this :

    if (strcmp(inputSeveral, "ON")==0)
...
    else if (strcmp(inputSeveral, "OFF")==0)

and got this:

10:37:11.601 → ON
10:37:11.601 →
10:37:11.601 → NOTHING
10:37:15.930 → OFF
10:37:15.930 →
10:37:15.930 → NOTHING

Then, changing in the serial monitor the end lines to nothing (no CR, LF) makes it work correctly:

10:37:26.000 → ON
10:37:26.000 → received ON
10:38:55.657 → OFF
10:38:55.657 → received ON