From be46611f57592cceff526a8e7bc990454a5e97f1 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 19 Mar 2021 10:44:47 +0100 Subject: [PATCH] Increase SR04 max sensor detection distance Increase SR04 max sensor detection distance to 500 (#11372) --- tasmota/my_user_config.h | 1 + tasmota/xsns_22_sr04.ino | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 3943ab4db..2df867689 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -673,6 +673,7 @@ #define STARTING_OFFSET 30 // Turn on NovaSDS XX-seconds before tele_period is reached //#define USE_HPMA // Add support for Honeywell HPMA115S0 particle concentration sensor (+1k4) //#define USE_SR04 // Add support for HC-SR04 ultrasonic devices (+1k code) + #define SR04_MAX_SENSOR_DISTANCE 500 // Set sensor max detection distance //#define USE_DYP // Add support for DYP ME-007 ultrasonic distance sensor, serial port version (+0k5 code) #define USE_SERIAL_BRIDGE // Add support for software Serial Bridge (+0k8 code) //#define USE_TCP_BRIDGE // Add support for Serial to TCP bridge (+1.3k code) diff --git a/tasmota/xsns_22_sr04.ino b/tasmota/xsns_22_sr04.ino index f2659f294..29876dce4 100644 --- a/tasmota/xsns_22_sr04.ino +++ b/tasmota/xsns_22_sr04.ino @@ -29,7 +29,11 @@ * - https://www.dfrobot.com/wiki/index.php/Weather-proof_Ultrasonic_Sensor_SKU_:_SEN0207 \*********************************************************************************************/ -#define XSNS_22 22 +#define XSNS_22 22 + +#ifndef SR04_MAX_SENSOR_DISTANCE +#define SR04_MAX_SENSOR_DISTANCE 500 +#endif uint8_t sr04_type = 1; real64_t distance; @@ -64,7 +68,7 @@ uint8_t Sr04TModeDetect(void) if (-1 == sr04_trig_pin) { sr04_trig_pin = Pin(GPIO_SR04_ECHO); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only } - sonar = new NewPing(sr04_trig_pin, sr04_echo_pin, 300); + sonar = new NewPing(sr04_trig_pin, sr04_echo_pin, SR04_MAX_SENSOR_DISTANCE); } else { if (sonar_serial->hardwareSerial()) { ClaimSerial();