Analog input changes when relay activated on digital pins

Hello! On Arduino Nano I have connected few things: LM35DZ temp sensor on A1 pin, voltage divider to A2, SD1306 OLED display on A4 and A5, 2-channel relay module to D7 and D8, push button to D4. All things powered via arduinos 5V pin, Arduino itself powered through Vin pin with 12V battery. Everything works fine while relay is inactive. After activating relay, temperature readings rise up by ~2.6 centigrade, voltage readings increases too. For analog input precision I use internal reference of 1.1V. Thought problem was change on reference voltage, but it didn’t change when relay is activated. Why relay causes analog input anomalies?
Originally project will be used and powered by a car, to read interior temp and charging voltage when car is on, then depending on temp it will power heater or ac via relays.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define WINDOW_SIZE 25


// declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

int INDEX = 0;

float tempSUM = 0;
float voltSUM = 0;
float tempREADINGS[WINDOW_SIZE];
float voltREADINGS[WINDOW_SIZE];
float tempAVERAGED = 0;
float voltAVERAGED = 0;

const int tempSensorPin = A1;
const int voltSensorPin = A2;
float tempSensorValue;
float voltSensorValue;
float tempVoltageOut;
float voltVoltageOut;
float temperatureC;
float voltageV;
float R1 = 220000;
float R2 = 10020;

int pandoraState = 0;
const int pandoraPin = 4;
const int heaterPin = 7;
const int acPin = 8;

void setup() {
  analogReference(INTERNAL);
  pinMode(tempSensorPin, INPUT);
  pinMode(voltSensorPin, INPUT);
  pinMode(pandoraPin, INPUT_PULLUP);
  pinMode(heaterPin, OUTPUT);
  pinMode(acPin, OUTPUT);
  digitalWrite(pandoraPin, HIGH);
  digitalWrite(heaterPin, HIGH);
  digitalWrite(acPin, HIGH);
  Serial.begin(9600);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }

  delay(2000);
  display.clearDisplay();
  display.setTextColor(WHITE);
}

void loop() {
  tempSUM = tempSUM - tempREADINGS[INDEX];       // Remove the oldest entry from the sum
  voltSUM = voltSUM - voltREADINGS[INDEX];       // Remove the oldest entry from the sum

  tempSensorValue = analogRead(tempSensorPin);  // Read the next sensor value
  voltSensorValue = analogRead(voltSensorPin);  // Read the next sensor value
  pandoraState = digitalRead(pandoraPin) ;      // Read Pandora remote heater channel pin

  tempREADINGS[INDEX] = tempSensorValue;           // Add the newest reading to the window
  voltREADINGS[INDEX] = voltSensorValue;           // Add the newest reading to the window

  tempSUM = tempSUM + tempSensorValue;                 // Add the newest reading to the sum
  voltSUM = voltSUM + voltSensorValue;                 // Add the newest reading to the sum

  INDEX = (INDEX + 1) % WINDOW_SIZE; // Increment the index, and wrap to 0 if it exceeds the window size

  tempAVERAGED = tempSUM / WINDOW_SIZE;      // Divide the sum of the window by the window size for the result
  voltAVERAGED = voltSUM / WINDOW_SIZE;      // Divide the sum of the window by the window size for the result

  tempVoltageOut = (tempAVERAGED * 1069) / 1023;
  voltVoltageOut = (voltAVERAGED * 1069) / 1023;

  temperatureC = tempVoltageOut / 10;
  voltageV = voltVoltageOut / (R2 / (R1 + R2)) / 1000;

  if (pandoraState == LOW) {
    if (temperatureC <= 26) {
      digitalWrite(heaterPin, LOW);
      digitalWrite(acPin, HIGH);
    }
    else {
      digitalWrite(heaterPin, HIGH);
      digitalWrite(acPin, LOW);
    }
  }
  if (pandoraState == HIGH) {
    digitalWrite(heaterPin, HIGH);
    digitalWrite(acPin, HIGH);
  }

  // clear display
  display.clearDisplay();

  // display temperature Celsius
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.print("Temperature: ");
  display.setTextSize(3);
  display.setCursor(0, 11);
  display.print(temperatureC, 1);
  display.setTextSize(1);
  display.cp437(true);
  display.write(167);
  display.setTextSize(3);
  display.print("C");

  // display voltage
  display.setTextSize(1);
  display.setCursor(0, 40);
  display.print("Voltage: ");
  display.setTextSize(2);
  display.setCursor(0, 50);
  display.print(voltageV);
  display.print(" ");
  display.setTextSize(2);
  display.print("V");

  display.display();
  delay(10);
}


I doubt that the on-board voltage regulator of the Nano is able to provide enough power for your relay board. As a result the input voltage of the ATmega328p on the Nano drops and the ADC doesn't have a stable reference voltage anymore.

pylon:
I doubt that the on-board voltage regulator of the Nano is able to provide enough power for your relay board. As a result the input voltage of the ATmega328p on the Nano drops and the ADC doesn't have a stable reference voltage anymore.

But aRef doesn't change when relay is activated. It stays 1.068V. I have lab dc power supply with 5V output, can I connect it to 5V pin on arduino without causing harm?

What do you mean by aref? the pin named so? In your wiring diagram you didn't connect that.

I have lab dc power supply with 5V output, can I connect it to 5V pin on arduino without causing harm?

Yes, that should be possible.

Came to conclusion that I will use car phone charger to power relays as they draw 75mA each. Charger outputs 5.22V but I think it will not burn relays.

I believe the LM35's minimum voltage is 4V, if the relay coil current is dragging the supply voltage down near 4, that might cause the LM35's output to change. Datasheet page 1.

You might try supplying the LM35 with 12V.

I assume you didn't share LM35 ground with any other wiring (like relay coil ground current).
Leo..

Wawa:
I assume you didn't share LM35 ground with any other wiring (like relay coil ground current).
Leo..

Ground is shared between all components. Should be visible from schematics.

@Wawa:
Good point.