0
const int pingPin = 7;
const int ledPin = 11; 
const int ledPin2 = 10;
int ledLevel = 0; 
int ledLevel2 = 255;
int constraint = 0;

void setup() 
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{ 
  long duration, inches, cm;

  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);

  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  constraint = constrain(duration, 500, 8000);

  ledLevel = map(constraint, 500, 8000, 255, 0);

  if (ledLevel < 192) {
  analogWrite(ledPin, ledLevel);
  ledLevel2 = ledLevel2 - 255;
  } else if (ledlevel >= 192) {
    analogWrite(ledPin, ledLevel);
    analogWrite(ledPin2, ledLevel2);
  }

  Serial.println(duration);
  delay(100);
}

This is my code for my arduino, it turns on one led when someone starts walking towards the ultrasonic sensor and when they get 3/4 of the way it turns on the second led. When I try to compile it this comes up "'ledLevel' was not declared in this scope," and highlights the else if statement.

1 Answer 1

5
else if (ledlevel >= 192)

ledLevel instead of ledlevel( L is upper case )
it should be

else if (ledLevel >= 192)
Sign up to request clarification or add additional context in comments.

1 Comment

Happens to everyone, LOL. Please upvote and mark this as answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.