Cold weather effecting reading?

When no sensors are pressed I have flactuating of reading around 15 numbers jumping around (between 0 to 15 ).

Yesterday I was facing the same but after a while it stopped and reading was stable.
What can It be? a change in temperature can make it?
I am wiring my arduino as follow:

I'm reading with the following code:

const byte heartbeatLED = 13;
unsigned long heartbeatMillis;
unsigned long previousMillis = 0;

unsigned long interval = 20; //reading every x ms

//mux pin for reading//
int s0 = 2;
int s1 = 3;
int s2 = 4;
int s3 = 5;

const int NUMSENSORS = 14; // change this variable to set the number of sensors

int SIG_pin = A0;
int previousValue[NUMSENSORS] = {0};
bool isOn[NUMSENSORS] = {false};


int pressThreshold = 22; // Change this variable to set the pressThreshold value
byte filter = 5; //whatever is needed

void setup() {
  Serial.begin(115200);
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  pinMode(heartbeatLED, OUTPUT);
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    readSensors();
    checkHeartbeatTIMER();
  }
}

void readSensors() {
  // Loop through all the sensors
  for (int i = 0; i < NUMSENSORS; i++) {
    // Set the multiplexer to select the correct channel
    digitalWrite(s0, (i & 1));
    digitalWrite(s1, (i & 2) >> 1);
    digitalWrite(s2, (i & 4) >> 2);
    digitalWrite(s3, (i & 8) >> 3);

    // Read the sensor value
    int sensorValue = 1023 -  analogRead(SIG_pin);

    // Check if the sensor value has changed
    if (sensorValue != previousValue[i]) {
      // Check if the change is greater than the filter value
      if (abs(previousValue[i] - sensorValue) > filter) {
        // Update the previous value
        previousValue[i] = sensorValue;

        // Print the sensor value
        Serial.print("value_ch");
        Serial.print(i);
        Serial.print(" ");
        Serial.println(sensorValue);


        // Check if the sensor value is greater than the press threshold
        if (sensorValue > pressThreshold) {
          // Check if the sensor is not already on
          if (!isOn[i]) {
            // Update the on/off state
            isOn[i] = true;
            // Print the on/off state
            Serial.print("ch");
            Serial.print(i);
            Serial.print("on ");
            Serial.println(isOn[i]);
          }
        }
        else {
          if (isOn[i]) {
            isOn[i] = false;
            Serial.print("ch");
            Serial.print(i);
            Serial.print("on ");
            Serial.println(isOn[i]);
          }
        }
      }
    }
  }
}




void checkHeartbeatTIMER()
{
  //*********************************                                heartbeat TIMER
  //is it time to toggle the heartbeatLED ?
  if (millis() - heartbeatMillis >= 500ul)
  {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the heartbeatLED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

} //END of   checkHeartbeatTIMER()

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

Where is the datasheet?

How long are the wires between the FSRs and the multiplexer? A 0.1uf ceramic cap from each FSR output to ground. That may help with environmental noise. That noise can come from fluorescent lights or any number of other sources.

image

wires are 3.3~ meters

data sheet:

Consider using a different sensor, what you describe is typical of noise. If you can get the sensor down to about 100 Ohms, a current mode sensor or a smart sensor would work, the key is keeping the resistance low or put the noise into common mode with the appropriate electronics. Each wire you currently have is an antenna.

Consider shorter wires. Or shielded wires with twisted pairs.

Must have a 100n cap between each muxer input and muxer ground (post#4), close to the muxer.
That also eliminates cross-talk between sensors.
And use twisted pairs (post#8)
Leo..

I can't change wires now, also 3~ meters can't be changed. I will add a 100nF cap between each input pin and ground. I hope it will help.
I might also change the filter variable in the code to 10 and also increase the threshold to around 40-50 .

only about programming filter:
I used to setup my modules by aquiring a serie of value. I detect the max and min, substract both (so I get the max range). At this point, I use a correction coefficient in my code, like 1.5 for example.
Max range*1.5 give me the threshold, so at each start-up (used in a toy car), the threshold is supposed to fit the environment.

This cap between signal input to gnd solved it completely!
can someone explain how does it work? is it a kind of low pas filter? what cut-off?

Sounds like a loose wire issue. Which may have been "fixed" when the capacitors were added.

The cap shunts higher frequency (faster changing) noise to ground.

As to the cutoff frequency, try the DigiKey filter calculator .

so the cut off is at 159 hz. Rhat mean that all the signal is below that frequency? actually the signal that the mux is reading is consider DC? so it has frequency of 0 herz right?

Means that fast vibrations above 150Hz are attenuated. But this is not a sharp cutoff.
Static pressure/weight is not affected.

Note that the muxer with the A/D also have a cutoff frequency. About 300Hz.
So lowering the caps to 47n or 10n won't change much.
Leo..

when we speak about 'noise' in the reading - undesired flactuating in signal - what frequency is? the noise

You can see that yourself if you use the serial plotter.
I expect the jumps were from cross-talk between the muxer channels.
Leo..

is the signal I'm reading from the sensor is consider dc signal? no fluctuating (0Hz) ?

If the pressure on the FSR is not changing, or not varying rapidly, then yes. It's a DC signal.

As said, the jumping you saw was probably from adjacent FSR channels "leaking" into the one you were sampling. Or from mains hum picked up by the wiring, or from strong RF.
Most issues can be fixed with 100n caps from muxer inputs to ground.
Leo..

1 Like