 }
 
 float GetHumidity(void) {
-  
+  float hum;
   val = analogRead(analogPin);
   float volt = val * 5.0 / 1024;
-  float res = log10(R / (Vref / volt - 1) / 1000);
-  float hum = a * res*res + b * res + c;
+  if (volt < Vm) {
+    hum = 100.0;
+  } else if (volt > Vref) {
+    hum = 0.0;
+  } else {
+    float res = Re / ((Vref-Vm)/(volt-Vm) - 1);
+    float reslog = log10(res);
+    hum = a * reslog*reslog + b * reslog + c;
+    if (hum > 100.0) {
+       hum = 100.0;
+    } else if (hum < 0.0) {
+       hum = 0.0;
+    }
+  }
   return (hum);
 }

static const int VCCPin = 8;
static const int analogPin = 1;
static const int R = 15000;
static const float Vref = 5.0 * 15 / (15 + 51);

static float a = 2.76366367;
static float b = -32.40924966;

  if (nowt < t) { 
      t = 0;
  }
  if ((nowt - t) > microwait) {
     digitalWrite(VCCPin, level);
     if (level == HIGH) {
          if (count == 200) {
             Serial.println(GetHumidity(),3);
             count = 0;
          } else {
             count++; 
