                 System.sleep(SLEEP_MODE_DEEP, wakeUpTimeoutShort);
             }
     }
+}
+
+void measureUS() {
+    // the pulseIn from the sensor needs to be read often, otherwise it gets backed up with old measurements
+    // perhaps using the analog signal would be better
+    waterHeight = 0;
+    waterHeight2 = 0;
+    for (int i = 0; i < 100; i++) {
+        duration = pulseIn(A0, HIGH);
+        distance = duration / uSperInch; // in inches
+        waterHeightSum += totalDistance - distance;
+        delay(50);
+    }
+    waterHeight = waterHeightSum/100;
 }
 
 void eventHandler(String event, String data)

float distance;
unsigned long duration;
float waterHeight;
//################### update these vars ###################
float totalDistance = 64; // the distance from the sensor to the bottom of the water tank
//################### update these vars ###################

// photocell
float lightIntensity;

    Particle.publish(eventPrefix + "/waterTankSensor/online", "true");
    
    // water height
    ThingSpeak.setField(1, waterHeight);
	
	Particle.publish(eventPrefix + "/waterTankSensor/waterHeight", String(waterHeight));
