us_range - wolfen351/public-micropython-iot-platform GitHub Wiki
Overview
The USRangeSensor
module is designed to interface with an ultrasonic range sensor (HC-SR04) to measure distances. It provides telemetry data, such as the average distance measured over a configurable number of readings, and integrates with the MicroPython framework.
Features
- Measures distance using the HC-SR04 ultrasonic sensor.
- Calculates and provides the average distance over a configurable number of readings.
- Filters out invalid or out-of-range readings.
- Provides telemetry data for integration with other systems.
- Configurable trigger and echo pins.
UI
The module includes a simple UI in the index.html
file:
- Displays the average distance measured in centimeters (
averagecm
).
Hardware / Pinout
The module uses the HC-SR04 ultrasonic sensor, which requires:
- Trigger Pin: Configurable via
basicSettings["usrange"]["triggerPinNumber"]
. - Echo Pin: Configurable via
basicSettings["usrange"]["echoPinNumber"]
.
Ensure the echo pin is protected with a 1k resistor to avoid damage to the microcontroller.
Configuration
The following settings can be configured in the basicSettings
dictionary:
triggerPinNumber
: The GPIO pin used to send the trigger pulse.echoPinNumber
: The GPIO pin used to receive the echo signal.average_over
: The number of readings used to calculate the average distance.
Telemetry Provided
The module provides the following telemetry data:
averagecm
: The average distance measured in centimeters, rounded to the nearest integer.
Telemetry is only sent if:
- A valid object is detected within the last 5 seconds.
- At least 5 valid readings are available.
Telemetry Consumed
This module does not consume any telemetry data.
Commands Provided
This module does not provide any commands.
Commands Consumed
This module does not consume any commands.