Ultrasonic Sensor with Explorer HAT Pro

Arduino Uno has a 10-bit ( 2 ^ 10 - 1 ) ADC, which will measure 0v to 5v with a number from 0 to 1023.

Explorer HAT has a 12-bit ADC ( 2 ^ 12 - 1 ), which will measure 0v to 5v with a number from 0 to 4095 ( but this is represented as a decimal in Python as it roughly maps to voltage )

So if 5v is 4095, that’s one millivolt granularity, approximately. ( it’s actually 1.221, millivolts granularity ).

Arduino has a granularity of about 5 millivolts ( well 4.8 and change ).

If 1 inch = Arduino reading / 2 then that would suggest 10mv per inch of resolution on the sensor. Although dividing by 2 is a very rough way to convert the Arduino ADC reading to inches that works around Arduino’s slow decimal handling.

To get inches out of Explorer HAT Pro that means you need to divide the output by about 8.19. Since Explorer HAT already divides it by 1000, you’ll need to do this:

So try:

import explorerhat as eh
import time

while True:
    sensor = eh.analog.one.read()
    inches = sensor / 0.00819
    print(inches)
    time.sleep(0.1)

Assuming your sensor isn’t clamped to a 10mv step, Explorer HAT Pro should give you a resolution of a tenth of an inch, whereas the Arduino can only tell you down to half an inch.

TLDR: inches = sensor / 0.00819