“Dzhmil” sketch settings (version 1.7)

The settings are constants at the top of the sketch (main.cpp). After changing a value, re-upload the sketch to the controller. Verify every change in real-world tests: reaction-zone and filter parameters directly affect the user's safety.

1. Obstacle reaction zones

ParameterDefaultUnitDescription and effect
CENTER_ALERT_DISTANCE_MM1050mmDistance at which the center sensor starts warning. Higher: earlier warning, but more unnecessary alerts in tight spaces. Lower: less time to react. Keep it above VIBRO_VERY_FAR_BORDER_MM, otherwise the “very far” rhythm is never used.
SIDE_ALERT_DISTANCE_MM900mmSame for the left and right sensors. Decrease it if walls in narrow corridors cause constant alerts.
DIRECTION_GROUP_MARGIN_MM300mmIf several sensors see obstacles within this margin of the nearest one, their motors vibrate together. Higher: several motors vibrate together more often (less precise direction). Lower: only the side of the nearest obstacle vibrates.
ALERT_HYSTERESIS_MM80mmMargin when leaving a zone: the signal stops only when the obstacle has moved beyond the zone border by more than this value. Higher: steadier at the border, but the signal stops later. Lower: the motors may twitch at the zone border.

2. Vibration rhythm by distance

The main cue for the user is the length of the pause: the closer the obstacle, the shorter the pause. The zone borders must decrease: VERY_FAR > FAR > MEDIUM > CLOSE.

ParameterDefaultUnitDescription and effect
VIBRO_VERY_FAR_BORDER_MM850mmBorder between the “very far” zone (beyond this border) and the “far” zone.
VIBRO_FAR_BORDER_MM700mmBorder between the “far” zone and the “medium distance” zone.
VIBRO_MEDIUM_BORDER_MM550mmBorder between the “medium distance” zone and the “close” zone.
VIBRO_CLOSE_BORDER_MM400mmBorder between the “close” zone and the “very close” zone.
PATTERN_VERY_FAR120 / 1200ms (pulse / pause)“Very far” zone: sparse single pulse.
PATTERN_FAR120 / 800ms (pulse / pause)“Far” zone: noticeably more frequent pulses.
PATTERN_MEDIUM140 / 450ms (pulse / pause)“Medium distance” zone.
PATTERN_CLOSE170 / 180ms (pulse / pause)“Close” zone.
PATTERN_VERY_CLOSE300 / 60ms (pulse / pause)“Very close” zone: almost continuous vibration.

3. Sensors and filtering

ParameterDefaultUnitDescription and effect
SENSOR_TIMING_BUDGET_US50000µsDuration of one sensor measurement. Higher: less noise and better performance in sunlight and at long range, but slower updates. Must not exceed SENSOR_CONTINUOUS_PERIOD_MS (50000 µs = 50 ms).
SENSOR_CONTINUOUS_PERIOD_MS70msInterval between measurements. Lower: faster reaction, but more I2C bus load and higher power consumption. Must not be shorter than the measurement time (SENSOR_TIMING_BUDGET_US).
SENSOR_MAX_VALID_DISTANCE_MM5000mmReadings beyond this value are treated as invalid. Normally not changed.
FILTER_WINDOW3pcsNumber of latest measurements in the median filter (odd number: 3 or 5). Higher: more robust against noise, but slower reaction.
FILTER_MIN_SAMPLES2pcsHow many measurements confirm an obstacle. 2 = two in a row (delay ≈ 140 ms). 1 gives the fastest reaction, but a single false measurement can trigger vibration (not recommended). Must not exceed FILTER_WINDOW.
MAX_BAD_READS3pcsHow many invalid measurements in a row are needed before the sensor is considered “empty” (no obstacle). Until then the previous value is kept.
SENSOR_STALL_MS500msIf a sensor delivers no new data for longer than this, it is considered hung and its last value is no longer used.
SENSOR_READ_INTERVAL_MS10msHow often the sensors are checked for new data. Normally not changed.
I2C_CLOCK_HZ100000HzI2C bus speed. 100 kHz is more reliable with long wires; 400 kHz is faster but more sensitive to wiring and interference.

4. Battery monitoring (1S2P)

ParameterDefaultUnitDescription and effect
BATTERY_DIVIDER_R_TOP_KOHM47kΩUpper divider resistor (from battery positive to GPIO34). Must match the installed resistor.
BATTERY_DIVIDER_R_BOTTOM_KOHM100kΩLower divider resistor (from GPIO34 to GND).
BATTERY_CALIBRATION_FACTOR1.00—Calibration factor: multimeter voltage ÷ Serial voltage.
BATTERY_LOW_VOLTAGE3.50V“Low charge” threshold (1 pair of pulses). Voltage of a single Li-ion cell under light load. Must be higher than BATTERY_CRITICAL_VOLTAGE.
BATTERY_CRITICAL_VOLTAGE3.30V“Critical charge” threshold (2 pairs of pulses). Must be higher than BATTERY_CUTOFF_WARNING.
BATTERY_CUTOFF_WARNING3.15V“Very critical charge” threshold (3 pairs of pulses): charge immediately. The TP4056 module protection cuts off the battery only at about 2.4–2.5 V, so the warning is given much earlier.
BATTERY_HYSTERESIS_V0.10VTo return to a better level, the voltage must rise above the threshold by this amount. Prevents warning “flicker” near a threshold.
BATTERY_FILTER_ALPHA0.300–1Voltage smoothing: share of the new measurement. Lower: smoother but slower to react. With measurements every 5 s, 0.30 averages over roughly 15–20 s.
BATTERY_READ_INTERVAL_MS5000msHow often the voltage is measured. A measurement is taken only while the motors are not vibrating.
BATTERY_FIRST_WARNING_DELAY_MS5000msTime after startup (or after the charge level worsens) until the first warning sounds.
LOW_BATTERY_WARNING_INTERVAL_MS60000msRepeat period of the “low charge” warning.
CRITICAL_BATTERY_WARNING_INTERVAL_MS15000msRepeat period of the “critical charge” warning.
VERY_CRITICAL_WARNING_INTERVAL_MS5000msRepeat period of the “very critical charge” warning.
LOW_BATTERY_WARNING_PAIRS
CRITICAL_BATTERY_WARNING_PAIRS
VERY_CRITICAL_BATTERY_WARNING_PAIRS
1 / 2 / 3pairsNumber of pulse pairs for each level: low / critical / very critical.
BATTERY_PAIR_PULSE_ON_MS130msDuration of one pulse within a pair.
BATTERY_PAIR_INNER_OFF_MS110msPause between the two pulses inside a pair.
BATTERY_PAIR_GAP_MS450msPause between pairs.
BATTERY_ADC_SAMPLES16pcsNumber of ADC readings averaged per measurement (with a pause of BATTERY_ADC_SAMPLE_DELAY_MS = 2 ms between them). Higher: less noise, but the program is blocked longer during the measurement (≈ 32 ms).

5. Service signals and diagnostics

ParameterDefaultUnitDescription and effect
MOTOR_SELF_TEST_ON_MS180msVibration time of each motor during the self-test at startup (order: left → center → right).
MOTOR_SELF_TEST_OFF_MS150msPause between motors during the self-test.
SENSOR_ERROR_PULSES9pcsNumber of short pulses on all motors if at least one sensor failed to start at power-up.
SENSOR_ERROR_ON_MS
SENSOR_ERROR_OFF_MS
120 / 120msPulse duration / pause in the sensor error signal.
LOG_ALERT_EVENTStruetrue / falsePrint to Serial the moments when the signal turns on and off for each sensor (useful for finding the cause of false alerts).
LOG_BATTERYtruetrue / falsePrint the battery status to Serial at every measurement.
DISTANCE_PRINT_INTERVAL_MS300msHow often distances are printed to the Serial Monitor.

6. Hardware (pins and addresses)

Change these values only if the wiring has changed.

ParameterDefaultUnitDescription and effect
I2C_SDA21GPIOI2C data line (SDA) of the sensors.
I2C_SCL22GPIOI2C clock line (SCL) of the sensors.
XSHUT_LEFT
XSHUT_CENTER
XSHUT_RIGHT
25 / 26 / 27GPIOShutdown pins of the left, center and right sensors; used to assign unique I2C addresses at startup.
MOTOR_LEFT
MOTOR_CENTER
MOTOR_RIGHT
16 / 17 / 18GPIOControl outputs of the left, center and right vibration motors (to the PWMA/PWMB inputs of the TB6612FNG drivers). At startup the self-test runs left → center → right; check that the physical motors vibrate in this order.
BATTERY_ADC_PIN34GPIOADC input for the battery voltage (midpoint of the divider). Use an ADC1 pin (GPIO32–39).
ADDR_LEFT
ADDR_CENTER
ADDR_RIGHT
0x30 / 0x31 / 0x32I2C addressI2C addresses assigned to the sensors at startup. Change only if they conflict with other I2C devices.
MOTOR_ON
MOTOR_OFF
HIGH / LOWlevelLogic levels that switch a motor on and off. Swap them if the driver works inversely.