raw-read

Example of the component phlangone/hc_sr04 v2.0.0
# Raw Pulse Example

This example shows how to read the raw HC-SR04 echo pulse width in microseconds using:

```c
hc_sr04_read_pulse_us()
```

This is useful when you want to apply your own conversion, filtering, calibration, or temperature compensation.

---

## Hardware

Default GPIOs used by this example:

| Signal | GPIO |
|---|---|
| TRIG | GPIO4 |
| ECHO | GPIO5 |

The HC-SR04 ECHO pin usually outputs 5 V. ESP32 GPIOs are not 5 V tolerant, so use a voltage divider or level shifter.

---

## Build and Flash

From this example directory:

```bash
idf.py set-target esp32
idf.py build flash monitor
```

---

## Expected Output

```text
I (1234) raw_pulse: pulse: 1166 us, distance: 19.99 cm
I (2234) raw_pulse: pulse: 1170 us, distance: 20.07 cm
I (3234) raw_pulse: pulse: 1168 us, distance: 20.03 cm
```

---

## Notes

The distance shown in this example is calculated manually from the raw pulse:

```c
distance_cm = pulse_us * HC_SR04_DEFAULT_SOUND_SPEED_CM_PER_US / 2.0f;
```

Use this example if you need access to the raw timing value instead of only the final distance.

To create a project from this example, run:

idf.py create-project-from-example "phlangone/hc_sr04=2.0.0:raw-read"

or download archive (~2.03 KB)