Project Sensor
Ultrasonic Module HC-SR04 Distance Sensor
![]()
Data from amazon.com
Detection Value Angle <15° Range 2cm ~ 500cm Resolution 0.3 cm Introduction
The sensor is used to locate objects in the grid to be mapped. The purpose of the calculation is to determine which cells contain objects. (Big objects could be in several cells.)Because the sensor has a detection angle of < 15°, the distance to objects adds uncertainty as to which cell(s) are occupied and which ones are not. For Example, in the diagram it is uncertain which cell is actually occupied.
![]()
Scanning
Scans are done by rotating the sensor (1° at a time) keeping track of the number of times a cell appears to contain an object. Cell with low detection counts are probably empty.
The scan should begin and end completely outside of the grid.
![]()
Note: The size of the grid cells and the sensor-to-object distance determinates how many false positives are detected. The best values for eliminating false positives can be determined by experimentation.
Which Cells Are Occupied?
Once an object is detected, you must determine which cell(s) the object might be in.
The sensor angle and the distance to the object are known. They can be used to determine which cell(s) are occupied.
I have chosen to use a simplification. Every time I move the sensor (1°) I use the sensor angle and distance to calculate which cell (if any) is occupied. I then modify the sensor angle ± 7° and calculate again to determine if any other cells appears to be occupied. If a cell is appears to be occupied, I increment its occupied count by one (1).
After scanning from one side of the grid to be mapped to the other, I see which cell(s) have the largest occupied count. These are probably occupied (contain an object). Lower counts are probably not occupied. For example:
![]()
![]()
![]()
![]()
I have chosen to start by changing the sensor angle ± 7°. Experimentation can be used to determine the optimal ± values. For example, using ± 3° and ± 7°.
Estimated Detection Angle Spread
7° 5 ft 10 ft 15 ft 0.6 ft 1.2 ft 1.8 ft
15° 5 ft 10 ft 15 ft 1.2 ft 2.4 ft 3.6 ft sine of 7° = 0.1218693434
sine of 15° = 0.2588190451