Serial Read Issue

Hi, every one
I want my arduino received two different commands via serial monitor,
for ex.
a=serial.read();
b=serial.read();
but a Not equal to b;

how to do that .
thanks :slight_smile:

but a Not equal to b;

how to do that .

Send two different "commands".

I meant when I type 3 in serial monitor and press enter button,
a=3 and b=3 that what happened with me, I need the Arduino distinguished between them.
the problem is that, I need two inputs the longitude and latitude , when program started it ask the user to enter the value of latitude and then the value of the longitude but I cant find the way to do it.
thanks :slight_smile:

EngFarouk:
I meant when I type 3 in serial monitor and press enter button,
a=3 and b=3 that what happened with me, I need the Arduino distinguished between them.
the problem is that, I need two inputs the longitude and latitude , when program started it ask the user to enter the value of latitude and then the value of the longitude but I cant find the way to do it.
thanks :slight_smile:

Perhaps serial is not the best aproach. The arduino should be requesting the data on a master/slave basis.
If this is not possible, you would need to send some data ID along with the data. For example 0xFA = 3, 0xFB = 3. Then you can load each value into an array and work with it independently. No more confusions.

I meant when I type 3 in serial monitor and press enter button,
a=3 and b=3 that what happened with me,

We can't see all of your code, so at best we'd be guessing as to what the problem is.

I need two inputs the longitude and latitude

One digit each?

Longitude and latitude are not commands.

when program started it ask the user to enter the value of latitude and then the value of the longitude but I cant find the way to do it.

You've obviously tried something. I'd guess, if I were willing to play that game, that you think the Arduino waits for a response. It does not. I'd further guess that you think you can read longitude using one Serial.read() call. You can't.

You need to post all of the code you have now, after reading Read this before posting a programming question ... - Programming Questions - Arduino Forum (which you should have already read).

EngFarouk:
I meant when I type 3 in serial monitor and press enter button,
a=3 and b=3 that what happened with me, I need the Arduino distinguished between them.
the problem is that, I need two inputs the longitude and latitude , when program started it ask the user to enter the value of latitude and then the value of the longitude but I cant find the way to do it.
thanks :slight_smile:

not knowing what you are doing with the values...

you could try this to enter two values via serial monitor...

long latitude, longitude;
float result;
boolean printed;
int state;

void setup()  
{
  Serial.begin(9600);
}
void loop()  
{
  if (state == 0)
  {
    if (!printed) Serial.println(F("Enter the Latitude"));
    printed = true;
    if (Serial.available())
    {
      latitude = Serial.parseInt();
      Serial.print(F("Latitude = "));
      Serial.println(latitude);
      printed = false;
      state = 1;
    }
  }
  else if (state == 1)
  {
    if (!printed) Serial.println(F("Enter the Longitude"));
    printed = true;
    if (Serial.available())
    {
      longitude = Serial.parseInt();
      Serial.print(F("Longitude = "));
      Serial.print(longitude);
      printed = false;
      state = 2;
    }
  }
  else if (state == 2)
  {
    // do your thing wiht your latitude and longitude
  }
}

look at parseFloat to do it with floating point numbers

Thank you very much my friends ,your tips were very helpful. :slight_smile: :slight_smile: