user54578: I have an Arduino connected to a 4-20 mA sensor through a current to voltage converter. When connected to the power supply the sensor reading fluctuates, as soon as I also connect it to a USB port it stabilizes and gives a correct reading (tested with other reader).
My main code is:
#include <Arduino.h>
#include "Display.h"

#define MINIMUM_DEWPOINT -100
#define MAXIMUM_DEWPOINT 20
#define AVG_READING_SIZE 20

float dewPoint;
uint8_t recordIndex = 0;
uint16_t analogReadingValue[20];
int sensorMin = 0;
int sensorMax = 1023;
int sensorValue = 0;

void setup()
{
    Serial.begin(9600);
    Display::init();

    for(uint8_t i = 0;i<AVG_READING_SIZE;i++)
    {
        analogReadingValue[i] = 0;
    }
}

uint16_t getAvg(uint16_t *arr,uint8_t numberOfElements)
{
    uint32_t sum = 0;
    for (uint8_t i = 0 ; i < numberOfElements ; i++)
    {
        sum += arr[i];
    }
    return  (uint16_t)(sum / numberOfElements);
}

void loop()
{
    analogReadingValue[recordIndex] = analogRead(A0);
    dewPoint = map(getAvg(analogReadingValue,AVG_READING_SIZE), sensorMin, sensorMax, MINIMUM_DEWPOINT, MAXIMUM_DEWPOINT);
    recordIndex++;

    if(recordIndex==AVG_READING_SIZE)
    {
        recordIndex = 0;
    }

    Display::displayDewpoint(dewPoint);
    Serial.println(dewPoint);
    Serial.println(getAvg(analogReadingValue, AVG_READING_SIZE));
    delay(2000);
}

My circuit diagram is:


user54578: Apparently 5V reference on the 5V pin was the issue as 5V was only supplied to the Vin pin and it was referencing to 0V. Swapping the power supply from Vin to 5V solved the issue

user40586: You need a decoupling ceramic capacitor between A0 and GND. 100nF should work just fine.

54578: <p>I have an Arduino connected to a 4-20 mA sensor through a current to voltage converter. When connected to the power supply the sensor reading fluctuates, as soon as I also connect it to a USB port it stabilizes and gives a correct reading (tested with other reader).</p>

<p>My main code is:</p>

<pre class="lang-cpp prettyprint-override"><code>#include &lt;Arduino.h&gt;
#include "Display.h"

#define MINIMUM_DEWPOINT -100
#define MAXIMUM_DEWPOINT 20
#define AVG_READING_SIZE 20

float dewPoint;
uint8_t recordIndex = 0;
uint16_t analogReadingValue[20];
int sensorMin = 0;
int sensorMax = 1023;
int sensorValue = 0;

void setup()
{
    Serial.begin(9600);
    Display::init();

    for(uint8_t i = 0;i&lt;AVG_READING_SIZE;i++)
    {
        analogReadingValue[i] = 0;
    }
}

uint16_t getAvg(uint16_t *arr,uint8_t numberOfElements)
{
    uint32_t sum = 0;
    for (uint8_t i = 0 ; i &lt; numberOfElements ; i++)
    {
        sum += arr[i];
    }
    return  (uint16_t)(sum / numberOfElements);
}

void loop()
{
    analogReadingValue[recordIndex] = analogRead(A0);
    dewPoint = map(getAvg(analogReadingValue,AVG_READING_SIZE), sensorMin, sensorMax, MINIMUM_DEWPOINT, MAXIMUM_DEWPOINT);
    recordIndex++;

    if(recordIndex==AVG_READING_SIZE)
    {
        recordIndex = 0;
    }

    Display::displayDewpoint(dewPoint);
    Serial.println(dewPoint);
    Serial.println(getAvg(analogReadingValue, AVG_READING_SIZE));
    delay(2000);
}
</code></pre>

<p>My circuit diagram is:
<a href="https://i.stack.imgur.com/K503v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K503v.png" alt="enter image description here"></a></p>
 54578: <p>Apparently 5V reference on the 5V pin was the issue as 5V was only supplied to the Vin pin and it was referencing to 0V. Swapping the power supply from Vin to 5V solved the issue</p>
 40586: <p>You need a decoupling ceramic capacitor between A0 and GND. 100nF should work just fine.</p>
