Home/Support/Support Forum/How to read ultrasonic sensor echo pulse

How to read ultrasonic sensor echo pulse

0 votes
I'm trying to use an ultrasonic sensor with the programmable XBee-PRO 900HP. Model is HC-SR04, data sheet is https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf. This sensor is ubiquitous in the Arduino world.

To read the distance from the ultrasonic sensor I send a 10 microsecond pulse on the trigger pin and measure the duration of the return pulse on the echo pin, which is proportional to the measured distance. This code to measure the duration of the echo pulse is trivial on Arduino (e.g., http://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/?ALLSTEPS) using Arduino's pulseIn function, but I can't figure out how to do the same on the XBee.

It seems like I should be using the input capture library to measure the echo pulse duration (is this correct?) but I'm struggling as I can't find working code examples online that demonstrate how to drive an ultrasonic sensor using a programmable XBee.

Basically I want to know how to write the equivalent of Arduino's pulseIn function for the XBee.

Any help much appreciated.

asked Mar 24, 2017 in XBee Programmable Development by jbarham New to the Community (0 points)

Please log in or register to answer this question.

2 Answers

0 votes
See these resources:


answered Mar 24, 2017 by DystopianFerret Veteran of the Digi Community (368 points)
0 votes
Also make sure that you have the proper level shifting occurring between the sensor and the XBee. The XBee's DIO lines will be 1.2V and your sensor is 5V.
answered Mar 24, 2017 by mvut Veteran of the Digi Community (14,288 points)