'Command' was not declared in this scope

I am trying to make this fan controller thing, but it keeps saying that my character is not declared in this scope. Here is my code:

#define Standby 3
#define Ready 2
void setup() {
  int spedo1 = 75;
  int spedo2 = 150;
  int spedo3 = 215;
 char Command;
  pinMode(7, OUTPUT);
  pinMode(Standby, OUTPUT);
  pinMode(Ready, OUTPUT);
  Serial.println("Ardunio Guenio 1 Motor contoll startup...");
  digitalWrite(Standby, HIGH);
  digitalWrite(Ready, LOW);
  Serial.println("Type now");
  digitalWrite(Ready, HIGH);

// the loop function runs over and over again forever
void loop() {
      Command = Serial.read();
      Serial.println("10110101 10011001");
      if(Command = "Motor ON"){
        Serial.println("Turning motor on");
        analogWrite(7, spedo1);
        Serial.println("Set speed:");
          Commmand = Serial.read();
          if(Command = "LOW"){
            anlogWrite(7, spedo1);     
          Commmand = Serial.read();
          if(Command = "MID"){
            anlogWrite(7, spedo2);
          Commmand = Serial.read();
          if(Command = "HI"){
            anlogWrite(7, spedo3);  
if(Command = "Motor OFF"){
analogWrite(7, 0);


The Command defined in setup is not in scope in loop.


That's an assignment, but of a string to a what seems to be a single char


what do you mean?

Command is declared in setup() which means that it can only be used inside that function but you are trying to use it in loop()

Declare it as a global variable at the top of the sketch to make it available everywhere in the sketch

Thanks! I'll try again...

...but fix all those assignments

It worked.

Did you fix the erroneous assignments such as

    if (Command = "Motor ON")

For a limited definiton of "worked"

So what I want is that what you input in the serial monitor is what the Arduino will control the motors on. so I want the 'Command' to be a certain text to do that. So how do you do that?

Well... I did get a error while during verification, but then it went away. What happened?

Command is a single character - it can never be equal to a string like "motor on".
Take a look at the serial handling basics topic.

So do you know how to make something that contains a string?

Serial handling basics topic.

Ummmm... Where can I find that? I am kind of new.


Always a good idea to take a really long look at the pinned topics before posting.

Serial input basics - updated

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