MKR Wifi 1010 with pressure sensor noise

I am trying to set up a pressure sensor (this model) using an MKR Wifi 1010. Everything has been working ok, but all of the sudden, I start getting a LOT of extra noise from the sensor reading. Here is the code I am using and my setup:

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float average;
  float pressureValue;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

  #include "thingProperties.h" 
  const int pressureInput = A1; // select the analog input pin for the pressure transducer
  const int pressureZero = 102.4; // analog reading of pressure transducer at 0psi
  const int pressureMax = 1023; // analog reading of pressure transducer at 100psi
  const int pressuretransducermaxPSI = 76; // psi value of transducer being used
  const int sensorreadDelay = 1000; // constant integer to set the sensor read delay in milliseconds
  float analogValue = 0; // variable to store the value coming from the analog input
  //float pressureValue = 0; // variable to store the value coming from the pressure transducer

  const int numReadings = 10;
  int readingIndex = 0;
  float total = 0;
  float readings[numReadings];
  //float average = 0;

void setup() {
    // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  Serial.begin(9600);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

}

void loop() {
  ArduinoCloud.update();
  analogValue = analogRead(pressureInput); //reads value from input pin and assigns to variable
  pressureValue = ((analogValue-pressureZero)*pressuretransducermaxPSI)/(pressureMax-pressureZero); //conversion equation to convert analog reading to psi
  
  total = total - readings[readingIndex];       // Remove the oldest entry from the total
  readings[readingIndex] = pressureValue;           // Add the newest reading to the window
  total = total + pressureValue;                 // Add the newest reading to the total number of readings
  readingIndex = (readingIndex+1) % numReadings;   // Increment the index, and wrap to 0 if it exceeds the window size


  average = total / numReadings;      // Divide the total of the window by the window size for the result

  Serial.print("Reading: ");
  Serial.println(pressureValue);
  Serial.print("Current Avg: ");
  Serial.println(average);
  Serial.println("***************************");  

  delay(sensorreadDelay); //delay in milliseconds between read values
}

Here is a chart showing the readings. You can see there is a small amount of noise, which I am averaging out, but then, the noise goes crazy. I was able to get the noise to go away by unhooking the pressure sensor from the 5v and re-attaching it. When I did that, the noise went away.

Any ideas on what is causing this? This has been happening frequently.

A couple other bits of info:

  1. The sensor is plugged into a standard compressor and I know the pressure is stable.
  2. The board is being powered through the usb.

overflow? in the averaging functions ?

Bad connections?

I don't think it's that. The noise is in the pressureValue variable, which is not averaged.

Did you see the warning to keep the sensor AWAY from vibration?

I did not see that warning, however, the compressor was filled up before I inserted the sensor and the compressor has not run since. I only have it hooked up to a compressor for testing. My intended use should not have significant vibrations.

This sensor should only be used with a 5volt-logic processor.
Bad idea to connect the sensor output directly to a 3.3volt-logic pin.
Leo..

The pressure range I am monitoring does not go above 50 psi. The specs say the voltage output at 50 psi is only 2.5 v.

Here is an update. Based on the feedback I got I did the following:

  1. I replaced the MKR board with an Uno Wifi R4 to have a 5v board.
  2. I added a hose between the system I am monitoring and the pressure sensor to minimize vibration when the system compressor runs.

I am still having the same issue. What is interesting to me is that to try replicate the issue, I hooked up two completely separate set-ups. I have two boards, each set up exactly the same with its own sensor. Both devices started getting the wild reading at exactly the same time and it seems to trigger when the compressor turns on.

I have observed the devices when the compressor runs and they are not receiving significant vibration, so I'm fairly sure that's not it. The only commonality among the two devices is they are plugged into the same outlet. Each board is being powered by it's own 5v power supply plugged into the outlet.

I'm thinking when the compressor kicks on it is sending some sort of interference to either the board or the sensor.

Any thoughts given this new info?

I will probably try powering one of the devices with batteries to see if that makes the issue go away. I do not want to do that as a long-term solution though. I'd like them to be plugged in.

Maybe it is a bad sensor?

Google "shock wave" you are seeing the compressor overcome the residual pressure in the tank and begin to add more air to the compressed air in the tank. Perfectly normal.

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