{"id":8445,"date":"2020-08-28T12:43:07","date_gmt":"2020-08-28T16:43:07","guid":{"rendered":"https:\/\/itp.nyu.edu\/physcomp\/?page_id=8445"},"modified":"2022-02-12T10:53:18","modified_gmt":"2022-02-12T15:53:18","slug":"distance-sensors-the-basics","status":"publish","type":"page","link":"https:\/\/itp.nyu.edu\/physcomp\/distance-sensors-the-basics\/","title":{"rendered":"Distance Sensors: The Basics"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p><strong>Distance sensors<\/strong> can be used for any number of applications including range finding, user detection, and obstacle avoidance. Distance sensors are increasingly commonplace in automobiles to facilitate parking and provide enhanced situational awareness. They are used in smartphones to prevent unintended touchscreen activation when holding the device to your ear, and they are integral to touch free paper towel dispensers. Any camera with autofocus relies on a distance sensor. Whether stationary or in motion, distance sensors take readings using one of three methods: signal strength (how diminished is the emitted signal when reflected off a target); triangulation (distance as a function of the angle at which the emitted signal is reflected off the target); or time of flight (the time it takes for a signal to be emitted, reflected off the target, and received). In this lesson, you\u2019ll learn a few principles of working with these sensors, and see some examples.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Youll_Need_to_Know\"><\/span>What You\u2019ll Need to Know<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>To get the most out of this page, it helps to be  familiar with the following concepts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/microcontrollers__trashed\/microcontrollers-the-basics\/\">What is a microcontroller<\/a><\/li><li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/programming__trashed\/programming-terms-and-programming-environments\/\">Beginning programming terms<\/a><\/li><li><a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/electronics\/electricity-the-basics\/\">The basics of electricity<\/a><\/li><li>The basics of serial communication, both <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/serial-communication__trashed\/serial-communication-the-basics\/\">asynchronous<\/a> and <a href=\"https:\/\/itp.nyu.edu\/physcomp\/lessons\/serial-communication__trashed\/synchronous-serial-communication-the-basics\/\">synchronous<\/a><\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Distance_Presence_and_Field_of_View\"><\/span>Distance, Presence, and Field of View<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>It&#8217;s important to understand what distance sensors can do, and what they can&#8217;t do. Two common uses for distances sensor are measuring distance, or how far away from the sensor a person or object is, and detecting presence, or whether there is a person in front of the sensor at all. Many distance sensors use the term proximity to refer to presence as well. A third use that many people often want from these sensors is to detect attention. Distance and presence or proximity are easy to sense. Attention is a more complex problem, not solved by distance sensors alone. To know whether a sensor can do the job at all, you should also know about where it can sense objects or people. The terms Field of View or Angle of View are often used to describe this in technical documents.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Measuring_Distance_vs_Detecting_Presence\"><\/span>Measuring Distance vs Detecting Presence<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u201cMost sensors that read the distance from a target send out some form of energy (light, magnetism, or sound). They measure the amount of energy that reflects off the target and compare it with the energy that went out. Then they convert the difference into an electrical voltage or digital signal that you can read on a microcontroller&#8230; This principle is common to many different sensors and across many scales. On a small scale, domestic robots such as Roombas emit an infrared light&nbsp; and wait for the reflected IR light from an obstacle to navigate a room. On a large scale, airplane radar systems operate by sending out a radio signal and measuring the time it takes for the signal to bounce back from a target&#8230;.<\/p>\n\n\n\n<p>\u201cOne common use for distance sensors is to track a person moving in front of an object in order to trigger the object to action when the person gets close enough. This can be very effective, but keep in mind that being present and paying attention are not the same thing, as any parent or teacher can confirm. Imagine that you want to sense when a person is looking at your painting so that you can make the painting respond in some way. You could put a ranging sensor in front of the painting and look for a person to get close enough, but this sensor alone won\u2019t tell you whether she\u2019s got her back to the painting or not. Sensing attention is a more complex problem.\u201d&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>From <em><a href=\"https:\/\/bobcat.library.nyu.edu\/permalink\/f\/ci13eu\/nyu_aleph000042374\">Physical Computing<\/a><\/em><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Field_of_View\"><\/span>Field of View<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You\u2019ll often see one of two terms referring to a distance sensor\u2019s capabilities: Angle of View or Field of View. While the term &#8220;Angle of View&#8221; is more accurate, you&#8217;ll most often see &#8220;Field of View&#8221; in documentation for these sensors. <strong>Angle of View<\/strong> describes the shape of the cone projected from the sensor within which a signal is either emitted or received and its value is measured in degrees. True <strong>Field of View<\/strong> describes the plane perpendicular to the sensor at any given distance that is bounded by the Angle of View. Note that a sensor\u2019s emitter and receiver may have different Angles of View but they are designed to overlap to the greatest extent possible. Figure 1 illustrates the relationship between angle of view and field of view. <\/p>\n\n\n\n<p>Figure 2 shows a typical distance sensor&#8217;s two main elements, the emitter and the receiver, showing the the angle of transmission from the transmitter and angle of view from the receiver. They sit beside each other on the device, pointing the same direction.   <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/xzdCTH7gf4Pz2nRcpg6SwkvtzqAuZLvd94fZgpuRJQjR0o-bu3ryy-n-SqxIFyGcQbLJIqmdyva7Lsx8h8K82lqR94OluV-UmusQmTsZIN9xF6hNYKot6EzNQ6Pqq3ZvYUxW4MSN\" alt=\"Angle of view and field of view illustrated.\"\/><figcaption>Figure 1. Angle of view and field of view illustrated, as described above. <a href=\"https:\/\/shuttermuse.com\/angle-of-view-vs-field-of-view-fov-aov\/\">Image from Shutter Muse<\/a><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"592\" height=\"526\" src=\"https:\/\/itp.nyu.edu\/physcomp\/wp-content\/uploads\/VL53L0x_drawing.png\" alt=\"Drawing of ST's Vl53L0X sensor.\" class=\"wp-image-8461\"\/><figcaption>Figure 2: drawing of ST&#8217;s Vl53L0X sensor. <a href=\"https:\/\/www.st.com\/resource\/en\/datasheet\/vl53l0x.pdf\">Image from ST\u2019s VL53L0X Data Sheet<\/a><\/figcaption><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Features_of_a_Distance_Sensor\"><\/span>Features of a Distance Sensor<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>Whether you\u2019re dealing with an IR proximity sensor, LiDAR distance sensor, or time of flight sensor, there are a few features you\u2019ll need to consider:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Range<\/strong> \u2013 Distance sensors come with different minimum and maximum ranges.<\/li><li><strong>Resolution<\/strong> \u2013 How granular the units of measurement. Not to be confused with a sensor\u2019s accuracy.<\/li><li><strong>Field of View<\/strong> \u2013 More accurately described as Angle of View when measured in degrees, the Field of View describes the area in which a target will trigger a reading at a given distance from the sensor.<\/li><li><strong>Susceptivity to ambient light conditions<\/strong> \u2013 With the exception of ultrasonic sensors, the presence of ambient light will affect a distance sensor\u2019s performance. Direct light is more disruptive than indirect, outdoor light more so than indoor, and incandescent light sources more so than artificial.<\/li><li>Some <strong>target properties<\/strong> will affect the sensor&#8217;s response. For example, large faceted shapes or concave shapes (like the inside of a bowl, or a hat) might not reflect the beam back to the sensor well. Other factors which could affect the response include:&nbsp;<ul><li>size<\/li><li>orientation (wrt the sensor)<\/li><li>color<\/li><li>transparency<\/li><li>reflectance<\/li><li>texture<\/li><\/ul><\/li><li><strong>Electrical Characteristics<\/strong> \u2013 As with any electronic sensor, you should pay attention to current consumption and make sure the rated voltage of your distance sensor is compatible with your microprocessor.<\/li><li><strong>Interface<\/strong> \u2013 Distance sensors come with a variety of interfaces. Some provide a changing analog voltage based on range. Others will provide a UART asynchronous or an I2C synchronous serial interface. Ultrasonic distance sensors will provide a changing pulse width that corresponds with the changing properties of the sensor. Nowadays, most light-based distance sensors are I2C.<\/li><li><strong>Extra Features <\/strong>\u2013 in addition to the basic physical properties, some distance sensors will have additional features, like the ability to measure ambient light, rudimentary gesture detection, or sophisticated control features like the ability to set angle of view or specific regions of interest (ROI).<\/li><\/ul>\n\n\n\n<p>For more on choosing a distance sensor, <a href=\"https:\/\/www.digikey.com\/en\/articles\/fundamentals-distance-measurement-gesture-recognition-tof-sensors#:~:text=Infrared%20(IR)%20LEDs%20have%20also,proximity%20detection%20and%20distance%20measurements.&amp;text=Another%20way%20to%20measure%20an,and%20return%20to%20the%20sensor.\">Digi-Key has a decent introductory guide<\/a> and <a href=\"https:\/\/www.sparkfun.com\/distance_sensor_comparison_guide\">SparkFun has a well organized comparison guide<\/a>.<\/p>\n\n\n\n<p>Most vendors of sensor modules do not actually make the sensors themselves, they just put them on a breakout board along with the reference circuit, for convenience. While you might buy your distance sensor from <a href=\"https:\/\/www.sparkfun.com\/categories\/84\">Sparkfun<\/a>, <a href=\"https:\/\/www.adafruit.com\/category\/57\">Adafruit<\/a>, <a href=\"https:\/\/www.seeedstudio.com\/proximity-c-910.html\">Seeed Studio<\/a>, or <a href=\"https:\/\/www.pololu.com\/category\/189\/proximity-sensors-and-range-finders\">Pololu<\/a>, for example, the chances are the actual sensor is manufactured by another company like <a href=\"https:\/\/ams.com\/proximity\">AMS<\/a>, <a href=\"http:\/\/global.sharp\/products\/device\/lineup\/selection\/opto\/haca\/diagram.html\">Sharp<\/a>, <a href=\"https:\/\/www.st.com\/en\/imaging-and-photonics-solutions\/proximity-sensors.html\">ST Microelectronics<\/a>, or <a href=\"https:\/\/www.vishay.com\/\">Vishay<\/a>. When you shop for a sensor module, check out the manufacturer\u2019s datasheet in addition to the vendor\u2019s tech specs. It\u2019s also worth doing a comparison search with the sensor part number on <a href=\"https:\/\/octopart.com\">Octopart.com <\/a>to see who else might make a breakout board.&nbsp;<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Ultrasonic_Distance_Sensors\"><\/span>Ultrasonic Distance Sensors<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>Ultrasonic distance sensors use a transducer to emit a pulse of ultrasound at 40 MHz measuring the time it takes for the pulse to bounce off the target and return to the sensor and calculating distance based on the speed of sound. Although it\u2019s unusual to see them described as such, technically they are a sonic time-of-flight sensor. Ultrasonic distance sensors are immune to ambient lighting conditions and target transparency however because sound transmission is influenced by the physical properties of air, accuracy is affected by ambient sound, temperature, and humidity. A \u2018soft\u2019 sound absorbing target with a surface covered by cloth will impact accuracy, as will a target with an irregular surface.<\/p>\n\n\n\n<p>HC-SR04 distance sensors are a staple of many starter kits built around the Arduino Uno, which means they are not plug-and-play compatible with 3.3V Arduino boards like the Nano 33 IoT.  It\u2019s simple enough to incorporate a voltage divider into your circuit, however, and if you\u2019re feeling adventurous, the HC-SR04 can be permanently <a href=\"https:\/\/www.instructables.com\/id\/Modify-Ultrasonic-Sensors-for-3-Volts-Logic-prepar\/\">modified for use with either 3.3V or 5V logic<\/a>.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.sparkfun.com\/products\/15569\">SparkFun\u2019s Ultrasonic Distance Sensor<\/a> (also their <a href=\"https:\/\/www.sparkfun.com\/products\/15171\">Zio Ultrasonic Distance Sensor<\/a> Qwiic version), and <a href=\"https:\/\/www.adafruit.com\/product\/3942\">Adafruit\u2019s Ultrasonic Sonar Distance Sensor<\/a> are variants of the HC-SR04. They are inexpensive and ubiquitous.&nbsp; Alternatively, <a href=\"https:\/\/www.adafruit.com\/product\/4007\">Adafruit\u2019s RCWL-1601 Ultrasonic Distance Sensor<\/a> and <a href=\"https:\/\/www.seeedstudio.com\/Grove-Ultrasonic-Distance-Sensor.html\">Seeed\u2019s Grove &#8211; Ultrasonic Distance Sensor<\/a> are more flexible, designed to work with either 3.3V or 5V logic out of the box, and comparably priced<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Infrared_LED_Proximity_Sensors\"><\/span>Infrared LED Proximity Sensors<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>The simplest approach to measuring distance using infrared light is to measure the amount of emitted IR light that bounces off a target and reflects back to the sensor. The ranges are relatively small \u2014 between 0 and 20cm \u2014 and the language used is \u2018proximity\u2019 rather than \u2018distance\u2019.<\/p>\n\n\n\n<p>Measuring proximity is often one capability of sensors that also measure other aspects of light, such as the <a href=\"https:\/\/www.adafruit.com\/product\/4161\">Adafruit VCNL4040 Proximity and Lux Sensor<\/a> and the <a href=\"https:\/\/www.sparkfun.com\/products\/15177\">SparkFun Proximity Sensor Breakout &#8211; 20cm, VCNL4040 (Qwiic)<\/a> which measure ambient light levels. Color and gesture sensors based on the Avago APDS-9960 also provide proximity readings, including the <a href=\"https:\/\/www.adafruit.com\/product\/3595\">Adafruit APDS9960 Proximity, Light, RGB, and Gesture Sensor<\/a> and the <a href=\"https:\/\/www.sparkfun.com\/products\/12787\">SparkFun RGB and Gesture Sensor &#8211; APDS-9960<\/a>. A <a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-serial-communication\/i2c-communication-with-a-color-gesture-and-proximity-sensor\/\">lab exercise on the APDS-9960<\/a> can be found on this site. <\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Infrared_LED_Time-of-Flight_Sensors\"><\/span>Infrared LED Time-of-Flight Sensors<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>Some optical time-of-flight distance sensors are based on IR LED emitters. They can be pricey. The Benewake TFmini sold by <a href=\"https:\/\/www.adafruit.com\/product\/3978\">Adafruit<\/a>, <a href=\"https:\/\/www.sparkfun.com\/products\/14786\">SparkFun<\/a> and <a href=\"https:\/\/www.seeedstudio.com\/Seeedstudio-Grove-TF-Mini-LiDAR.html\">Seeed<\/a> is capable of ranging distances up to 12 meters and while it requires 5V to operate, it uses 3.3V logic to communicate. Unlike other distance sensors that use I2C, the TFmini uses the UART protocol for asynchronous serial communication.<\/p>\n\n\n\n<p>The Garmin LIDAR-Lite V4 \u2014 available at <a href=\"https:\/\/www.adafruit.com\/product\/4441\">Adafruit<\/a> and <a href=\"https:\/\/www.sparkfun.com\/products\/15776\">SparkFun<\/a> (also available <a href=\"https:\/\/www.sparkfun.com\/products\/15777\">with Qwiic connector<\/a>) \u2014 has a 10 meter range and is more expensive than the Benewake sensor but comes with some additional features including I2C serial protocol and wireless control using Garmin\u2019s open <a href=\"https:\/\/www.thisisant.com\/\">ANT Protocol<\/a>, a low power wireless protocol alternative to BLE.<\/p>\n\n\n\n<p>Note that both Benewake and Garmin take creative license and, while not technically accurate, nonetheless market the two products above as \u2018LiDAR\u2019 distance sensors.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Infrared_LED_Triangulation_Sensors\"><\/span>Infrared LED Triangulation Sensors<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>Another method for calculating distance using infrared light is triangulation. A pulse of IR light is emitted and range is determined based on the angle of reflection. Most of the maker \/ hobbyist sensors of this category are manufactured by <a href=\"http:\/\/global.sharp\/products\/device\/lineup\/selection\/opto\/haca\/diagram.html\">Sharp<\/a>. They come in both analog and digital output variations but because most of them require 5V, they can be used with the Uno but not the Nano 33 IoT. The Sharp GP2Y0A60SZLF is an exception, operating at 3V. <a href=\"https:\/\/www.pololu.com\/product\/2476\">Pololu makes a breadboard-friendly module<\/a> with this sensor.<\/p>\n\n\n\n<p>Maximum distances for analog output sensors range from 5cm to 80cm depending on the model. For sensors with digital output, maximum distances range from 1.5cm to 550cm.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"LiDAR_Distance_Sensors\"><\/span>LiDAR Distance Sensors<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>LiDAR distance ranging sensors like the Garmin LIDAR-Lite v3 available from <a href=\"https:\/\/www.adafruit.com\/product\/4058\">Adafruit<\/a> and <a href=\"https:\/\/www.sparkfun.com\/products\/14032\">SparkFun<\/a> use time-of-flight to calculate distance as a function of the time it takes a pulse of emitted laser light to reflect off a target and return to the sensor. The Garmin LIDAR-Lite v3 is capable of very rapid readings measuring distances up to 40 meters although at a resolution of centimeters rather than millimeters. Data can be sent to the microprocessor as either a digital signal using I2C or an analog signal using pulse width modulation. Distance sensors of this kind are often used in robotics and autonomous vehicles; they are quite expensive and less likely to be of practical use to PComp projects.<\/p>\n\n\n\n<p>LiDAR is an acronym for light detection and ranging pr laser imaging, detection, and ranging. Note that some distance sensors marketed as LiDAR are actually lensed IR LED time-of-flight sensors and do not actually user lasers. <\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"VCSEL_Vertical_Cavity_Surface_Emitting_Laser_Sensors\"><\/span>VCSEL (Vertical Cavity Surface Emitting Laser) Sensors<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>Another example of optical time-of-flight, these distance sensors combine a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Vertical-cavity_surface-emitting_laser\">vertical cavity surface emitting laser (VCSEL)<\/a> with a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Single-photon_avalanche_diode\">single-photon avalanche diode (SPAD)<\/a> array to measure the time it takes a photon of light to travel from the sensor, to the target, and back. Distance is then calculated using the speed of light, which is a constant. VCSEL distance sensors provide true laser-based ranging with high resolution (millimeters rather than centimeters) in a very small form factor. ST\u2019s <a href=\"https:\/\/www.st.com\/en\/imaging-and-photonics-solutions\/vl53l0x.html\">VL53L0X<\/a> and ST\u2019s <a href=\"https:\/\/www.st.com\/en\/imaging-and-photonics-solutions\/vl53l1x.html\">VL53L1X<\/a> are VCSEL sensors. <meta charset=\"utf-8\">A <a href=\"https:\/\/itp.nyu.edu\/physcomp\/i2c-communication-with-a-time-of-flight-distance-sensor\/\" data-type=\"page\" data-id=\"8941\">lab exercise on the VL53L0x sensor<\/a> can be found on this site. <\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"RADAR\"><\/span>RADAR<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p><strong>RADAR<\/strong> is an acronym for Radio Detection and Ranging.  Radar is a technology that dates back to the 1940&#8217;s. Despite being a mature technology, though, it is still not as inexpensive or as ubiquitous as  other forms of distance ranging. Seeed Studio makes a Doppler Radar module, however, for those interested in radar: <a href=\"https:\/\/wiki.seeedstudio.com\/Grove-Doppler-Radar\/\">Seeed Grove Doppler Radar<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_To_Look_For_in_a_Distance_Sensor_Library\"><\/span>What To Look For in a Distance Sensor Library<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>Different vendors will often write their own libraries for the distance sensors they sell. When you\u2019re looking at a given vendor\u2019s product, take a look at the properties of the sensor in the vendor\u2019s datasheet, and the list of public functions in the library\u2019s API. Does the library give you the functions of the sensor that you need? If the sensor supports multiple sensing ranges, does the library give you access to setting and getting the range? Is it well-documented, and well-commented? Are there simple, clear, well-commented examples?<\/p>\n\n\n\n<p>For example, both <a href=\"https:\/\/www.sparkfun.com\/products\/14722\">SparkFun<\/a> and <a href=\"https:\/\/www.pololu.com\/product\/3415\">Pololu<\/a> make breakout boards for the <a href=\"https:\/\/www.st.com\/en\/imaging-and-photonics-solutions\/vl53l1x.html\">VL53L1X Time-of-Flight sensor<\/a>. The VL53L1X is typical of a next gen distance sensor; it\u2019s got an I2C interface, operates at 2.8V, and offers a large range from 4cm to 400cm. The <a href=\"https:\/\/learn.sparkfun.com\/tutorials\/qwiic-distance-sensor-vl53l1x-hookup-guide\/\">SparkFun hookup guide<\/a> is more accessible than the <a href=\"https:\/\/www.pololu.com\/product\/3415\">Using the VL53L1X section on Pololu\u2019s product page<\/a> but neither provides a summary of all the functions in their libraries. To see that, you need to look at the header files for each library.<\/p>\n\n\n\n<p>Pololu offers two different libraries for the VL53L1X. The <a href=\"https:\/\/github.com\/pololu\/vl53l1x-arduino\">Pololu VL53L1X library<\/a> is streamlined to use less resources but doesn\u2019t surface some of the more technical features of the sensor. On the other hand, the <a href=\"https:\/\/github.com\/pololu\/vl53l1x-st-api-arduino\">Pololu ST VL53L1X API library<\/a> is a largely literal implementation of <a href=\"https:\/\/www.st.com\/en\/embedded-software\/stsw-img007.html\">ST\u2019s VL53L1X Full API<\/a>, providing more advanced functionality at the expense of a larger memory footprint and a more opaque code base divided into multiple header files geared less toward the student or hobbyist than someone with an electrical engineering background.<\/p>\n\n\n\n<p>By comparison, <a href=\"https:\/\/github.com\/sparkfun\/SparkFun_VL53L1X_Arduino_Library\/blob\/master\/src\/SparkFun_VL53L1X.h\">SparkFun\u2019s header file<\/a> is less verbose and significantly shorter than either of the Pololu offerings with clean, succinct, in-line comments that make it accessible and easy to navigate. The public functions start around line 35. Both are functional libraries, though, and you should choose based on the features you want and how easy you find each to use.<\/p>\n\n\n\n<p>You can find further notes on how to pick a library in <a href=\"https:\/\/itp.nyu.edu\/physcomp\/labs\/labs-serial-communication\/i2c-communication-with-a-color-gesture-and-proximity-sensor\/#How_To_Pick_a_Library\">this lab exercise<\/a> for the APDS-9960 Color, Light, and Gesture sensor.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>There are dozens of distance sensors on the market, and as they become more ubiquitous in electronic devices, they continue to get smaller, cheaper, more sophisticated and more power-efficient. The principles laid out here should give you a basis for assessing new sensors as needed.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Additional_Links\"><\/span>Additional Links<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/itp.nyu.edu\/classes\/intangible-interaction\/\">Intangible Interactions<\/a> course &#8211; including a <a href=\"https:\/\/itp.nyu.edu\/classes\/intangible-interaction\/distance-sensor\/\">guide to choosing a distance sensor<\/a><\/li><li><a href=\"https:\/\/www.digikey.com\/en\/articles\/fundamentals-distance-measurement-gesture-recognition-tof-sensors\">Digi-Key \u00bb Fundamentals of Distance Measurement and Gesture Recognition Using ToF Sensors<\/a><\/li><li><a href=\"https:\/\/www.seeedstudio.com\/blog\/2019\/12\/23\/distance-sensors-types-and-selection-guide\/\">Seeed Studio Blog \u00bb Types of Distance Sensor and how to select one?<\/a><\/li><li><a href=\"https:\/\/www.sparkfun.com\/distance_sensing\">SparkFun \u00bb Distance Sensing Overview<\/a><\/li><li><a href=\"https:\/\/www.sparkfun.com\/distance_sensor_comparison_guide\">SparkFun \u00bb Distance Sensor COmparison Guide<\/a><\/li><li><a href=\"https:\/\/www.terabee.com\/choosing-right-distance-sensor-your-application\/\">Terabee \u00bb Choosing the Right Distance Sensor for Your Application<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Distance sensors can be used for any number of applications including range finding, user detection, and obstacle avoidance. Distance sensors are increasingly commonplace in automobiles to facilitate parking and provide enhanced situational awareness. They are used in smartphones to prevent unintended touchscreen activation when holding the device to your ear, and they are integral &hellip; <a href=\"https:\/\/itp.nyu.edu\/physcomp\/distance-sensors-the-basics\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Distance Sensors: The Basics&#8221;<\/span><\/a><\/p>\n","protected":false},"author":62,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[5,52,7],"tags":[],"class_list":["post-8445","page","type-page","status-publish","hentry","category-electronics","category-lesson","category-sensors"],"_links":{"self":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/8445"}],"collection":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/users\/62"}],"replies":[{"embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/comments?post=8445"}],"version-history":[{"count":24,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/8445\/revisions"}],"predecessor-version":[{"id":9532,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/pages\/8445\/revisions\/9532"}],"wp:attachment":[{"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/media?parent=8445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/categories?post=8445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itp.nyu.edu\/physcomp\/wp-json\/wp\/v2\/tags?post=8445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}