/* The circuit: * +V connection of the PING))) attached to +5V * GND connection of the PING))) attached to ground * SIG connection of the PING))) attached to digital pin 7 */ const int tankPingPin = 7; const int snowPingPin = 28; float getPingGallons() { // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration; float inches, depth, gallons; pinMode(tankPingPin, OUTPUT); digitalWrite(tankPingPin, LOW); delayMicroseconds(2); noInterrupts(); digitalWrite(tankPingPin, HIGH); delayMicroseconds(5); digitalWrite(tankPingPin, LOW); // The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(tankPingPin, INPUT); duration = pulseIn(tankPingPin, HIGH); interrupts(); // convert the time into a distance inches = duration / 74.0 / 2.0;; // convert to depth and gallons // real tank: depth = 63 - inches; depth = 13.61f - inches; if (depth < 0) depth = 0; gallons = depth / 2.63f; Serial.print(inches); Serial.print("in, "); Serial.print(depth); Serial.print("depth, "); Serial.print(gallons); Serial.print("gallons"); Serial.println(); return(gallons); } float getSnowInches() { long duration; float inches, depth; pinMode(snowPingPin, OUTPUT); digitalWrite(snowPingPin, LOW); delayMicroseconds(2); noInterrupts(); digitalWrite(snowPingPin, HIGH); delayMicroseconds(5); digitalWrite(snowPingPin, LOW); // The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(snowPingPin, INPUT); duration = pulseIn(snowPingPin, HIGH); interrupts(); // convert the time into a distance inches = duration / 74.0 / 2.0;; // convert to snow depth depth = 36.0f - inches; if (depth < 0) depth = 0; Serial.print("Snow: "); Serial.print(inches); Serial.print("in, "); Serial.print(depth); Serial.print("depth, "); Serial.println(); return(depth); }