 
 #define trigPin 5
 #define echoPin 4
-int binHeight = 11.5;       //silo height is 18 cm
-float binPercent;
-float binPercenttwo;
-float binpercentThree;
-
+//ultrasonic variables
+int maximumRange = 50;
+long duration, distance, d1,d2,d3;
+int testDistance=15;
 
 const int pinRed = 9;        // initialize the danger pin
 const int pinNorm = 8;      // initialize normal pin


int CheckDistance()
{
 long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  return distance;
}
// ====================================================================== loop

void loop()
{
  // Calculate percentages of Silo fill
  int testDistance = CheckDistance();           /// get object distance using ping
   float binPercent = 11.5 - testDistance;
  float binPercenttwo = binPercent / 11.5;
  float binpercentThree =  binPercenttwo * 100;

  int siloHeight = binpercentThree;

  if (binpercentThree > 90) /// if silo is more than 90% full
  {
    Serial.println("Silo is almost full");
  }
  Serial.print(binPercent);
  Serial.println("Empty");
  Serial.print(testDistance);
  Serial.println(" cm");
  delay(500);



  delay(20000);     // thingspeak needs 15 sec delay between updates,
}

