EN / USD
32
of 76
TEP , The Engineering Projects , Image

syedzainnasir

TEP , The Engineering Projects , Rating 7.5 7.5 / 10
TEP , The Engineering Projects , Icon Level: Moderator
TEP , The Engineering Projects , Icon Joined: 20 Mar 2022
TEP , The Engineering Projects , Icon Last Active: 2:21 PM
TEP , The Engineering Projects , Icon Location: TEP , The Engineering Projects , Flag
TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon
Driving two Ultrasonic sensor with Arduino
TEP , The Engineering Projects , Calender Question: 20-Feb-2017
TEP , The Engineering Projects , Category In: Arduino Projects
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!
TEP , The Engineering Projects , Icon Answer: 1 TEP , The Engineering Projects , Icon Views: 150 TEP , The Engineering Projects , Icon Followers: 85
Small Bio
TEP , The Engineering Projects , Image

adiono

TEP , The Engineering Projects , Rating 7.5 7.5 / 10
TEP , The Engineering Projects , Icon Level: Moderator
TEP , The Engineering Projects , Icon Joined: 20 Mar 2022
TEP , The Engineering Projects , Icon Last Active: 2:21 PM
TEP , The Engineering Projects , Icon Location: TEP , The Engineering Projects , Flag
TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon TEP , The ENgineering Projects , Icon

RE:

Driving two Ultrasonic sensor with Arduino
TEP , The Engineering Projects , Calender Comment: 20-Feb-2017
TEP , The Engineering Projects , Category In: Arduino Projects
[quote=Patricia post_id=117 time=1487599729 user_id=75] 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! [/quote]
Besides the asynchronous problem, there might be an issue where the sensors interfere with each other by the Ping from one sensor reaching both.

To combat this, you need to ping one sensor by pulling it high, and read the length. Then, you'll want a short delay between them to allow the ping to die off. Then, you should do the same for the second sensor.

This allows you to get the most accurate readings.

Recommended tutorial: [url=http://www.theengineeringprojects.com/2015/02/interfacing-ultrasonic-sensor-arduino.html]Interface Ultrasonic Sensor with Arduino[/url]
TEP , The Engineering Projects , Tick Correct Answer
Comment Bio
TEP , The Engineering Projects , Tags
PLC
Robot
STM32
Arduino
AI
ESP32
Ladder Logic
PLC Projects
Programming
Communicates STM32
PLC Projects
Communicates PLC
Font Style
Alignment
Indenting and Lists
Insert Media
Insert Items

Want to leave an answer!

Word Count :0 Draft Saved at 12:42 am.