How do I solve, the error ' thresh was not declared'

Did you declare the variable thresh[] in the sketch?

Please attach code using the code </> tags

In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.

![solve|690x356](upload://9Tb84XhLdo7UpwMSEc4qbyerXO8.png)

![solve|690x356](upload://9Tb84XhLdo7UpwMSEc4qbyerXO8.png)

``

Not the image, but copy/paste in the code.

#include <NewPing.h>  // This library allows us to search (or "ping") for the nearest object.

#define TRIGGER_PIN 11    // Digital Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 10       // Digital Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200  // Maximum distance we want to ping for (in centimeters).
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);  // Open serial monitor at 115200 baud to see distance and threshold results.
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(50);
  // Wait 50ms between pings (about 20 pings/sec) so that there's time to respond.
  unsigned int uS = sonar.ping();       // Send ping, get ping time in microseconds (uS).
  int distance = uS / US_ROUNDTRIP_CM;  // Convert microseconds into distance in centimeters.
  Serial.print(distance);               // Print distance.
  Serial.print("cm");
  // if statement determines how full the bin is. If distance is between thresh[0], or 24cm, and thresh[1], or 18cm,
  // the bin is only 25% full.
  if (distance < thresh[0] && distance >= thresh[1]) {
    Serial.print(", 25% Full");
  } else if (distance < thresh[1] && distance >= thresh[2]) {
    Serial.print(", 50% Full");
  } else if (distance < thresh[2] && distance >= thresh[3]) {
    Serial.print(", 75% Full");
  } else if (distance < thresh[3] && distance >= thresh[4]) {
    Serial.print(", 100% Full");
  } else {
    Serial.print(", Empty");  // Empty will print if you take the sensor out of the bin or the sensor is not getting a reading
  }
  Serial.println();
  delay(1000);
}

Perhaps there is a line or two you did not copy?

this is all I've got. Do you think that something is missing?

The line where "thresh[]" is defined seems to be missing, as others have pointed out.

its been set from 0-4, check the if statement part

No it is not being set. You are just reading the values in an array at that point. Nowhere do you create the array and seed it with values. To do that just before the setup function have the line:-

int thresh[] = { 10, 20, 30, 40, 50};

Where the numbers 10, 20, 30, 40, 50 are replace with the threshold values you want to use when deciding what range you are detecting.

Thank you so much,
The error cleared.