Using a Capacitor to Clean Up the Messy Noise

To whom it may concern,

Hello. I have a question about how to smooth out the noise/messy signal using a capacitor when it comes to controlling a joystick with an Arduino.

The link is pasted down below to view a photo. There are three photos within a link; Arduino/joystick diagram, photo, and signal wave.

LINK : Imgur: The magic of the Internet

As you can know, the signal is not always constant as shown in one of the photos. The signal is received by a pin A4 (Analog Pin) on Arduino Mega.

My goal here is to get rid of the unstable-messy signal wave and to smooth it out using a capacitor.

Does anyone have any ideas on how to wire a capacitor to smooth out the messy signal? And also, what type of capacitor should I use?

If someone could paste the diagram on how to wire a capacitor and also show an electrical calculation with a detailed explanation, that would be very helpful.

Best Regards,
Alex

I assume that the picture is a screen shot from the serial plotter? As far as one can see the value is varying by +/-1 LSB and occasionally by an extra LSB. This isn't really significant and could easily be conversion errors in the ADC. You could try just connecting say a 1 microfarad capacitor from the analogue input pin to ground. The type isn't really significant, whatever you have to hand. It might make a difference. I don't think a diagram is needed and calculation is superfluous - just try it and see.

For future reference you can copy and paste jpg and png images straight into your post from your PC - generally we prefer not to have to click on links.

Or just zero the LSB.

Just zeroing the LSB will not fix all of what @alexuas calls noise.

When the signal is near a point where a transition in the reported value, (analogRead() & 0x3fe, or whatever number of bits are ignored), that value will change back and forth. Without user action.

If you want stable readings, check this recent thread:

Noise on reading a potentiometer

Then weigh the tradeoffs.

HTH

a7

It looks like noise from a switching power supply of some type, I am assuming your PC. Check your Aref voltage, I suspect it also has the noise. A shielded wire would not hurt a thing.

Because you havent posted your code I can only guess what the numbers on the signal wave mean.

[quote="alexuas, post:1, topic:1066174"]
The signal is received by a pin A4 (Analog Pin) on Arduino Mega.
[/quote] but what are you using as your reference?

Its entirely normal to get adc readings that differ by +/- 1 or 2 LSB.
Even if the input voltage is exteremely precise and stable.
A capacitor wont help

You need to address this issue in software: Firstly by taking a set of readings and averaging them, as explained in this link; and secondly by ignoring any change that is less than a threshold value.

If "jitter" is only one ADC count this might help:

val = analogRead(A0);
val = antiDither(val);
} // end loop

int antiDither(int newVal) // prevents +1 <-> -1 dither
{                       
  static int val = 0, oldVal = 0;
  if(newVal != val && newVal != oldVal)
  {
    oldVal = val;
    val = newVal;
  }
  return val;
} 

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.