'Stop' was not declared in this scope problem

Hello we would like to ask for help, we are very new to coding Arduino or coding in general and we hope to find a solution to fix the build up error code, but we as a group would like to seek help from other people. Thank you!

#include "IR_remote.h"
#include "keymap.h"

IRremote ir(3);

#include <Servo.h>

int base_degress;
int arm_degress;
int claw_degress;

Servo myservo1;
Servo myservo2;
Servo myservo3;


void setup()
{
  IRremote ir(3);

  base_degress = 90;
  arm_degress = 90;
  claw_degress = 90;
  myservo1.attach(9);
  myservo2.attach(10);
  myservo3.attach(11);
  myservo1.write(claw_degress);
  delay(500);
  myservo2.write(arm_degress);
  delay(500);
  myservo3.write(base_degress);
  delay(500);
  pinMode(2, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(6, OUTPUT);
  Stop();
}
void loop(){
  myservo1.write(claw_degress);//make claw servo 1 rotate to 90°
  delay(200);
  myservo2.write(arm_degress);//make arm servo 2 rotate to 135°
  delay(200);
  myservo3.write(base_degress);//make base servo 3 rotate to 90°
  delay(200);
}
}

void loop(){
  if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_UP) {
    Move_Forward(100);
    delay(300);
    Stop();
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_DOWN) {
    Move_Backward(100);
    delay(300);
    Stop();
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_LEFT) {
    Rotate_Left(70);
    delay(300);
    Stop();
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_RIGHT) {
    Rotate_Right(70);
    delay(300);
    Stop();
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_OK) {
    Stop();
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_9) {
    claw_degress = claw_degress - 5;
    if (claw_degress <= 50) {
      claw_degress = 50;

    }
    myservo1.write(claw_degress);
    delay(2);
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_7) {
    claw_degress = claw_degress + 5;
    if (claw_degress >= 180) {
      claw_degress = 180;
    }
    myservo1.write(claw_degress);
    delay(2);
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_2) {
    arm_degress = arm_degress + 5;
    if (arm_degress >= 180) {
      arm_degress = 180;
    }
    myservo2.write(arm_degress);
    delay(2);
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_8) {
    arm_degress = arm_degress - 5;
    if (arm_degress <= 0) {
      arm_degress = 0;
    }
    myservo2.write(arm_degress);
    delay(2);
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_4) {
    base_degress = base_degress + 5;
    if (base_degress >= 180) {
      base_degress = 180;
    }
    myservo3.write(base_degress);
    delay(2);
  } else if (ir.getIrKey(ir.getCode(),1) == IR_KEYCODE_6) {
    base_degress = base_degress - 5;
    if (base_degress <= 0) {
      base_degress = 0;
    }
    myservo3.write(base_degress);
    delay(2);
  }
void Stop() {
  digitalWrite(2,LOW);
  analogWrite(5,0);
  digitalWrite(4,HIGH);
  analogWrite(6,0);
}
}
void Move_Backward(int speed) {
  digitalWrite(2,LOW);
  analogWrite(5,speed);
  digitalWrite(4,HIGH);
  analogWrite(6,speed);
}
void Rotate_Right(int speed) {
  digitalWrite(2,HIGH);
  analogWrite(5,speed);
  digitalWrite(4,HIGH);
  analogWrite(6,speed);
}
void Rotate_Left(int speed) {
  digitalWrite(2,LOW);
  analogWrite(5,speed);
  digitalWrite(4,LOW);
  analogWrite(6,speed);
}

void Move_Forward(int speed) {
  digitalWrite(2,HIGH);
  analogWrite(5,speed);
  digitalWrite(4,LOW);
  analogWrite(6,speed);
}

The problem is that your stop() routine is defined within loop(). Note the additional curly brace below your stop ():

void Stop() {
  digitalWrite(2,LOW);
  analogWrite(5,0);
  digitalWrite(4,HIGH);
  analogWrite(6,0);
}
}

Change it to this and it may compile a little better:

}
void Stop() {
  digitalWrite(2,LOW);
  analogWrite(5,0);
  digitalWrite(4,HIGH);
  analogWrite(6,0);
}

This problem is easier to spot if you use proper indentation, for instance by using auto-formatting.

And you have two loop() functions in your code. it's not OK.

1 Like

Hi, thank you so much but sadly it didn't work. Here is the error build up message:

Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"

C:\Users---\Downloads\LAFVIN 4WD Robot Arm Smart Car V2.2 (1)\Arduino_Code\Lesson_8\Test_1_Infrared_Remote_Control_Robot_Arm_Smart_Car\Test_1_Infrared_Remote_Control_Robot_Arm_Smart_Car.ino: In function 'void setup()':
Test_1_Infrared_Remote_Control_Robot_Arm_Smart_Car:37:3: error: 'Stop' was not declared in this scope
Stop();
^~~~
C:\Users---\Downloads\LAFVIN 4WD Robot Arm Smart Car V2.2 (1)\Arduino_Code\Lesson_8\Test_1_Infrared_Remote_Control_Robot_Arm_Smart_Car\Test_1_Infrared_Remote_Control_Robot_Arm_Smart_Car.ino:37:3: note: suggested alternative: 'loop'
Stop();
^~~~
loop
C:\Users---\Downloads\LAFVIN 4WD Robot Arm Smart Car V2.2 (1)\Arduino_Code\Lesson_8\Test_1_Infrared_Remote_Control_Robot_Arm_Smart_Car\Test_1_Infrared_Remote_Control_Robot_Arm_Smart_Car.ino: At global scope:
Test_1_Infrared_Remote_Control_Robot_Arm_Smart_Car:47:1: error: expected declaration before '}' token
}
^
Multiple libraries were found for "Servo.h"
Used: C:\Users---\OneDrive\Documents\Arduino\libraries\Servo
Not used: C:\Program Files (x86)\Arduino\libraries\Servo
exit status 1
'Stop' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

That was to be expected; see the additional responses above.

The problem seems to trace to an attempt to merge several sketches by copy-pasting them together and this has resulted in numerous syntax errors.

Start with reformatting your code so it's easier to see where the obvious problems with curly braces are.

+1.

And when you have new code, let us see it in a new post on this thread. We can't track all of what you do without too much like work and the possibility that we do what was you said, and you did not, or vice versa.

a7

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