Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8969521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:36:13+00:00 2026-06-15T17:36:13+00:00

const int pingPin = 7; const int ledPin = 11; const int ledPin2 =

  • 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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:36:14+00:00Added an answer on June 15, 2026 at 5:36 pm
    else if (ledlevel >= 192)
    

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

    else if (ledLevel >= 192)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

void DoWork(int n); void DoWork(const int &n); What's the difference?
EDIT: void print(const int *v, const int size) { FILE *fpIn; fpIn = fopen(char-array.txt,
void foo (int x) { struct A { static const int d = 0;
class Foo { public: static const int kType = 42; }; void Func() {
class foo { public: void set(const int a) {b=a;} private: int b; }; Here
void main() { const int * a; *a = 5; } gcc error :
For this function: void foo_ref(const int& i) { cout << i << endl; }
if(typeid(int) == typeid(const int)) cout << Same types<< endl; PROGRAM OUTPUT: Same types am
So you can do this: void foo(const int * const pIntArray, const unsigned int
For example: void func(const int i); Here,the const is unnecessary since all parameters are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.