Giving commands

Hello!

I have written this code that I attached and everything works fine, but in order to do my project I need to be able to give commands to my Arduino.

For example, when I send a command through the serial monitor:

“S” the arduino starts executing my written code, but when I send the command “C” it stops executing the code.
I’ve tried different methods, but nothing works.
Can anyone please help me on this??
The closest that I got (if(Serial.available() > 0) was when pressing any button gave me only one reading, but I need different buttons to do different things.

First_test_27.02.ino (1.55 KB)

what you should be looking at is a shield called 1Sheeld if you google that you will find info on what you can use it requires a board that mounts on an Arduino Uno board allowing it to be many shields that can be controlled via smart phones

veisp:
Hello!

I have written this code that I attached and everything works fine, but in order to do my project I need to be able to give commands to my Arduino.

For example, when I send a command through the serial monitor:

"S" the arduino starts executing my written code, but when I send the command "C" it stops executing the code.
I've tried different methods, but nothing works.
Can anyone please help me on this??
The closest that I got (if(Serial.available() > 0) was when pressing any button gave me only one reading, but I need different buttons to do different things.

It's actually pretty simple,
you just need to to make the condition that checks if there's anything available from the computer and then read the character.
the code should look like this:

void setup() {
  // put your setup code here, to run once:

}

void loop() {

  if(Serial.available() > 0){   // checks if the computer/board is transmitting data
    char charecter = Serial.read();   // gets the charecter from the computer/board
    if(charecter == 'S'){
      Execute();
    }
    else if(charecter == 'C'){
      Stop();
    }
  }

}

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Hello!

After i wrote my code with your suggested if and else if,
When I write for example "S" it runs the code only one time, but I need the code to run all the time, while i haven't written anything else. Is it possible?

veisp:
When I write for example "S" it runs the code only one time, but I need the code to run all the time, while i haven't written anything else. Is it possible?

Of course.

But if you want help you need to post your program so we can see exactly what you have done.

...R

You have to create a finite state machine, where you switch between states using your Serial inputs.