• thanks Manxome, I will have to try the shorter version later.

    Meanwhile, here is my code for reading temperature from a home made temp sensor.

    I soldered an NTC resistor (size 0603) onto a small piece of circuit board, added wires and mounted it inside a stainless ring terminal of the type you crimp onto a wire, using epoxy. One of the two wires connect to GND, the other one to A1, with a 10k pullup to 3.3V.
    I run the macro by typing "getTemp(A1);"

    function getTemp(pin){
      var n=10;
      var val=medianRead(n,pin);
      var ohms=10000*val/(1-val);
      var A=0.00088607485;
      var B=0.00025169965;
      var C=0.00000019152452;
      var W=Math.log(ohms);
      var temp=1/(A+W*(B+C*W*W))-273.15;
      return temp.toFixed(3);
    }
    function CompareForSort(a,b) {
      if(a==b)
        return 0;
      if(a<b)
        return -1;
      else
        return 1;
    }
    function medianRead(n,pin){
      var myarr = [];
      for (i=0;i<n;i++){
        myarr[i]=analogRead(pin);
      }
      myarr.sort(CompareForSort);
      myarr.splice(n-2,2);
      myarr.splice(0,2);
      m=myarr.length;
      var sum = myarr.reduce(function(a,b) {
        return a+b;
      });
      return sum/m;
    }
    
    
About

Avatar for tage @tage started