Answers.Body: <p>The sensor reports two <code>UInt8</code> bytes, one in <a href="https://en.wikipedia.org/wiki/Inch" rel="nofollow noreferrer">inches</a> (i.e. 0 ... 255, but capped at the maximum range of 10&quot;) and one in &quot;inverse fractional inches&quot; (i.e. 1/255 ... 1/1). The actual code is:</p>
  <pre><code>    var inches = Double(bytes[5])
      let invFracInches = bytes[7]
      if invFracInches != 0 {
          inches += 1 / Double(invFracInches)
      }
  </code></pre>
  <p>Your software will be converting inches to mm/cm for metric locales - here in UK it practically reports in integer inches (thus the step is 25.4mm) from its maximum range of 10&quot;, then once below 6&quot; it starts to report 0.5&quot; steps, below 3&quot; it will report 0.33&quot; then 0.25&quot; steps. In principle it should be able at short range to discern quite small steps.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-21T04:02:11.207Z
Answers.Text: Thanks, so it should register from 254mm.  I'll have a second look if I can ever get that distance.
Answers.UserDisplayName: Superman.Lopez
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-20T16:03:08.667Z
Answers.LastActivityDate: 2022-04-20T16:03:08.667Z
Answers.UserDisplayName: Grimxn
Body: <p>While programming our Lego Boost set <em>(using the Lego Boost App on iPad)</em> I noticed that the distance sensor seemed to give inaccurate triggers.  To try to confirm this, I connected the move hub to my computer and used <a href="https://nathankellenicki.github.io/node-poweredup/index.html" rel="nofollow noreferrer"><code>node-poweredup</code></a> to read out the sensor.</p>
  <p>The results surprised me:  the max reading I get <em>(the furthest it registers an object)</em> is 157mm.  Also the steps are rather big, it always goes in steps of 25mm.</p>
  <p>Is this normal range of the distance sensor?  Or is it possible that ours has an issue <em>(I wiped the sensor clean with a dry cotton cloth and reconnected it to the Move Hub)</em>?</p>
  
Tags: <boost><sensor>
Title: Lego Boost distance sensor, what range does it have?
UserDisplayName: Superman.Lopez
ThreadText: # Lego Boost distance sensor, what range does it have?
  
  (Asked by: username_0 on 2019-12-06)
  
  While programming our Lego Boost set *(using the Lego Boost App on iPad)* I noticed that the distance sensor seemed to give inaccurate triggers. To try to confirm this, I connected the move hub to my computer and used [`node-poweredup`](https://nathankellenicki.github.io/node-poweredup/index.html) to read out the sensor.
  
  The results surprised me: the max reading I get *(the furthest it registers an object)* is 157mm. Also the steps are rather big, it always goes in steps of 25mm.
  
  Is this normal range of the distance sensor? Or is it possible that ours has an issue *(I wiped the sensor clean with a dry cotton cloth and reconnected it to the Move Hub)*?
  
  **Tags:** boost, sensor
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-04-20. Score: 1 | Accepted answer
  
  The sensor reports two `UInt8` bytes, one in [inches](https://en.wikipedia.org/wiki/Inch) (i.e. 0 ... 255, but capped at the maximum range of 10") and one in "inverse fractional inches" (i.e. 1/255 ... 1/1). The actual code is:
  
  ```
      var inches = Double(bytes[5])
      let invFracInches = bytes[7]
      if invFracInches != 0 {
          inches += 1 / Double(invFracInches)
      }
  
  ```
  
  Your software will be converting inches to mm/cm for metric locales - here in UK it practically reports in integer inches (thus the step is 25.4mm) from its maximum range of 10", then once below 6" it starts to report 0.5" steps, below 3" it will report 0.33" then 0.25" steps. In principle it should be able at short range to discern quite small steps.
  
  > **Comments:**
  > **username_0**: Thanks, so it should register from 254mm.  I'll have a second look if I can ever get that distance.  
  
  ---
  
  