Project 5 out of the project book the is 'potVal' was not declared in this scope

what do i need to do to get this program to work the error is ‘potVal’ was not declared in this scope
and i need help on how to fix it if anyone could help that would be great

void setup() {
// put your setup code here, to run once:
#include <Servo.h>;
Servo myServo;
int const potPin = A0;
int potVal;
int angle;
myServo.attach(9);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
potVal = analogRead(potPin);
Serial.print(“potVal: “);
Serial.print potVal ;
angle = map(potVal, 0, 1023, 0, 179);
Serial.print(”, angle:”);
Serial.println(angle)
myServo.write(angle);
delay(15);
}

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here

Have another closer look at the code in the book

#include <Servo.h>;
Servo myServo;
int const potPin = A0;
int potVal;
int angle;

Should these statements be inside setup() ?
I think not otherwise the variables will not be available outside of setup()

Hi,
As well as what @UKHeliBob has pointed out.

Serial.print potVal ;

Should be;

Serial.print (potVal) ;

Tom... :slight_smile:

Hello beenobread,

You might find this useful Variable scope as your problem is caused by not understanding variable scope.

I found that whole of that web site useful when I was learning C.

Please use code tags </> when posting code.

Recheck the code in the book. The code you have posted here has many errors...

You can find the programs in the IDE:
File > Examples > 10.StarterKit_BasicKit