LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can anyone help me on how to make readings using three sensors on LabView using Visa so that the reading position doesn't move?

I tried to monitor fuel usage using three sensors, namely an ultrasonic sensor to measure tank volume, a flowmeter sensor to measure the flow of fuel coming out of the tank, and a proximity sensor to measure engine speed, but when reading in LabView using Visa, the readings did not stay in place. Sometimes the readings from the flowmeter sensor are displayed in the ultrasonic sensor readings or sometimes vice versa this is my Arduinno coding


// Pin untuk sensor flowmeter
const double flowMeterPin = 2; // Ganti dengan pin yang sesuai

// Pin untuk sensor ultrasonik HC-SR04
const double trigPin = 9;
const double echoPin = 10;
long durasi, jarak;

// Pin untuk sensor infrared proximity
const double irProximityPin = 4; // Ganti dengan pin yang sesuai

// Variabel untuk menghitung liter yang telah mengalir
volatile double pulseCount = 0;
float flowRate = 0.0;
unsigned int flowMilliLitres = 0;
unsigned long totalMilliLitres = 0;
unsigned long oldTime = 0;

void setup() {
  Serial.begin(9600);
  pinMode(flowMeterPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(irProximityPin, INPUT);

  // Attach interrupt untuk sensor flowmeterq
}

void loop() {
  // Membaca data dari sensor flowmeter dan menghitung laju alir
 
  unsigned long currentTime = millis();
  if (currentTime - oldTime > 1000) {
    detachInterrupt(digitalPinToInterrupt(flowMeterPin));

    flowRate = (1000.0 / (currentTime - oldTime)) * pulseCount;
    oldTime = currentTime;
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
    pulseCount = 0;

   
    Serial.print(flowRate);
    Serial.print(totalMilliLitres);
    Serial.println(" ml");
   
    attachInterrupt(digitalPinToInterrupt(flowMeterPin), pulseCounter, FALLING);
  }

  // Membaca data dari sensor ultrasonik

   digitalWrite(trigPin, LOW);
 delayMicroseconds(10);
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin, LOW);
 delayMicroseconds  (10);
durasi = pulseIn(echoPin, HIGH);
jarak = (durasi / 2) / 29.1;


  Serial.print( jarak );
  Serial.println(" cm");
 

  // Membaca data dari sensor infrared proximity
  int irProximityValue = analogRead(irProximityPin);
  int rpm = map(irProximityValue, 0, 1023, 0, 1000); // Misalnya, 0-1023 analog input menjadi 0-1000 rpm
 
  Serial.println(rpm);

  delay(1000); // Delay satu detik (sesuaikan sesuai kebutuhan)
}

// Fungsi untuk menghitung pulsa dari sensor flowmeter
void pulseCounter() {
  pulseCount++;
}
0 Kudos
Message 1 of 11
(623 Views)

Wiring the iteration counter to the byte count input of visa read makes absolutely no sense. Can you explain why you think that was a good idea? (reading zero bytes in the first iteration, one byte on the second iterations .... and possibly millions of bytes much later?)

 

Why are there terminals without labels? (You can hide labels on the front panel, but don't make them empty strings!

 

Then you have silly code constructs e.g. as follows:

 

altenbach_0-1703952156158.png

 

 

Have you done any basic LabVIEW tutorials?

 

(Also, when posting you would typically place code inside code tags and regular text outside, not the other way around. I fixed your post)

0 Kudos
Message 2 of 11
(618 Views)

The first thing I would do is change your messaging protocol so that you send 1 message for all three sensors at a single time.  Send a comma between each sensor reading to act as a delimiter.  So I would update your Arduino code to something more like the following:

 

// Pin untuk sensor flowmeter
const double flowMeterPin = 2; // Ganti dengan pin yang sesuai

// Pin untuk sensor ultrasonik HC-SR04
const double trigPin = 9;
const double echoPin = 10;
long durasi, jarak;

// Pin untuk sensor infrared proximity
const double irProximityPin = 4; // Ganti dengan pin yang sesuai

// Variabel untuk menghitung liter yang telah mengalir
volatile double pulseCount = 0;
float flowRate = 0.0;
unsigned int flowMilliLitres = 0;
unsigned long totalMilliLitres = 0;
unsigned long oldTime = 0;

void setup() {
  Serial.begin(9600);
  pinMode(flowMeterPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(irProximityPin, INPUT);

  // Attach interrupt untuk sensor flowmeterq
}

void loop() {
  // Membaca data dari sensor flowmeter dan menghitung laju alir
 
  unsigned long currentTime = millis();

  detachInterrupt(digitalPinToInterrupt(flowMeterPin));

  flowRate = (1000.0 / (currentTime - oldTime)) * pulseCount;
  oldTime = currentTime;
  flowMilliLitres = (flowRate / 60) * 1000;
  totalMilliLitres += flowMilliLitres;
  pulseCount = 0;

  attachInterrupt(digitalPinToInterrupt(flowMeterPin), pulseCounter, FALLING);
  // Membaca data dari sensor ultrasonik
  digitalWrite(trigPin, LOW);
  delayMicroseconds(10);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  delayMicroseconds  (10);
  durasi = pulseIn(echoPin, HIGH);
  jarak = (durasi / 2) / 29.1;

  // Membaca data dari sensor infrared proximity
  int irProximityValue = analogRead(irProximityPin);
  int rpm = map(irProximityValue, 0, 1023, 0, 1000); // Misalnya, 0-1023 analog input menjadi 0-1000 rpm

  //Send all the data in a single message
  Serial.print(flowRate);
  Serial.print(",");
  Serial.print(totalMilliLitres);
  Serial.print(",");
  Serial.print(jarak);
  Serial.print(",");
  Serial.println(rpm);

  delay(1000); // Delay satu detik (sesuaikan sesuai kebutuhan)
}

// Fungsi untuk menghitung pulsa dari sensor flowmeter
void pulseCounter() {
  pulseCount++;
}

 

 

Now on the LabVIEW side, you just try to read more than you ever expect in a message and it is simple parsing from there.  Here is a simplified version of your code.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
Message 3 of 11
(557 Views)

Thank you, you are very helpful, so what if I want to save the results of the sensor readings to Excel?

0 Kudos
Message 4 of 11
(505 Views)

Hi Campuds,

 


@Campuds wrote:

what if I want to save the results of the sensor readings to Excel?


Just do it!

I recommend to start with writing simple CSV files, using the WriteDelimitedFile function…

 

(Later on you can optimize your VI with using plain file functions together with ArrayToSpreadsheetString.)

 

Recommendation: when writing about "Excel files" you clearly should state the desired file format! Writing to CSV files is really simple as they are just text, while XLS(X) is a little more complex…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 11
(492 Views)

@Campuds wrote:

Can i use this format?


We cannot answer because a picture cannot tell us how you configured the express vi.

 

And as has been mentioned before, all your data gymnastics makes no sense at all.

0 Kudos
Message 7 of 11
(454 Views)

so what do you think what command should I do in labview?

0 Kudos
Message 8 of 11
(447 Views)

@Campuds wrote:

so what do you think what command should I do in labview?


Did you read Gerd's suggestions? it is all there!

0 Kudos
Message 9 of 11
(440 Views)