Ican read keys but cant turn on Led light on ( cant send)

const int led1=5;
const int led2=6;
const int led3=7;
const int led4=8;
const int led5=9;
const int key1=A0;
const int key2=15;
const int key3=14;
const int key4=16;
const int key5=10;

String outputString = "";
String inputString = "";

void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(key1,INPUT_PULLUP);
  pinMode(key2,INPUT_PULLUP);
  pinMode(key3,INPUT_PULLUP);
  pinMode(key4,INPUT_PULLUP);
  pinMode(key5,INPUT_PULLUP); 
  
outputString.reserve(10);
inputString.reserve(40);
    Serial.begin(9600);

    while (!Serial) {
    ; 
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  outputString.concat(digitalRead(key1));
  outputString.concat(",");
  outputString.concat(digitalRead(key2));
  outputString.concat(",");
  outputString.concat(digitalRead(key3));
  outputString.concat(",");
  outputString.concat(digitalRead(key4));
  outputString.concat(",");
  outputString.concat(digitalRead(key5));
  outputString.concat(",");
  outputString.concat('*');  
  
  Serial.println(outputString);
  outputString="";
  delay(500);

}

char temp;
char inputString_index=0;
void serialEvent() {
  while (Serial.available()) {
        char inChar = (char)Serial.read();
        inputString += inChar;
        inputString_index++;
        if(inChar=='*'){
            
            temp=inputString[inputString_index-3];
            if(temp=='1')   digitalWrite(led5,HIGH);
            else digitalWrite(led5,LOW);

            
            temp=inputString[inputString_index-5];
            if(temp=='1')   digitalWrite(led4,HIGH);
            else digitalWrite(led4,LOW);
            temp=inputString[inputString_index-7];

            if(temp=='1')   digitalWrite(led3,HIGH);
            else digitalWrite(led3,LOW);
            temp=inputString[inputString_index-9];

            if(temp=='1')   digitalWrite(led2,HIGH);
            else digitalWrite(led2,LOW);
            temp=inputString[inputString_index-11];

            if(temp=='1')   digitalWrite(led1,HIGH);
            else digitalWrite(led1,LOW);
        
         inputString_index=0;
         inputString="";
        }  
    }

  }

arduino_serial.ino (2.3 KB)

I'm guessing your code doesn't compile.

hi every one
i use serial port and this program send data to pc with 0 and 1 (like this 1,1,0,1,1,) and the star is for seprating the commands, and will recieve same code
i can see recieve code in serial monitor but when i send the command for example like this (1,0,1,0,1,
) the LEDs wont light up and my pc hand for 10 second
why is this happening

i have 5 keys and 5 lights

what should i do
i try it with proteus software and it works but in arduino pro micro
only the keys worked

Post the code you claim runs.

const int led1=5;
const int led2=6;
const int led3=7;
const int led4=8;
const int led5=9;
const int key1=A0;
const int key2=15;
const int key3=14;
const int key4=16;
const int key5=10;

String outputString = "";
String inputString = "";

void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(key1,INPUT_PULLUP);
  pinMode(key2,INPUT_PULLUP);
  pinMode(key3,INPUT_PULLUP);
  pinMode(key4,INPUT_PULLUP);
  pinMode(key5,INPUT_PULLUP); 
  
outputString.reserve(10);
inputString.reserve(40);
    Serial.begin(9600);

    while (!Serial) {
    ; 
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  outputString.concat(digitalRead(key1));
  outputString.concat(",");
  outputString.concat(digitalRead(key2));
  outputString.concat(",");
  outputString.concat(digitalRead(key3));
  outputString.concat(",");
  outputString.concat(digitalRead(key4));
  outputString.concat(",");
  outputString.concat(digitalRead(key5));
  outputString.concat(",");
  outputString.concat('*');  
  
  Serial.println(outputString);
  outputString="";
  delay(500);

}

char temp;
char inputString_index=0;
void serialEvent() {
  while (Serial.available()) {
        char inChar = (char)Serial.read();
        inputString += inChar;
        inputString_index++;
        if(inChar=='*'){
            
            temp=inputString[inputString_index-3];
            if(temp=='1')   digitalWrite(led5,HIGH);
            else digitalWrite(led5,LOW);

            
            temp=inputString[inputString_index-5];
            if(temp=='1')   digitalWrite(led4,HIGH);
            else digitalWrite(led4,LOW);
            temp=inputString[inputString_index-7];

            if(temp=='1')   digitalWrite(led3,HIGH);
            else digitalWrite(led3,LOW);
            temp=inputString[inputString_index-9];

            if(temp=='1')   digitalWrite(led2,HIGH);
            else digitalWrite(led2,LOW);
            temp=inputString[inputString_index-11];

            if(temp=='1')   digitalWrite(led1,HIGH);
            else digitalWrite(led1,LOW);
        
         inputString_index=0;
         inputString="";
        }  
    }

  }

the keys works pefectly
but no lights

Ok, sorry, missed your serialEvent function.
You could maybe clean up the code using the IDE's auto format tool.

i am a complat idiot in electronic and programing
can u plz fix the codes

sorry i cant do shit
i am noob
can u plz change it and sent the entire code for me so i can upload it
plz

Please (note spelling) mind your language.

I'm out.

sry
forgive me
i didnt want to be rude

sry again

:pensive:
:pensive: :pensive: :pensive: :pensive:

What you can try for starters is make a simple "echo" application on your Arduino. That is, you send something and it is supposed to send back what you have sent.

Then what you can do is put a Serial.print(inputString), within the loop with the "*" processing that is supposed to process your inputs. Then you see if your logic arrives there or not.

And then narrow your search further down until you know where the problem is.

And whatever you do: try to be polite and mind your language because on this forum we only help those that try to do their best and use proper language.

ty for your reply
dear friend i have no knowlage about programing T this code has been writen bye someone els who is no in covid 19 qurantine and i cant rich him
could u plz done all this to the main code and sent it to me
i just can upload the code and nothing else

:sob: :sob: :sob: :sob:

See the code in loop that produces a debug output for the physical switches?
Try to see if you can do something similar for the serialEvent code

ty again and i will try this tommorow and i will tell u that it works or no
ty again
and i am not a bad and rude person
i have a vast taste of humor

i will do that for them too but i will do it tomorrow
ty for coming back