 
   for(int i=0;i<VWC_CNT;i++){
     val[i] = analogRead(pin_vwc[i]); //connect sensor to Analog 0
+    update_avg(i,val[i]);
     if( mode == 1 ){
-      if(val[i]> bound[i].v_top) bound[i].v_top = val[i];
-      if(val[i]< bound[i].v_down ) bound[i].v_down = val[i];
+      if(dyn_avg[i]> bound[i].v_top - BOUND_MARGIN) {
+        bound[i].v_top = round(dyn_avg[i]);
+        bound_change[i*2+0] =1;
+      }
+      if(dyn_avg[i]< bound[i].v_down + BOUND_MARGIN ) {
+        bound[i].v_down = round(dyn_avg[i]);
+        bound_change[i*2+ 1] =1;
+      }
     }
   
     vwc[i] = 1.0-((float(val[i])-bound[i].v_down)/(bound[i].v_top-bound[i].v_down));

ADC_Bound bound[VWC_CNT];
int pin_vwc[VWC_CNT] = {A3,A4,A5};
int mode =0; //mode 0: normal mode , mode 1: calibrate mode
int count=0; // lopp count 

void save_setting(){
  for(int i=0;i<VWC_CNT;i++){
    EEPROM.put(0+i*sizeof(ADC_Bound), bound[i]);  
  }

 *  Features:
 *    load/save VWC boundry value at EEPROM address 0 ( size = 2* int )
 *    Press button to start/stop calibrate mode. 
 *    Calibrating with LED blinking
 *  
 *  Connection: 
 *    Button : D2, default high
