I need some coding help please

Im trying to do Project 6 in the Arduino projects book but I keep getting the same error and i could really use some help. here the error "Compilation error: 'SensorValue' was not declared in this scope" and here's my code:

int sensorValue;
int sensorLow = 1023;
int sensorHigh = 0;
const int LedPin = 8;

void setup() {

pinMode(LedPin, OUTPUT);
digitalWrite(LedPin, HIGH);
while (millis() < 5000) {
sensorValue = analogRead(A0);
if (SensorValue > sensorHigh) {
sensorHigh = sensorValue;
}
if (sensorValue < sensorLow) {
sensorLow = sensorValue;
}
}
digitalWrite(LedPin, LOW);
}

void loop() {

sensorValue = analogRead(A0);
int pitch =
map(sensorValue, sensorLow, sensorHigh, 50, 4000);
tone(8,pitch,20);
delay(10);
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

        if (SensorValue > sensorHigh)

Is the name of the variable SensorValue or is it sensorValue ?

You have both SensorValue and sensorValue. Lowercase or uppercase is significant, so those are actually two different variables. Choose one.

Thank you so much I can't believe I missed that.

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