 
   DEBUG = true;         // enable debug serial
 
-  //Initializing the Pins of the Ultrasonic Sensor (Trig pin as the output and Echo pin as the input)
-  pinMode(trigPin, OUTPUT);
-  pinMode(echoPin, INPUT);
-
+//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


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);



    if (DEBUG)  Serial.println("Temp=" + String(t) + " *C");
    if (DEBUG) Serial.println("Humidity=" + String(h) + " %");

   if (d2>0){
       thingSpeakWrite(t, h, d2);                                     // Write values to thingspeak
   }
   
  }
