0

I have connected the circuit as shown.

Circuit diagram

The circuit works perfectly when I Use the Arduino ide. When I use LabVIEW, the distance from the ultrasonic sensor is always zero.

The LabVIEW circuit diagram is shown.

LabVIEW circuit diagram.

The Arduino ide code is shown below.

        int thresh_=10;
        int pin=10;
        int dist_=0;
        #define echoPin 2
        #define trigPin 3
        
        long duration;
        int distance;
        
        void setup() {
            
           pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
           pinMode(echoPin, INPUT);
           
           Serial.begin(9600);
           pinMode(pin,OUTPUT);
           
        }
        
        void loop() {
          digitalWrite(trigPin, LOW);
          delayMicroseconds(2);
          // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
          digitalWrite(trigPin, HIGH);
          delayMicroseconds(10);
          digitalWrite(trigPin, LOW);
          // Reads the echoPin, returns the sound wave travel time in microseconds
          duration = pulseIn(echoPin, HIGH);
          // Calculating the distance
          distance = duration * 0.034 / 2;
        
          
            Serial.println(distance);
           if (distance<=20){
            digitalWrite(pin,HIGH);}
           else{
             digitalWrite(pin,LOW);}
        }

What could be the issue?

Dave Tweed
  • 168,369
  • 17
  • 228
  • 393
Alex Mwaura
  • 21
  • 1
  • 7
  • The result from the serial port is written to the ultrasonic sensor. The loop rate is there to show us how the program runs and does not affect the running of the program. The program runs with no error. The LED gets turned on indicating the distance value gotten from the ultrasonic sensor is always zero which cannot be true. – Alex Mwaura May 21 '21 at 10:33
  • I believe the Arduino is still part of the circuit. – Alex Mwaura May 21 '21 at 10:42
  • I am not aware of the internal workings of the Arduino and LabVIEW. Am not sure I fully understand your question. – Alex Mwaura May 21 '21 at 11:08
  • I might have misunderstood the setup. Ignore my comments above. Consider adding more details to the question though. – AJN May 21 '21 at 11:09

1 Answers1

0

The linx Ultrasonic sensor found in Labview 2020 has an issue and does not work. I double clicked it to open it’s front panel. From there I opened its block diagram window and double clicked on the digital Read pulse width to open it’s front panel. From there I opened its block diagram window and set the stimulus pulse to a constant active high.

Alex Mwaura
  • 21
  • 1
  • 7