Different output from Arduino Nano when plugged to an external power source!!

Hi,

So I'm working on a project where I have to sense current using the ACS712-30A sensor interfaaced with an arduino nano; and transmit data via the nrf24l01 module to an arduino Mega setup to be the receiver!

When I'm in debug mode and the arduino NANO is plugged to my computer, I'm able to silence the noise with a 10kohms resistor and I get zeros as output. (That is, without it being connected to the sensor).
However, once I plug it to a power pack *(see specs below), I begin to get wrong values again like with the noise!

What could be the problem?
*Power bank Specs:
Capacity:4400mAh
Input:DC5.0v = 1000mA
Output:DC5.0v = 1000mA

Here's my sample code for reference...

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "RF24.h"
#include "printf.h"

#define ACS712 A0

unsigned long lastData = 0;
int dataSum = 0;
int Count = 0;

float vpc = 4.8828126; // approx. voltage per count
RF24 radio(9, 10); // CE, CSN

struct Sensor1Data {
  float v1;
  float c1;
  float p1;
  float k1;
} Sensor1;

unsigned char ADDRESS0[5]  = {0xb1, 0x43, 0x88, 0x99, 0x45}; // Define a static TX address
//just change b1 to b2 or b3 to send to other pip on resciever

void setup()
{
  radio.begin();
  Serial.begin(115200);
  printf_begin();
  radio.setPALevel(RF24_PA_MIN);
  radio.enableDynamicPayloads();
  radio.setDataRate(RF24_250KBPS);
  radio.setChannel(124);
  radio.openWritingPipe(ADDRESS0);
  radio.openReadingPipe(0, ADDRESS0);
  radio.stopListening();
}

void loop()
{
  if (millis() > lastData + 1) {
    dataSum += sq(analogRead(ACS712) - 512);
    Count++;

    lastData = millis();
  }
  // If statement to make calculations.
  if (Count == 1000) {

    // To get the RMS of the data.
    float mean = dataSum / Count;
    float value = sqrt(mean);

    // To get the Voltage (in volts) consumed.
    float Voltage = value * vpc;

    // To get the Current (in amps) consumed.
    float Current = Voltage / 66;

    // To get the Power (in watts) consumed.
    float Power = Current * 240;

    //To get the Consumption rating (in kilowatthour)
    float Consumption = Power / 1000;

    dataSum = 0;
    Count = 0;

    //Attach values to struct
    Sensor1.v1 = Voltage;
    Sensor1.c1 = Current;
    Sensor1.p1 = Power;
    Sensor1.k1 = Consumption;
    Serial.println(Sensor1.v1);
    Serial.println(Sensor1.c1);
    Serial.println(Sensor1.p1);
    Serial.println(Sensor1.k1);

    //Transmit data and check if it goes succesfully!
      bool ok = radio.write(&Sensor1, sizeof(Sensor1));
      if (ok) {
      Serial.println("Sent!");
      } else {
      Serial.println("Failed!");
      }
      delay(100);
  }
}

Thanks!

Can you post the schematic ?

Hi!
It happens because the MCU needs a voltage reference for analogs inputs.
Connect the "Aref" pin to your power supply(<=5v) and add this line to your code at setup section:

analogReference(EXTERNAL);

dont forget the 0.1uF/0.01uF ceramic capacitor between the input pin and GND.
Good luck!