Make LED light up from serial monitor

I want to controll red diode with a comand, blue diode with a comandand same with green. 3 different if statements. I want it as basic as possible so I can understand the code

const int RED = 9;
const int GREEN = 8;
const int BLUE = 7;

void setup() 
{
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
}
void loop()
{
  
 digitalWrite(RED, HIGH);
 digitalWrite(GREEN, HIGH);
 digitalWrite(BLUE, HIGH);
}

image

Hello babynisse

It seems to be a school assigment, isn´t it?

Show your recent attemps to see how we can help.

my attempt is in my post. I don't understand how to do it. do you have some examples?

If you open the IDE, and click on "files" you'll see a drop-down with "examples".
Enjoy!

I can´t see any attempt to use the if() instrucution.

Do you have to use this instruction?
Switch()/case would be more suitable.

yes its a switch case task. we didnt get any lecture for it.

the preferred method in this forum is:

put it some own effort (googling finding an example) and then ask a specific question about a specific line of code

Make LED light up from serial monitor

Arduino switch case example code

Add the following codes at the appropriate place of your sketch of post #1 to establish that Red LED turns ON when you send R from the InputBox of SM.

  byte n = Serial.available();
  if (n != 0)
  {
    char y = Serial.read();
    if (y == 'R')
    {
      digitalWrite(RED, HIGH);
    }
  }

I'm interested in the exercise-text you received. Would you mind posting the text of the exercise you got from your teacher? I want to make a suggestion from there. (after reading the exercise-text)

best regards Stefan

its in norwegian so it may not help?

i cant type in serial monitor now? You know why that is

You upload sketch in UNO; open SM; bring cursor in the InputBox of SM; now enter/type R and then click on the Send Button. The RED LED should turn ON.

I simply will use google translate
Jeg bruker bare google translate

it dosent work

google is always worth a five minute search.
I got a

full hit

= a democode that does almost exactly what you would like to have
image

Post the latest sketch into which you have included the codes of post #8 and have uploaded.

const int RED = 9;
const int GREEN = 8;
const int BLUE = 7;

void setup() 
{
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
}
void loop()
{
  byte n = Serial.available();
  if (n != 0)
  {
    char y = Serial.read();
    if (y == 'R')
    {
      digitalWrite(RED, HIGH);
    }
  }
 digitalWrite(GREEN, HIGH);
 digitalWrite(BLUE, HIGH);
}

and your question is?

see post on top

Is the sketch of post #17 working? If not, what is the problem? Do you have an Arduino UNO?