SMC vacuum sensor

Hi All,

I am currently developing a program to capture the pressure decay using Arduino but I am having a problem on the captured data which have a quite wider difference.

The sensor that I am using is an SMC ZSE30 with 1 - 5v analog voltage output which the 0 kpa is 1v & 101kpa for 5v respectively.

I can't get my head around on the proper coding to get a more suitable results. Below is my created code and i need your expert advise on how to make it work properly.

void loop() {

int initRead = analogRead(A0); //Read initial pressure
float initVoltage = 5.0 * initRead / 1023;
float initKpa = mapFloat(initVoltage, 1.0, 5.0, 0.0, 101); // 1..5v & 0 - 101kpa
delay(3000); // 3 seconds pressure decay
int finalRead = analogRead(A0); // Read final pressure
float finalVoltage = 5.0 * finalRead / 1023;
float finalKpa = mapFloat(finalVoltage, 1.0, 5.0, 0.0, 101); // 1..5v & 0 - 101kpa
float deltaKpa = initKpa - finalKpa; // Calculate pressure difference
Serial.print("Initial Pressure: ");
Serial.print(initKpa, 3); // 3 decimals
Serial.print("Final Pressure: ");
Serial.print(finalKpa, 3); // 3 decimals
Serial.print("Pressure Delta: ");
Serial.println(deltaKpa, 3); // 3 decimals
}
float mapFloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Thanks.

float initKpa = mapFloat(initVoltage, 1.0, 5.0, 0.0, 101);    // 1..5v & 0 - 101kpa

The map function does not use the float data type.

I can't get my head around on the proper coding to get a more suitable results.

We can't see the unsuitable results nor do we know what suitable results are to you so it is hard to suggest how to fix the code.

Serial print the intermediate results. Maybe you can see where it is going wrong.

Untested.
Leo..

// 1volt is an A/D value of ~205 with a 10-bit A/D and 5volt Aref
const int offset = 205; // calibrate zero pressure
float pressure;

void setup() {
  Serial.begin(9600);
}

void loop() {
  pressure = (analogRead(A0) - offset) * 101.0 / (1023 - offset);
  Serial.println(pressure, 1); // one decimal place (= max resolution with a 10-bit A/D)
  delay(500);
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

I can't get my head around on the proper coding to get a more suitable results. Below is my created code and i need your expert advise on how to make it work properly.

What "suitable" results are you looking for.
How are you proving your results?

What is the application, what is the pressure you are trying to analyse?

Tom.... :slight_smile:

Hi Tom,

The application is to measure the sealing leakage within 3 seconds in kPa. Using my code, the leakage result has a quite larger difference (deltaKpa) where the sensor's display almost no change at all.

I am asking your expert advise on how to make this work if my coding has an issue. Your help is highly appreciated.

Regards,
Tatzmon

I am asking your expert advise on how to make this work if my coding has an issue.

Have you followed the advice given in other posts yet, and if so, what was the result?

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How are you powering your project?

Can you please post a picture of your project?

Have you replaced the sensor input with a potentimeter to see if a constant input voltage produces a zero deltaKpa ?

A link to data/specs of your sensor will help too.

Thanks.. Tom.. :slight_smile:

Hi,
You have got Voltage Output selected and are supplying the sensor with 12 to 24Vdc?

You have got the gnd of the sensor and gnd of the Arduino connected together?

Tom... :slight_smile:

Hi,

I've had created or tried a similar code made by Wawa but the result is the same and still have a quite significant offset in first and second ready. Also able to use a potentiometer to replace the sensor and i got a zero deltaKpa.

I also attached the wiring diagram,sensor specs sheet, reading result of the sensor and potentiometer.

Thanks.

Here is the code:

int pinTrigger = 7;            

const int offset = 205; // calibrate zero pressure             

bool stateTrigger = false;            
bool stateCycle = false;         
bool stateCycleComplete = false; 

float initKpa;  
float finalKpa;

void setup() {
    pinMode(pinTrigger, INPUT);
    Serial.begin(9600);
  }

void loop() {
    stateTrigger = digitalRead(pinTrigger); // Read input 

    if(stateTrigger == true && stateCycle == false) 
    {
      stateCycle = true;
      }
    if (stateCycle == true && stateTrigger == true)
    {
      
    initKpa = (analogRead(A0) - offset) * 101 / (1023 - offset); // First reading of analog value
    Serial.print("Initial Pressure: ");
    Serial.println(initKpa); 
    
    delay(3000); // 3 seconds pressure decay
    
    finalKpa = (analogRead(A0) - offset) * 101 / (1023 - offset); // Second reading after 3 seconds 
    Serial.print("Final Pressure: ");
    Serial.println(finalKpa);  
    
    float deltaKpa = initKpa - finalKpa; // Calculate pressure difference 
    Serial.print("Pressure Delta: ");
    Serial.println(deltaKpa); 
      
  }
}

Result - SEN.PNG

Result - POT.PNG

SMC_ZSA30A.pdf (188 KB)

(analogRead(A0) - offset) * 101.0 / (1023 - offset); // my code
(analogRead(A0) - offset) * 101 / (1023 - offset); // your code

Might need that .0 for a float calculation.
Leo..

Hi,

Have you got proof that the readings should be the same?
Have you a calibrated leak?
That is a container with a fixed leakage hole that is constant from test to test?

Do you have access to a storage oscilloscope so you can monitor the analog output of the sensor to help you correlate your results?

Can you use a cylinder that has a valve so you can cause a leak, and over say 30Seconds take one reading, then release some pressure, then measure again, knowing the pressure drop.
What I am getting at is you do two static readings.

Also ALL your pressure calcs should be floating, just declaring the answer floating will not give a proper floating answer, note all your results are 35.00, 33.00 they are ints in floating format.

const float offset = 205.0; // calibrate zero pressure

finalKpa = ((float)analogRead(A0) - offset) * 101.0 / (1023.0 - offset);

Make ALL the terms in your calculation float.

Tom... :slight_smile:

TomGeorge:
Make ALL the terms in your calculation float.

Not sure what the exact requirements are, but one float in a maths line usually works ok.
As said, the code I gave was untested.
Leo..

This is a tested Code. You will get output in mmHg which you can easily convert in any other units.

float A = -189.9342;
float B = 188.6949;
float C = 0.82273655;


void setup()
{
  Serial.begin(115200);
  Serial.println("Testing Vacuum Switch");
  analogReference(DEFAULT);
}

void loop()
{
  float smc_vac = smc_vac_adc();
  Serial.print("Vacuum:");
  Serial.println(smc_vac);
  Serial.print("  mmHg");
  Serial.println("");
  delay(1000);
}

float smc_vac_adc ()
{
  int adc = analogRead(A0);
  float x = adc * (4.95 / 1024);
  float vac_mmhg = 0;
  Serial.print("Voltage: ");
  Serial.println(x);

  if (x < 1)
  {
       return vac_mmhg;
  }
  else 
  {
      vac_mmhg = A + (B * x) + (C * (x*x) );
      return vac_mmhg;
  }
}