 
 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;
+   digitalWrite(trigPin,LOW);
+    delayMicroseconds(2);
+    
+    digitalWrite(trigPin,HIGH);
+    delayMicroseconds(10);
+    
+    duration=pulseIn (echoPin,HIGH);
+    
+    distance= duration/58.2;
+    delay (1000);
+    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
+  int d3 = CheckDistance();           /// get object distance using ping
+  d1=testDistance-d3;
+  d2=(d1 *6.66666667);
+
+
+  if (d2 > 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");
+   Serial.println(d2);
+   Serial.println("Percent full");
+
   delay(500);
 
 

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








  DEBUG = true;         // enable debug serial

//Initializing the Pins of the Ultrasonic Sensor (Trig pin as the output and Echo pin as the input)
  Serial.begin (9600);
  pinMode (trigPin, OUTPUT);
  pinMode (echoPin, INPUT );


    
  Serial.begin(9600);                  // starts the serial
  pinMode(pinRed, INPUT);             // initialize the Danger Pin
  pinMode(pinNorm, INPUT);           // initialize the Normal  Pin
