Nano, LM35/DHT_11, 128x64_OLED issues

Hi,
Small project.
Utilizing Nano328 and LM35(or DHT11) for temperature reading.

Works fine, good stable and accurate temperature readings via serial.

But once I connect an 128x64_OLED temperature readings become erratic, jumping +- ~5C.

Any ideas guys? :confused:

Code /*********************************************************************This is - Pastebin.com

Are you using these lines in your code.

tempC = analogRead(tempPin);
tempC = (5.0 * tempC * 100.0)/1024.0;

That measures the LM35 against the potentially unstable default Aref.
And default Aref (5volt) of a Nano on USB power is only ~4.6volt.

The solution is to measure the LM35 with the internal 1.1volt Aref.
This example sketch also uses averaging.
Change your code to this once you onderstand it.
Leo..

// LM35 temp sensor connected A0

unsigned int total; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change to (INTERNAL1V1) for a Mega
  Serial.begin(9600);
}

void loop() {
  // read the sensor
  for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
    total = total + analogRead(A0); // add each value
  }
  // temp conversion
  tempC = total * 0.001632; // Calibrate by slightly changing 0.0016xx
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit

  Serial.print("The temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 0); // no decimal places
  Serial.println(" Fahrenheit");

  total = 0; // reset total
  delay(1000); // slows readings
}

Thanks Wawa.
Temperature reading accuracy has increased to ~ +- 1C.
That is good enough for me.

That sketch should be stable to +- 0.1C.

Accuracy has to be calibrated by you.
Every Arduino has a slightly different 1.1volt Aref, so the calibration only works for that Arduino.
Leo..

Hmn, further investigation is showing that sensor is still prone to give erratic readings once I connect the I2C 128x64 OLED screen.
Anyone else has come across sensor and I2C device interference? :frowning: