NTC 10K/OLED/millis for print delay

Hi.
I’ve made a code to control a temperature with cooling and heating. I’ve used millis() instead of delay and for loops.
But when I put in a millis delay for print time to my OLED screen, my temperature fluctuate +/-0,5, and the temperature is shown on the OLED immediately when I start the arduino nano. If I run the code without the millis delay for printing to my OLED, my temperature is steady as intended, and the temperature is shown on the OLED 2 sec after start up, and that seems to be correct because of the average readings of the temperature.
I can’t figure out the reason for the fluctuation to be associated with the millis delay for printing. Any ideas?

Tempregulator2.2.ino (5.9 KB)

Need to post the code correctly with code tags* and a schematic would be nice , otherwise difficult to guess .

  • phone users can’t read .INO !!

Parts of the loop() run very fast, for example the part that writes to the display.
Could you add a delay(10); or delay(100); at the end of the loop() ? Then there is a delay to make the Nano voltages steady before doing the next analogRead().

A OLED module runs at 3.3V. It might work at 5V, but its SDA and SCL signals are still 3.3V signals. As far as I know, only Adafruit makes a OLED that is compatible with a 5V Arduino board.

Using the avarage of a few samples is a good way to reduce electronic noise.

long total = 0;
const int n = 10;
for( int i=0; i<n; i++)
{
  total += analogRead( A0);
}
total += n / 2;   // add half-a-bit correction
VRT = float( total) / float( n);
VRT = (5.00 / 1024.00) * VRT;  // Conversion to voltage

Did you power the NTC+resistor with the 5V pin of the Nano ? If you accidentally used the 3.3V pin for that, then it will no longer be accurate. Do you use the GND wire to the NTC for something else ? If you, for example, have a single GND wire to a breadboard, and there is a OLED display and NTC on that breadboard, then it will be less accurate. You need a wire from the 5V pin and use that only to power the NTC+resistor, and you need a GND wire straight from the Arduino board to the NTC. Don’t use that GND wire for something else.

Thank you for your reply.
About the loop running fast. That is also what i would like, and that’s why I use millis() instead of delay and for loops. Is that wrong?
Anyway, i tried to connect one ground to the NTC as you suggest, but that maked no difference. But then I added a delay(10); at the end of the loop, and that maked the difference. The temp readings are now steady, when I use millis() delay for printing to the OLED.
A delay of 10ms is okay, that doesn’t make a big impact on the buttons in the program.
I just still don’t get why the program is running fine when i run the loop without the last millis() delay for printing to OLED, and why it is possible with the dealy(10);

It was a wild guess. The Arduino Nano has a weak 5V when powered with a USB cable. The OLED draws current and causes trouble on the I2C bus. Perhaps a small delay would remove the extra noise or voltage drop by the OLED.

What happens when you send the data to the serial monitor and not to the OLED ?

I also would like the loop() to run hundreds times per second or faster. But I don’t like to write to the OLED display every time the loop() runs.

Just tried the serial monitor without the OLED. That’s the same story. It runs fine without any delay in the printing, but when I add millis() delay for printing (100ms) the temperature fluctuate ±0,5 degrees. And if I ad a delay(10) in the end of the loop, it runs fine again.
I also tried it on a original Arduino Uno board. No difference.
I’m powering the board via the vin and gnd pins with a powerbank. Also tried to power it with 4xAA batteries(9V), but that also makes no difference.

I putted in the millis delay for printing to the OLED, because I have heard somewhere, that it’s not prefereable to print to nthe display constant.

Quick summarize.
It’s working with the delay(10) in the end of the loop, and that must be how it’s done then.
Thank you for your time and effort.

You did all the right tests, but I still don’t know the cause.
Let’s store this problem under: Weird random :poop:

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