Qwery regarding serial.println

I am using a serial println loop inside if loop similar as:

if (x == 1){
serial.prinln(1)
}
else if (y==1){
serial.prinln(2)
}
....
But I am getting output only sending '2'. the loop never goes out of the else loop.
How to achieve this so that bit '1' also sent through serial?

@debasishnath Installation and Troubleshooting is for Problems with the Arduino IDE itself NOT your project. It says so in the description of the section.

Therefore I have moved your post here. Please be more careful where you post in future.

You may want to read this before you proceed:-
how to get the best out of this forum

First, it is Serial.println, not Serial.prinln.

Second, show us the complete code.

Post ALL your code... bits of it don't help anyone trying to debug.

Use code tags (these things in the editor </>).

They are not loops. They do not loop. Loop means to repeat some code multiple times. The code in if and else only execute once, or don't execute.

The code will only print "1" if the variable x has the value 1. Perhaps that is not happening.

int threshold() {
  a = 0; b = 0; c = 0; d = 0;  p = 0; q = 0; r = 0; s = 0;
  initial_time = millis();
  while (millis() - initial_time < 3000)
  {
    digitalWrite(12, HIGH);                                                                 // in 3 seconds
     
    EMGState5 = digitalRead(EMGPin5); EMGState6 = digitalRead(EMGPin6); EMGState7 = digitalRead(EMGPin7); EMGState8 = digitalRead(EMGPin8);
     
    if (EMGState5 == HIGH && EMGState6 == HIGH && EMGState5 == HIGH && EMGState8 == HIGH) {
    
      d = 1; digitalWrite(5, HIGH);  
      
      Serial.println(4);//delay(5);  
      if (count4_prt <  prt) {
    
      }
      
    }
    else if (EMGState6 == HIGH && EMGState5 == LOW && EMGState8 == HIGH && EMGState7 == HIGH) {
    
      c = 1; digitalWrite(6, HIGH);    
     
      if (count3_prt < prt) {
      
        Serial.println(3);//delay(5);
      }
     
    }
    else if (EMGState7 == HIGH && EMGState6 == LOW && EMGState5 == LOW && EMGState8 == HIGH) {
  
       b = 1; digitalWrite(7, HIGH);
    
      if (count2_prt < prt) {
        Serial.println(2);//delay(5);
   
        
      }
     
    }
    else if (EMGState8 == HIGH && EMGState7 == LOW && EMGState6 == LOW && EMGState5 == LOW) {
     
      a = 1; digitalWrite(8, HIGH);
      

      if (count1_prt < prt) {
 
        Serial.println(1);//delay(5);
      }
    
    }
  }                                                   // in 3 seconds
  digitalWrite(12, LOW);
  return a;
  return b;
  return c;
  return d;
}

Please check the complete code.
The code only sends '1'. through serial.

Where? That is NOT the complete code (e.g. loop and setup missing, variables missing).

Hmm, after the first return, the function ends. So you will have to make up your mind which variable needs to be returned.

Are you having difficulty understanding the word all.

It means all the code you are using. The code in its entirety. Every single line of code that you have in your program that you uploaded to your Arduino.

Please post all your code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.