Uno wifi R4 analogue pins

Hi,

I'm using the below code on an Arduino uno and I am getting the correct temp of 20 degrees celsius. The exact same code on an Arduino Uno R4 Wifi is giving me a temp of 27 degrees.

I have put the LM35 direct to 5v pin.

I was using this on the Uno but noticed this doesnt work on the Rev4 Wifi analogReference(INTERNAL);

What am I doing wrong?

#include <SPI.h>
#include <SimpleTimer.h>


//pins:
// Define the analogue pin used to read the temperature sensor (A1) */
const int LM35Pin = A1;


SimpleTimer timer;


int Temperature;
float temp_val;

/////////////////////////

void setup()
{
  Serial.begin(9600);

  timer.setTimeout(3600000L, [] () {} ); // dummy/sacrificial Function timers with ID 0 cannot be turned on/off
  timer.setInterval(1000, CheckTemp); // Miliseconds to seconds, every second run function

}

void loop()
{
  timer.run();
}

void CheckTemp()
{
  Temperature = analogRead(LM35Pin);  /* Read Temperature */
  temp_val = (Temperature * 4.88); /* Convert adc value to equivalent voltage */
  temp_val = (temp_val / 10); /* LM35 gives output of 10mv/°C */
  Serial.println(temp_val);

}

The UNO R4 WiFi has a Renesas microcontroller that's fundamentally different from the ATmega controller on the regular UNO. You'd have to verify in its datasheet whether it has an internal bandgap reference and how it can be used in Arduino. Alternatively you'll have to offer an external reference voltage and compare the reading against that value.

So you'll need a modification in the code and perhaps also a modification in the project hardware.

Thanks,

Ive been doing some more reading
analogReference(INTERNAL) for uno boards is 1.1v and for the uno R4 you use AR_INTERNAL which is 1.5v. So As you say I guess its then just modifying the math?

yes, it also seems sensible that your reading is off by a couple of degrees given the fairly limited difference in reference voltage. You could run the numbers and see if it pans out if you adjust the code for this.
It's this line you'd need to modify:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.