Noise on denoised analogRead values when starting an external power source

Hi,
Summary of the problem:
I read a few times that it is normal for the ADCs inside the Arduino to be noisy. So I denoised them inside the code (I called it "deJitter"). But very strangely whenever I turn on my external power source even the denoised values inside the Serial Monitor start to be noisy again.
I even built an analog low pass filter and filtered the signal of the potentiometer. This did not change anything. So I figure that the problem somehow must have to do with the Arduino itself.
Project:
My goal is to have a stepper motor adjust its position according to the angle of a potentiometer. I want to build a motorized follow focus. This is a device which is used to turn e.g. the focus ring of a camera lens remotely.
Hardware:
AZDelivery Nano, Atmega328 CH340.
Code:

const int potiPin = A0;
const int joystickXPin = A1;
const int joystickYPin = A2;
const int joystickButtonPIn = 4;
const int stepPin = 2;
const int dirPin = 3;
const int minMicroDelay = 50;
const int maxMicroDelay = 1000;

int stepIndex = 0;
int currentStep = 0;
int potiValueInSteps = 0;
int newPotiValue = 0;
int currentPotiValue = 0;
int lastPotiValue = 0;
int potiPercentage = 0;
int joystickXValue = 0;
int joystickYValue = 0;
bool joystickButtonState = false;
int joystickMappedMicroDelay = 0;
int currentValue = 0;
int valueDifference = 0;


void setup(){
    pinMode(stepPin, OUTPUT);
    pinMode(dirPin, OUTPUT);
    Serial.begin(2000000);
    digitalWrite(dirPin, HIGH);
    digitalWrite(stepPin, LOW);
}

void loop(){
    // joystickControlsMotor(516);
    turnForPotiValue(400);
    // motorOneStep(true, true, 500000);
    // Serial.println(analogRead(potiPin));
}



void joystickControlsMotor(int centerValue){
    /*
    Functionality:
        AnalogRead of Joystick controls speed and direction of the motor.

    Arguments:
        centerValue: idle value of the analogRead input at which the motor is not turned.
    */
    joystickYValue = analogRead(joystickYPin);

    if (joystickYValue > (centerValue + 10)){
        joystickMappedMicroDelay = map(joystickYValue, (516 + 10), 1023, maxMicroDelay, minMicroDelay);
        motorOneStep(true, true, joystickMappedMicroDelay);
    }
    else if (joystickYValue < (centerValue - 10)){
        joystickMappedMicroDelay = map(joystickYValue, 0, (516 - 10), minMicroDelay, maxMicroDelay);
        motorOneStep(true, false ,joystickMappedMicroDelay);
    }
    else{
        motorOneStep(false, false, joystickMappedMicroDelay);
    }
}

int deJitter(int newValue){
    valueDifference = newValue - currentValue;
    if (valueDifference > 5 || valueDifference < -5){
        currentValue = newValue;
    }
    else{
        // idle
    }
    return currentValue;
}

void setPotiPercentage(){
    /*
    Functionality:
        AnalogRead of the poti is stabilized (input jitter) and mapped from 0% to 100%.
    */
    newPotiValue = analogRead(potiPin);
    currentPotiValue = deJitter(newPotiValue);
    Serial.println(currentPotiValue);
    currentPotiValue = limitDataRange(currentPotiValue, 5, 1015);
    potiPercentage = map(currentPotiValue, 1015, 5, 0, 100);
}

int limitDataRange(int inputValue, int minValue, int maxValue){
    if (inputValue < minValue){
        return minValue;
    }
    else if (inputValue > maxValue){
        return maxValue;
    }
    else{
        return inputValue;
    }
}

void turnForPotiValue(int maxStep){
    setPotiPercentage();
    potiValueInSteps = potiPercentage * (maxStep / 100);
    //Serial.println(currentStep);
    //Serial.println(potiValueInSteps);
    if (currentStep < potiValueInSteps){
        motorOneStep(true, true, 500);
        currentStep = currentStep + 1;
        // Serial.println(0);
    }
    else if (currentStep > potiValueInSteps){
        motorOneStep(true, false, 500);
        currentStep = currentStep - 1;
        // Serial.println(1);
    }
    else if (currentStep == potiValueInSteps){
        motorOneStep(false, false, 500);
        // Serial.println(2);
    }
    // Serial.println(potiValueInSteps);
    // Serial.println(currentStep);
}

void motorOneStep(bool motorRunning, bool turningRight, int stepMicroDelay){
    /*
    Functionality:
        A signal is sent to the motor driver that performs one step of the motor.

    Arguments:
        motorRunning: if "false" the motor will hold its position, if "true" the motor will turn.
        turningRight: if "true" the motor will turn to the right direction, "false" left.
        stepMicroDelay: the smaller the delay the faster the motor will turn.
    */
    if (turningRight == true){
        digitalWrite(dirPin, LOW);
    }
    else{
        digitalWrite(dirPin, HIGH);
    }
    if (motorRunning == true){
        digitalWrite(stepPin, HIGH);
        delayMicroseconds(stepMicroDelay);

        digitalWrite(stepPin, LOW);
        delayMicroseconds(stepMicroDelay);
    }
    else{
        digitalWrite(stepPin, LOW);
    }
}

Schematic:
The schematic is in the attachement.
My guess:
Maybe the problem could be that the power source and the Arduino Nano do not share the same ground potential (I hope this term is understandable, I did not learn electrical engineering in English). However, I am scared to connect both grounds. I think if the potential of the Arduino is lower the current from the power source (about 800 mA) might flow to the Arduino and just fry it. Would it work if I put a resistor in series?
My level of experience:
I learned the basics of electrical engineering in university. But I do not have much hands-on experience.

If you need any further information please tell me.
Anyways, thanks for checking out this post and I am happy for any helpful suggestions!

I think you will need to create a common ground connection. That almost certainly would reduce the noise levels. Another thing I do when I want really tight readings is to use a TL431 (effectively, a high precision and very stable voltage reference) as the reference voltage for analog reads.

Can you show a photo of the wiring ?
If possible, can you show a screendump of the values (for example with the Serial Plotter). It makes a difference if it is noise or if it is spikes.

Your de-jitter is not enough. It might remove some spikes.

I suppose your A4899 module has the GNDs connected. Can you give a link to where you bought that module ?

You have split the power 'P'-ground from the 'A'-ground. I would like to split that more. The potentiometer is a analog signal, it should have its own ground, not shared with something else. Use three wires directly from the Arduino Nano to the potentiometer (5V, GND, A0) and do not connect something else to those wires.

You need to connect the GNDs of course. But you have to be aware of ground currents as you wrote. Suppose something is wrong and 800mA will go through the ground of the Arduino board, that will not damage it.

When the 5V is not stable, that is not a big problem.
Suppose the voltage is 5V and the potentiometer is at 50%, then analogRead() returns 512.
When the voltage drops to 4V, the potentiometer is still at 50% and analogRead() still returns 512.
Your low-pass filter could make the noise worse, because the analog value will no longer be 50%.
In that case it is better to add a capacitor of 100µF or 470µF or more to 5V and GND and remove the capacitor at A0.
A voltage reference will not help, because the potentiometer outputs a percentage (a voltage relative to the 5V).

High frequency noise can be reduced a lot by using the average of a few samples. With only 5 samples, there is already a good improvement, so lets use 100.

const int n = 100;
long total = 0;
for( int i=0; i<n; i++)
{
  total += (long) analogRead( A0);
}
int result = total / n;

To make it really smooth, a low-pass filter in software can be added. It can be done with integers, but it is easier with float. In the code below, the resulting 'value' is 99% of its own value and only 1% of the new value.

// global variable 'value'.
float value;

void loop()
{
  float new = (float) analogRead( A0);      // or the result from averaged samples
  value = (0.99 * value) + (0.01 * new);
}

Hi,
Ops circuit, a bit bigger.

Value of the pot may be too high, especially it's 100k or even more it may be sensitive to the electric noise from the stepper and driver.

Keep the wires physically separate.

Hi,
Can you please post:
Link to specs of stepper motor.
Link to specs of external power supply.

Thanks... Tom.. :slight_smile:

jrdoner:
I think you will need to create a common ground connection. That almost certainly would reduce the noise levels. Another thing I do when I want really tight readings is to use a TL431 (effectively, a high precision and very stable voltage reference) as the reference voltage for analog reads.

Hi,
thanks for your suggestions. I tried to provide a common ground connection. It made the values noisier than before (probably twice as bad). And the lowest value of the potentiometer reading could not be reached anymore.

TomGeorge:
Hi,
Can you please post:
Link to specs of stepper motor.
Link to specs of external power supply.

Thanks... Tom.. :slight_smile:

Hi Tom,
stepper motor
external power supply
A4899 by Longruner (could not find an English version)

The stepper motor works just fine without the potentiometer implementation. No noisy, jittery behavior at all when turning.

wvmarle:
Value of the pot may be too high, especially it's 100k or even more it may be sensitive to the electric noise from the stepper and driver.

Keep the wires physically separate.

The value of the potentiometer is 10k ohms. As shown in the circuit diagram.

Koepel:
Can you show a photo of the wiring ?
If possible, can you show a screendump of the values (for example with the Serial Plotter). It makes a difference if it is noise or if it is spikes.

Your de-jitter is not enough. It might remove some spikes.

I suppose your A4899 module has the GNDs connected. Can you give a link to where you bought that module ?

You have split the power 'P'-ground from the 'A'-ground. I would like to split that more. The potentiometer is a analog signal, it should have its own ground, not shared with something else. Use three wires directly from the Arduino Nano to the potentiometer (5V, GND, A0) and do not connect something else to those wires.

You need to connect the GNDs of course. But you have to be aware of ground currents as you wrote. Suppose something is wrong and 800mA will go through the ground of the Arduino board, that will not damage it.

When the 5V is not stable, that is not a big problem.
Suppose the voltage is 5V and the potentiometer is at 50%, then analogRead() returns 512.
When the voltage drops to 4V, the potentiometer is still at 50% and analogRead() still returns 512.
Your low-pass filter could make the noise worse, because the analog value will no longer be 50%.
In that case it is better to add a capacitor of 100µF or 470µF or more to 5V and GND and remove the capacitor at A0.
A voltage reference will not help, because the potentiometer outputs a percentage (a voltage relative to the 5V).

High frequency noise can be reduced a lot by using the average of a few samples. With only 5 samples, there is already a good improvement, so lets use 100.

const int n = 100;

long total = 0;
for( int i=0; i<n; i++)
{
 total += (long) analogRead( A0);
}
int result = total / n;




To make it really smooth, a low-pass filter in software can be added. It can be done with integers, but it is easier with float. In the code below, the resulting 'value' is 99% of its own value and only 1% of the new value.


// global variable 'value'.
float value;

void loop()
{
 float new = (float) analogRead( A0);      // or the result from averaged samples
 value = (0.99 * value) + (0.01 * new);
}

I just spend quite a long time to write an in-depth answer. When trying to send it I got an error that the request sent was too big and everything I wrote is gone.
To sum things up: running the potentiometer seperately seemed to solve the problem.
I will maybe also use the sample code you sent.

Thanks a lot for your help! I was struggling quite some time with this one!

Koepel:
Can you show a photo of the wiring ?
If possible, can you show a screendump of the values (for example with the Serial Plotter). It makes a difference if it is noise or if it is spikes.

Your de-jitter is not enough. It might remove some spikes.

I suppose your A4899 module has the GNDs connected. Can you give a link to where you bought that module ?

You have split the power 'P'-ground from the 'A'-ground. I would like to split that more. The potentiometer is a analog signal, it should have its own ground, not shared with something else. Use three wires directly from the Arduino Nano to the potentiometer (5V, GND, A0) and do not connect something else to those wires.

You need to connect the GNDs of course. But you have to be aware of ground currents as you wrote. Suppose something is wrong and 800mA will go through the ground of the Arduino board, that will not damage it.

When the 5V is not stable, that is not a big problem.
Suppose the voltage is 5V and the potentiometer is at 50%, then analogRead() returns 512.
When the voltage drops to 4V, the potentiometer is still at 50% and analogRead() still returns 512.
Your low-pass filter could make the noise worse, because the analog value will no longer be 50%.
In that case it is better to add a capacitor of 100µF or 470µF or more to 5V and GND and remove the capacitor at A0.
A voltage reference will not help, because the potentiometer outputs a percentage (a voltage relative to the 5V).

High frequency noise can be reduced a lot by using the average of a few samples. With only 5 samples, there is already a good improvement, so lets use 100.

const int n = 100;

long total = 0;
for( int i=0; i<n; i++)
{
 total += (long) analogRead( A0);
}
int result = total / n;




To make it really smooth, a low-pass filter in software can be added. It can be done with integers, but it is easier with float. In the code below, the resulting 'value' is 99% of its own value and only 1% of the new value.


// global variable 'value'.
float value;

void loop()
{
 float new = (float) analogRead( A0);      // or the result from averaged samples
 value = (0.99 * value) + (0.01 * new);
}

Photo of the wiring:
I will send it separately.
Amount of de-jitter:
According to the readings of the Serial Monitor the amount of the de-jitter is in fact enough. It is even more strange that the analog reading does not seem to change when I turn on the power supply. But the de-jittered value begins to jitter. But mostly in increments smaller than the de-jitter would even allow. (In theory the de-jittered value can only move in steps of 6. But after the power source is turned on it changes values in steps of 1.)
Link to A4899:
See the answer above.
Running the potentiometer completely seperate:
This seemed to work! Still a few hickups here and there but maybe they have also do to with the movement of the connections of the potentiometer when I turn it.
Too much current through the Arduino:
You wrote the Arduino would not be damaged by 800 mA. But I checked and the USB 2.0 standard seems to accept a max. current of 500 mA. So I will better not try this with the Arduino connected to my pc :slight_smile:
Sample codes:
Thanks! Maybe I will implement them instead or in connection with the de-jitter.

Thanks for your help!

Koepel:
Can you show a photo of the wiring ?
If possible, can you show a screendump of the values (for example with the Serial Plotter). It makes a difference if it is noise or if it is spikes.

Your de-jitter is not enough. It might remove some spikes.

I suppose your A4899 module has the GNDs connected. Can you give a link to where you bought that module ?

You have split the power 'P'-ground from the 'A'-ground. I would like to split that more. The potentiometer is a analog signal, it should have its own ground, not shared with something else. Use three wires directly from the Arduino Nano to the potentiometer (5V, GND, A0) and do not connect something else to those wires.

You need to connect the GNDs of course. But you have to be aware of ground currents as you wrote. Suppose something is wrong and 800mA will go through the ground of the Arduino board, that will not damage it.

When the 5V is not stable, that is not a big problem.
Suppose the voltage is 5V and the potentiometer is at 50%, then analogRead() returns 512.
When the voltage drops to 4V, the potentiometer is still at 50% and analogRead() still returns 512.
Your low-pass filter could make the noise worse, because the analog value will no longer be 50%.
In that case it is better to add a capacitor of 100µF or 470µF or more to 5V and GND and remove the capacitor at A0.
A voltage reference will not help, because the potentiometer outputs a percentage (a voltage relative to the 5V).

High frequency noise can be reduced a lot by using the average of a few samples. With only 5 samples, there is already a good improvement, so lets use 100.

const int n = 100;

long total = 0;
for( int i=0; i<n; i++)
{
 total += (long) analogRead( A0);
}
int result = total / n;




To make it really smooth, a low-pass filter in software can be added. It can be done with integers, but it is easier with float. In the code below, the resulting 'value' is 99% of its own value and only 1% of the new value.


// global variable 'value'.
float value;

void loop()
{
 float new = (float) analogRead( A0);      // or the result from averaged samples
 value = (0.99 * value) + (0.01 * new);
}

Analog reading, power supply off:

00:53:27.477 -> 853
00:53:27.477 -> 852
00:53:27.477 -> 853
00:53:27.477 -> 854
00:53:27.477 -> 852
00:53:27.477 -> 852
00:53:27.477 -> 852
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 852
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 852
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 852
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 851
00:53:27.477 -> 853
00:53:27.477 -> 852
00:53:27.477 -> 854
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 853
00:53:27.477 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 851
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 852
00:53:27.512 -> 852
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853
00:53:27.512 -> 853

Analog reading, power supply on:

2
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 851
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 852
00:55:16.573 -> 852
00:55:16.573 -> 848
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 851
00:55:16.573 -> 854
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 854
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 852
00:55:16.573 -> 854
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 849
00:55:16.573 -> 851
00:55:16.573 -> 852
00:55:16.573 -> 851
00:55:16.573 -> 854
00:55:16.573 -> 851
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 855
00:55:16.573 -> 851
00:55:16.573 -> 852
00:55:16.573 -> 852
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 855
00:55:16.573 -> 850
00:55:16.573 -> 853
00:55:16.573 -> 854
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 852
00:55:16.573 -> 851
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 858
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 851
00:55:16.573 -> 855
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 853
00:55:16.573 -> 853
00:55:16.573 -> 854
00:55:16.573 -> 853
00:55:16.573 -> 852
00:55:16.573 -> 852

De-jitter reading, power supply off:

00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.411 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.446 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852
00:56:39.481 -> 852

De-jitter reading, power supply on:

00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.386 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 854
00:58:00.420 -> 848
00:58:00.420 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 848
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 855
00:58:00.454 -> 848
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.454 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 848
00:58:00.489 -> 848
00:58:00.489 -> 848
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.489 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854
00:58:00.523 -> 854

I always try to avoid floating point calculations where possible, and use nice round numbers for this kind of averaging/oversampling.

Koepel:
High frequency noise can be reduced a lot by using the average of a few samples. With only 5 samples, there is already a good improvement, so lets use 100.

const int n = 100;

long total = 0;
for( int i=0; i<n; i++)
{
  total += (long) analogRead( A0);
}
int result = total / n;

A round number for a computer is 64 or 128. This simplifies the final calculation:

int result = total >> 6; // for n = 64, or >>7 if n = 128

This saves a modest 60 bytes, integer calculations are pretty efficient already.

To make it really smooth, a low-pass filter in software can be added. It can be done with integers, but it is easier with float. In the code below, the resulting 'value' is 99% of its own value and only 1% of the new value.

// global variable 'value'.

float value;
void loop()
{
  float new = (float) analogRead( A0);      // or the result from averaged samples
  value = (0.99 * value) + (0.01 * new);
}

Doing this with 1/64th of the new value and all bit shifts:

uint16_t value;
void loop() {
  uint16_t newVal = analogRead( A0);      // or the result from averaged samples
  value = (value << 6 + newVal) >> 6;
  Serial.print(value);
  delay(1000);
}

This saves 1356 bytes of code, as you avoid using floating point calculations. That's significant for an Arduino. It will also mean the code runs that much faster.

Using more than 6 bits shift for adding 1/128th per read means you have to increase the variable width, this fits perfectly in a 16-bit integer.

This seems to have become unnecessarily complicated.
The readings from the pot should be (reasonably) stable PROVIDED
it is connected to the +5 and GND at the Arduino.
Why - because that is where the ADC gets its reference.

@LeonHardWolf: Use three wires directly from the Arduino Nano to the potentiometer (5V, GND, A0) and do not connect something else to those wires.

I read a few times that it is normal for the ADCs inside the Arduino to be noisy

I once read the earth was flat and moon made of cheese.

Its normal for the reading to fluctuate by a small amount especialy if the input voltage is close to the transition from one ADC reading to the next. So we often take multiple readings (eg 16) and take the INTEGER average.

whenever I turn on my external power source even the denoised values inside the Serial Monitor start to be noisy again.

So the noise is coming in some way from the external power supply. You dont say if that is with the steppers active.

You need to check the ground connections on the A4988 module to see if they are seperate, but I'm guessing they are not.

The 100uF cap you have across the PSU COULD be upsetting it; in any case I'd recommend putting a choke and a BIG cap to eliminate any noise from there.

And look at your power supply connection layout; especially grounds, but if the 5V supply is shared look at the 5V rail too. Are you driving the arduino from the same psu?

All this dejitter is just fudging the problem - get rid of the noise first.

Hi,
I think some of this "noise" problem is due to layout.
Can you please post some pictures of your project so we can see your component layout?

Thanks.. Tom... :slight_smile:

Pictures of the layout:

You should start by untangling that rats nest.

It seems the wires to the stepper are somewhere somehow in the middle of passing through under and over the wires of your pot. This as you appear to have a stepper driver (the thingy with heat sink) hidden under a bunch of wires, then there's a huge bundle, and on the other side is a stepper motor...

Hi,
I don't think you will be able to improve anymore after taking @wvmarle advice.

The main problem is you are using a protoboard with many, many, mechanical connections relying on spring clips.
Long wires will not help either.

If you are making something more permanent you will need to get the soldering iron out and solder protoboard similar to this.


or one of many variants.

Tom... :slight_smile: