• Good news!

    Even got it work on a esp32 with espruino
    Here is the code

    var high = 0.5;
    var low = 0.0;
    
    function map_value(val, in_min, in_max, out_min, out_max){
      var result = (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
      
      if(result < out_min) {
        return out_min;  
      } 
      else if(result > out_max) {
        return out_max;
      }
      
      return result;
    }
    
    function onTimer() {
      var h = analogRead(D35); // D35 is a adc-port (analog to digital converter)
      var hp = map_value(h, low, high, 0, 100);
      var percentage = hp.toFixed(0)+"%";
      
      console.log("Soil moister", percentage);
    }
    
    // Update soil moister every 2 seconds
    setInterval(onTimer, 2000);
    // Update soil moister immediately
    onTimer();
    

    To bad there are no bluetooth support yet :(

About

Avatar for Wilberforce @Wilberforce started