I've found that while "duration1" and "duration2" exchange their order(which means duration2 runs first, then duration1 runs.), the result becomes that distance1 shows 0 but distance2 shows correct value.

It seems there are some problems while I using the function "pulseIn", is that right?

Could anyone help me fix this problem, thanks!">
I've found that while "duration1" and "duration2" exchange their order(which means duration2 runs first, then duration1 runs.), the result becomes that distance1 shows 0 but distance2 shows correct value.

It seems there are some problems while I using the function "pulseIn", is that right?

Could anyone help me fix this problem, thanks!">
I've found that while "duration1" and "duration2" exchange their order(which means duration2 runs first, then duration1 runs.), the result becomes that distance1 shows 0 but distance2 shows correct value.

It seems there are some problems while I using the function "pulseIn", is that right?

Could anyone help me fix this problem, thanks!">
everyone. I've got a problem while I try to use Arduino uno to drive two HC-SR04 ultrasonic sensor. While a try to display two measured value from each sensor, one of them work fine but the other displays value 0.
[code]int trigPin=12; // this pin work as the output of the two trig pin of the two sensor int echoPin1=8; int echoPin2=13; void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin1, INPUT); pinMode(echoPin2, INPUT); } void loop() { float duration1, distance1, duration2, distance2; digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); //trig:10 microsecond TTL pulse duration1 = pulseIn(echoPin1, HIGH); duration2 = pulseIn(echoPin2, HIGH); distance1 = duration1/2/29.1; distance2 = duration2/2/29.1; Serial.print(distance1); Serial.print(','); Serial.println(distance2); delay(20); }[/code] The situation is that on the Serial Monitor, "distance1" shows correct value however "distance2" is always 0.

I've found that while "duration1" and "duration2" exchange their order(which means duration2 runs first, then duration1 runs.), the result becomes that distance1 shows 0 but distance2 shows correct value.

It seems there are some problems while I using the function "pulseIn", is that right?

Could anyone help me fix this problem, thanks!


JLCPCB – Prototype 10 PCBs for $2 (For Any Color)

China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir