Analog I/O

analogRead(pin)

Example:

function setup() {
  pinMode(A33, INPUT);
}

function readNTC(pin) {
  let ntcNominalT = 25; // Nominal temperature
  let ntcNominalR = 10e3; // Resistance at 25°C
  let ntcBCoeff = 3950; // usually 3000-4000
  let seriesResistor = 10e3; // The other resistor

  // Analog reference is not the same as system voltage
  let vSys = 3.3;
  let vIn = analogRead(pin);

  // Compute NTC resistance connected with series resistor
  let R = (vIn * seriesResistor) / (vSys - vIn);

  // Compute temperature using Steinhart-Hart equation
  let steinhart =
    log(R / ntcNominalR) / ntcBCoeff + 1.0 / (ntcNominalT + 273.15);
  return 1.0 / steinhart - 273.15;
}

function loop() {
  print("temp=", readNTC(A33));
}

Reads an analog voltage of the given pin and returns the read value in millivolts.

Not all pins are capable of reporting analog values. The possible values for pin are:

PinAliasDescription
33A33ADC1_CH5 / GPIO33
36A36ADC1_CH0 / GPIO36