Keep the level of resistance fixed?

Hi,

I am wanting to detect any lateral movement of a rod pendulum. The pendulum is attached to a 10k pot at one end and the other end hanging down and is free to swing back and forth in one 2 directions. The Arduino then fires off a command if it detect a voltage change on pin A0 from the 10k pot.

This works great but when the pendulum is NOT moving the voltage is floating slightly on the Arduino A0 pin thus my readings are eg 556,556,557,558,556,555,557 probably due to noise!

I have put the readings into a moving average to help smooth and using that to detect any changes which has help but I still do get the odd of fluctuations so instead of detect 1mv change on the A0 pin I am having to detect approx 5mv but I would like to lower this.

Does anybody know of a way to say reduce this further either electrically or programmatically.

Thanks

How frequently are you sampling the pot?

I ask because a good way to deal with this is to increase the sampling rate and then apply a low pass filter, which you can implement in two lines of code.

Obviously that's after you've eliminated all the usual sources of noise. :slightly_smiling_face:

Have you worked out the effect of the pot on the Q of your pendulum?

Thanks for the reply

I am taking 5 samples per second for the pot.

What is Q ?

Which Arduino.
An Uno should not vary by more than one A/D value.
If it does, you could have a wiring issue.
Did you connect the pot directly to VCC/GND/A0 (not shared with other things).

This would get solved faster if you had posted according to the forum guidelines (code, picture, etc.)
Leo..

Hi,
Try placing a small value capacitor in port A0, to eliminate possible electrical noise.
maybe 1Kpf.

Which ref. are you using for ADC?

RV mineirin

Don't start 'fixing' until you know the real problem.

Pots should ONLY be read with default Aref.
Leo..

https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/

  • DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)

Atmel-8271I-AVR- ATmega-Datasheet_10/2014

The internal voltage reference may thus be decoupled by an external
capacitor at the AREF pin to improve noise immunity.

RV mineirin

Which is already done on an Uno.
Leo..

So, here is the info for Wawa wanted.

I am running everything off 3.3V from the Uno at the moment with the main Uno power coming from the 5v USB but it will be eventually driven off a 5V power pack
There will be a mixture of 3.3v and 5v components so will be using a level shifter for the 5v components.

I will be using analogReference(EXTERNAL); as I shall be adding 2 thermistors to the project, these are currently working fine on my main Uno project all running at 3.3v but when I tried 5V I keep getting errors so setting analogReference to DEFAULT will not work.

#include <movingAvg.h>

int RotationResistancePin = A0;

movingAvg Rotation_Resistance(8);

int RRv = 0;

void setup(void) {

Serial.begin(9600);

Rotation_Resistance.begin();

RRv = RotationResistance();

}

void loop(void) {

RRv = RotationResistance();

if (RRv > 1) {

Serial.print("Resistance Change @ ");

Serial.println(RRv);

}

}

int RotationResistance() {

int avg = 0;

int diffres = 0;

int pc = 0;

pc = analogRead(RotationResistancePin);

if (pc >= 1023) {

pc = 1023;

}

avg = Rotation_Resistance.reading(pc); // calculate the moving average

diffres = abs(pc - avg);

return diffres;

}

Here is my output of my Serial Monitor.

fdfd

My question made sense?

RV mineirin

What does that mean. Why EXTERNAL.
Thermistors (and pots) are ratiometric sensors.
They must be powered from the same source (voltage) as Aref, to keep ratiometric behaviour.
You don't get a higher resolution if you lower Aref (if that's what you're thinking of).

What's under the heatshrink. Did you solder the wires, or just use Dupond connectors.
Did you try to read the pot with just a basic sketch, before you resorted to averaging.
Did it jump <= 1 A/D value then?
Leo..

It's the ratio of how much energy is stored in the bob, compared with how much energy is lost per swing (multiplied by a constant, which is unimportant to the concept). So, a high Q means a high ratio between energy stored and energy lost.

If a constant amplitude is to be maintained, the energy lost per swing must be replaced by the energy added by the clock escapement (or whatever impulsing system is used). If energy lost = energy added, then another way of defining Q is the ratio of energy stored to the energy added.

Adding energy (the "impulse") has the potential to interfere with the timekeeping. Adding energy must be done exactly symmetrically about the centre point of the pendulum swing, otherwise the pendulum will be sped up or slowed down by the impulse. No mechanical clock, and virtually no electrical clock, produces that perfect impulse. Therefore, the smaller we can make the impulse, the less it will interfere with the timekeeping. And we make the impulse smaller by making the energy lost by the pendulum smaller, which means the Q will be higher. In summary: for a given pendulum, the smaller the losses (the higher the Q), the smaller the impulse, and the smaller the interference from the impulse, so the better the timekeeping.

Your potentiometer will add a small frictional loss to the pendulum, which means it will lower the Q of the pendulum, which means it may not keep such good time. The reason I asked is because if you want to make precision measurements of a pendulum's behaviour, it's not a good idea to use a potentiometer.

Phew! Sorry for the length of this! :grinning:

1 Like

It depends what you are hoping to do with the measurements, but if you want a precise picture of what the pendulum is doing moment-by-moment, you really need to sample much faster than that. At least ten times faster would be good: 50Hz sampling. As I say, it depends on what the aim is, which you haven't told us yet.

If precision is important, I would avoid filtering in software or hardware. All filtering introduces phase distortion in the signal, which you may not want. (If that is unimportant then filtering is worth discussing.)

Finally, are you sure the pendulum really is exactly stationary? All pendulums move slightly in response to vibrations in the floor or wall of the building, and to air movements. Thus what you are measuring might, actually, be real, not noise.

I do hope the potentiometer will not be moving very often.

That is a common carbon track potentiometer. It will wear out very quickly! :roll_eyes:

Thanks for the replies.

The pendulum will not be moving very much, it's just there to detect any movement.
I did try an MPU6050 at the end of the pendulum but it was problematic.

My main project is working fine, I am just adding the pendulum to this project so just setting the pendulum bit up on another Uno first and writing the code before migrating to my main project.

I did just sense the pot changes before the smoothing but because of the variance of the readings I added smoothing. I don't really need a higher sampling rate for precision as I am not needing precision movement detection, I just need to detect a single movement every now and then. Think of it this way, I just wish to detect a single movement but not measure it every 5 mins or so.

1 Like

I am just following the article code for using these thermistors, if they are set at Default then THEY DO give a different reading (the Steinhart equation gives a .5 degree increase) so the article states they must be at EXTERNAL Aref. to produce a correct reading. I don't understand the reason why but this is what works as I have an external temperature probe which clarifies this.

Did I miss something?
Leo..

Technically No, as the thermistors are in another project that this pendulum/pot will be added to.

This is the article on how to improve reading thermistor values. Scroll to the bottom to "Better Readings"

https://learn.adafruit.com/thermistor/using-a-thermistor

I don't have a code example but you can make your code ignore small changes (i.e. hysteresis) especially around the center point.

Note that there is ALWAYS a possibility of +/- 1 count because the analog can be on the "hairy edge" between two digital values. (But your software can ignore the 1st count.)