Differences between revisions 14 and 15
Revision 14 as of 2011-09-17 17:24:32
Size: 2980
Editor: CarlNobile
Comment:
Revision 15 as of 2011-09-17 17:25:01
Size: 2979
Editor: CarlNobile
Comment:
Deletions are marked like this. Additions are marked like this.
Line 24: Line 24:
'''Notes: The latest version supports the changing the ''cm'' and ''in'' divisor. Changing these divisors will make the distance more accurate between different distances from the sensor. The standard divisor 29 for ''cm'' and 74 for ''in'' seem to work well only at the maximum range of the sensors, 15 feet. Where the current default of ''27.61837989429403516341'' for ''cm'' and ''70.15068493150684931507'' for ''in'' work better at the ''46''/''18'' ''cm''/''in'' distances.''' '''NOTE: The latest version supports the changing the ''cm'' and ''in'' divisor. Changing these divisors will make the distance more accurate between different distances from the sensor. The standard divisor 29 for ''cm'' and 74 for ''in'' seem to work well only at the maximum range of the sensors, 15 feet. Where the current default of ''27.61837989429403516341'' for ''cm'' and ''70.15068493150684931507'' for ''in'' work better at the ''46''/''18'' ''cm''/''in'' distances.'''

HC-SR04 Ultrasonic Sensor Library

This library can be used to read data from the HC-SR04 ultrasonic sensor.

Features

There are five methods in the Ultrasonic class.

  1. Ultrasonic::CM and Ultrasonic::IN are static const class member objects on the Ultrasonic class.

  2. long timing() This method reads data from the sensor. The return value is used for the microsec argument to the next method described below.

  3. long convert(long microsec, int metric) This method converts the microsecond output of timing() passed to microsec to either centimeters or inches. The metric argument can be either of the two member object discribed in 1 above.

  4. void setDivisor(float value, int metric) This method permits the changing of the cm and in divisor so the accuracy of the sensor can be adjusted for distance.

  5. bool sampleCreate(size_t size, ...) This method sets up the buffer(s) needed to derive the standard deviation. The size argument is the number of buffers that you will need. For each buffer, you need to pass an additional argument indication the length of that buffer. ex. bool success = sampleCreate(3, 10, 15, 8) This indicates that there will be three buffers each with lengths of 10, 15, 8 respectively. You should check the return value for true before proceeding with calling the two following methods.

  6. void sampleClear() This method resets all the buffers to zero.

  7. float unbiasedStdDev(long msec, size_t bufNum) This method generates the standard deviation. The msec argument can be the return value of either timing() or convert(). The bufNum argument is the ordinal number of the buffer meaning 0 - n. If you have defined three buffers the numbers would be 0 - 2.

Divisor Chart

TO-DO

Download

NOTE: The latest version supports the changing the cm and in divisor. Changing these divisors will make the distance more accurate between different distances from the sensor. The standard divisor 29 for cm and 74 for in seem to work well only at the maximum range of the sensors, 15 feet. Where the current default of 27.61837989429403516341 for cm and 70.15068493150684931507 for in work better at the 46/18 cm/in distances.

SVN Repository This is off site.

Download Tarball

Download ZIP

WARNING: If you downloaded any of these packages before 1:00 PM EST on Sep 17, 2011 there was a very big bug in the UltrasonicDemo.pde. Please download the latest package.

HCSR04Ultrasonic (last edited 2013-03-23 22:17:06 by CarlNobile)