[Arduino Circuit Question] Using a Capacitor to Smooth Out the Messy Noise or Unstable Signal

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
AlexUAS
 
Posts: 1
Joined: Sun Dec 11, 2022 10:15 pm

[Arduino Circuit Question] Using a Capacitor to Smooth Out the Messy Noise or Unstable Signal

Post by AlexUAS »

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 : https://imgur.com/a/dARk6hX

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

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: [Arduino Circuit Question] Using a Capacitor to Smooth Out the Messy Noise or Unstable Signal

Post by adafruit_support_bill »

Software filtering is usually a simpler and more flexible approach: https://www.megunolink.com/articles/cod ... surements/

User avatar
languer
 
Posts: 102
Joined: Fri May 17, 2013 2:02 pm

Re: [Arduino Circuit Question] Using a Capacitor to Smooth Out the Messy Noise or Unstable Signal

Post by languer »

The joystick you show seems like this one: https://www.adafruit.com/product/512

What is the waveform you show of? - it doesn't look like an analog one.

The following example shows a basic example of this: https://learn.adafruit.com/pro-trinket- ... tick-mouse

You could take some ideas from that. A capacitor (to ground) at the Xout and one at the Yout pins will certainly smooth out the waveform, but the waveform you showed looks more like a serial (or pwm) signal than it does an analog one so I am not sure what you are really seeing. And as Bill suggested, software filtering may be a better option, if you end up needing to. The following section on the example above provides you some real-life example of how to "filter" the analog reading:

Code: Select all

// Reads a joystick axis (0 or 1 for x or y) and scales the 
//  analog input range to a range from 0 to <range>
int readAxis(int thisAxis) { 
  int reading = analogRead(thisAxis);  // read the analog input

  // map the reading from the analog input range to the output range
  reading = map(reading, 0, 1023, 0, range);

  // if the output reading is outside from the rest position threshold, use it
  int distance = center - reading;

  if (abs(distance) < threshold) { // if distance not to threshold, no move
    distance = 0;                  // prevents tiny jitters due to readings
  } 
  return distance;   // return the distance for this axis
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”