I have connected the circuit as shown.
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.
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?