Faucet switch position detection method and device, electronic equipment and storage medium
By sampling and calculating the three-axis acceleration data of the faucet using an accelerometer, the problem of high misjudgment rate in the position detection of the electric faucet switch was solved, achieving higher precision position detection and lower production cost.
Patent Information
- Application Number
- CN202511297628.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-11
- Publication Date
- 2025-12-12
AI Technical Summary
Existing electronic faucet switch position detection methods suffer from high false alarm rates, complex manufacturing processes, and high costs, especially when the switch travel is short, which can easily lead to false alarms.
Accelerometers are used to sample and acquire triaxial acceleration data. After calibration and filtering, the displacement data is calculated using the first-order approximate trapezoidal method to determine the position of the faucet switch.
It improves the accuracy of switch position detection, reduces production costs, simplifies the production process, and reduces the false alarm rate.
Smart Images

Figure CN121112979A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent detection technology, and in particular to a method, device, electronic device, and storage medium for detecting the position of a faucet switch. Background Technology
[0002] As an essential piece of equipment for daily production and living, faucets are widely used in kitchens, bathrooms and other places.
[0003] With the development of technology, electronically controlled intelligent faucets are gradually replacing traditional manual faucets. Existing electronically controlled faucets typically use Hall effect sensors and magnets to detect the switch's position; that is, the water temperature is displayed when the switch is pressed and not when it is not pressed. However, this method suffers from problems such as low accuracy in switch position detection, a high false alarm rate, complex manufacturing processes, and high costs. For example, when the switch travel is small (e.g., only 3mm), false alarms are prone to occur. Therefore, there is an urgent need for a new faucet switch position detection method to solve the aforementioned technical problems. Summary of the Invention
[0004] In view of this, the present invention provides a method, apparatus, device and storage medium for detecting the position of a faucet switch, which can solve the problem of high misjudgment rate in the prior art, and improve the accuracy of position detection while reducing production costs.
[0005] According to one aspect of the present invention, an embodiment of the present invention provides a method for detecting the position of a faucet switch, applied to an electronic device, wherein the electronic device communicates with an accelerometer via a preset communication method; the method includes:
[0006] The accelerometer is sampled to obtain triaxial acceleration data at each sampling time; wherein the accelerometer is disposed in the faucet to be tested;
[0007] Displacement data is determined based on the triaxial acceleration data;
[0008] The on / off position of the faucet to be tested is determined based on the displacement data.
[0009] According to another aspect of the present invention, embodiments of the present invention also provide a faucet switch position detection device, applied to an electronic device, wherein the electronic device communicates with an acceleration sensor via a preset communication method; the device includes:
[0010] A sampling module is used to sample the faucet under test based on a calibrated accelerometer to obtain triaxial acceleration data of the faucet under test at each sampling time; wherein the accelerometer is disposed in the faucet under test.
[0011] The displacement determination module is used to determine displacement data based on the triaxial acceleration data and the preset trapezoidal law.
[0012] The state determination module is used to determine the on / off position state of the faucet to be detected based on the displacement data.
[0013] According to another aspect of the present invention, embodiments of the present invention also provide an electronic device, the electronic device comprising:
[0014] At least one processor; and
[0015] A memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program that can be executed by the at least one processor, which enables the at least one processor to perform the faucet switch position detection method according to any embodiment of the present invention.
[0017] According to another aspect of the present invention, embodiments of the present invention also provide a computer-readable storage medium storing computer instructions, the computer instructions being configured to cause a processor to execute and implement the faucet switch position detection method according to any embodiment of the present invention.
[0018] According to another aspect of the present invention, embodiments of the present invention also provide a computer program product, the computer program product including a computer program, which, when executed by a processor, implements the faucet switch position detection method according to any embodiment of the present invention.
[0019] The above-described technical solution of this invention obtains corresponding triaxial acceleration data by sampling an accelerometer. Based on this, displacement data is determined from the triaxial acceleration data. Based on this, the switch position of the faucet to be detected is determined from the displacement data. This solves the problem of easy misjudgment by traditional Hall sensors and magnets, especially when the switch travel is small, the misjudgment rate is high. This improves the accuracy of position detection. Moreover, the use of an accelerometer to replace the detection method of Hall sensors and magnets is cheaper and helps to reduce production costs.
[0020] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 A flowchart illustrating a faucet switch position detection method according to an embodiment of the present invention;
[0023] Figure 2 A flowchart illustrating another method for detecting the position of a faucet switch according to an embodiment of the present invention;
[0024] Figure 3 This is a schematic diagram of a process for detecting the position of a faucet switch according to an embodiment of the present invention;
[0025] Figure 4 This is a schematic diagram of the switch state of a push-button faucet when it is closed and not pressed, according to an embodiment of the present invention.
[0026] Figure 5 This is a schematic diagram of a push-button faucet that dispenses water when pressed, according to an embodiment of the present invention, and is in the open state.
[0027] Figure 6 This is a structural block diagram of a faucet switch position detection device according to an embodiment of the present invention;
[0028] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0029] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0030] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0031] In one embodiment, Figure 1 This is a flowchart of a faucet switch position detection method according to an embodiment of the present invention. This embodiment is applicable to the situation of detecting the switch position of a faucet. The method can be executed by a faucet switch position detection device, which can be implemented in hardware and / or software and can be configured in an electronic device.
[0032] like Figure 1 As shown, this method is applied to an electronic device, which communicates with an acceleration sensor via a preset communication method; wherein, the preset communication method may include, but is not limited to, the serial communication protocol I2C communication method; the electronic device in this embodiment may be a device including an MCU microcontroller unit; specifically, the method includes:
[0033] S110. Sample the accelerometer to obtain triaxial acceleration data for each sampling.
[0034] The triaxial acceleration data can include X-axis acceleration data, Y-axis acceleration data, and Z-axis acceleration data.
[0035] In this embodiment, the accelerometer sensor configured in the faucet under test is continuously sampled to obtain the triaxial acceleration data corresponding to each sampling. In this embodiment, the position of the accelerometer sensor in the faucet under test is not limited. For example, the accelerometer sensor can be configured on the upper, left, or right side of the faucet, depending on the type of faucet; this embodiment does not impose any restrictions.
[0036] In one embodiment, determining the positional relationship between the accelerometer and the faucet to be tested includes: reading initial triaxial acceleration data from the accelerometer before position detection of the faucet; determining the faucet type based on the initial triaxial acceleration data; wherein the faucet type includes: push-button faucet and handle-operated faucet; determining the positional relationship between the accelerometer and the faucet to be tested based on the faucet type; wherein the positional relationship includes: the accelerometer being installed inside the upper part of the faucet to be tested; the accelerometer being installed inside the side of the faucet to be tested.
[0037] In this embodiment, the initial triaxial acceleration data is the triaxial acceleration data of the accelerometer sensor located on the faucet under test when it is stationary before the position detection of the faucet. This triaxial acceleration data in a stationary state can determine whether the faucet is a push-button faucet or a handle-type faucet with left and right switches. Knowing the faucet type, i.e., knowing the positional relationship between the accelerometer sensor and the faucet under test, calibration can begin according to this relationship. For example, X = 0, Y = 0, Z = 4096 indicates gravitational acceleration on the Z-axis; in this case, the circuit board of a push-button faucet is installed horizontally, corresponding to a push-button switch faucet. If X = 0, Y = 4096, Z = 0, it indicates gravitational acceleration on the Y-axis; in this case, the circuit board is installed vertically, corresponding to a handle-type faucet.
[0038] In this embodiment, before detecting the faucet switch position, the accelerometer installed in the faucet needs to be calibrated. The calibration method can be to adjust the offset by programming the register within the accelerometer. Because the accelerometer may introduce errors during production, transportation, or installation before use, these errors can lead to distorted measurement data. For example, if the sensor is not aligned with the "actual measurement axis" during installation (e.g., it should be installed horizontally but is actually tilted at 5°), the measured acceleration will be the "projection of the true acceleration onto the installation axis," not the true value (e.g., a true horizontal acceleration of 1g, after tilting at 5°, the measured value is only cos5°≈0.996g). Therefore, calibration is necessary. In this embodiment, this calibration operation can eliminate 0g offset or bias error, preventing the difference between the measured value and the true 0 value from affecting the calculation results. After calibration, when the user operates the faucet switch, the switch will cause the valve core to open and close. The calibrated accelerometer will sample the faucet under test to obtain the triaxial acceleration data of the faucet under test at each sampling. It can be understood that the calibrated accelerometer will transmit the sampled triaxial acceleration data to the electronic device via I2C communication, so that the electronic device can determine the displacement data of the switch through the sampled triaxial acceleration data, and then calculate the current position of the switch based on the displacement data, thereby determining whether the valve core is currently in the open or closed state.
[0039] In one embodiment, before sampling the accelerometer, the method further includes: calibrating the accelerometer; wherein, the calibration of the accelerometer includes: initializing the parameter values of the accelerometer; wherein, the parameter values include at least: the sampling frequency of the sampled values and the acceleration range measured by the accelerometer.
[0040] Once the positional relationship between the faucet to be tested and the accelerometer is determined, the triaxial acceleration data to be calibrated in a static state is read from the register address of the initialized accelerometer.
[0041] The triaxial acceleration data to be calibrated are performed with binary two's complement to convert them into decimal form to obtain the calibration value after two's complement.
[0042] The offset calibration value is determined based on the two's complement calibration value and written into the offset register of the accelerometer. The offset calibration value is then used to calibrate the triaxial acceleration data to be calibrated, resulting in the calibrated accelerometer.
[0043] The acceleration range measured by the accelerometer can also be called the range setting of the accelerometer, which is the upper and lower limits of the measurement range. For example, the range setting is ±2g, where g is the gravitational acceleration, which indicates that the maximum acceleration range that the sensor can measure and accurately output is from negative 2 gravitational accelerations to positive 2 gravitational accelerations.
[0044] In this embodiment, after the positional relationship between the faucet to be detected and the accelerometer is determined, for example, the accelerometer circuit board is mounted on the faucet push-button switch, the parameter values of the accelerometer are initialized. After the positional relationship between the faucet to be detected and the accelerometer is determined, the triaxial acceleration data to be calibrated in a stationary state (stationary placement) is read from the register address of the initialized accelerometer. This may include reading the X-axis value from the X-axis register address, the Y-axis value from the Y-axis register address, and the Z-axis value from the Z-axis register address. Then, the triaxial acceleration data to be calibrated is subjected to binary two's complement operation to convert it into decimal form to obtain the corresponding two's complement calibration value. This step includes performing binary two's complement operation on the X-axis value, Y-axis value, and Z-axis value to obtain the corresponding two's complement calibration value, and writing the offset calibration value into the offset register of the accelerometer. The offset calibration value is used to calibrate the triaxial acceleration data to be calibrated to obtain the calibrated accelerometer.
[0045] For example, the positional relationship is that the accelerometer is positioned above the faucet. The registers of the accelerometer are: OUT_X_MSB(0x01), OUT_X_LSB(0x02), OUT_Y_MSB(0x03), OUT_Y_LSB(0x04), OUT_Z_MSB(0x05), and OUT_Z_LSB(0x06). The registers at addresses 0x01 and 0x02 are read, and their values are 0xFF and 0x12, respectively, i.e., OUT_X_MSB(0x01) = 0xFF and OUT_X_LSB(0x02) = 0x12. The read data is converted from binary two's complement to decimal. The MSB data of the X-axis is 0xFF = -1, and the LSB data is 0x12 = 18. Converting to decimal, this is -1(256) + 18 = -238. The binary two's complement data of the X-axis is -238. After calculating the binary two's complement, the calibration value is then calculated. It should be noted that, because it is in 2g range mode, according to the chip's usage, it needs to be divided by 8 again, i.e., the calibration value is -238 / 8. This calibration value is then converted to binary using two's complement, and represented in hexadecimal, it becomes (-238 / 8)*(-1)=30=0x1E. At this point, 0x1E is the X-axis offset calibration value. It should be noted that the division by 8 during the above two's complement operation is determined by the accelerometer chip's mode. It needs to be divided by 8 again when storing in the calibration register. During the conversion from two's complement to binary, there is a multiplication by -1 operation, which is required in two's complement; if the value is negative, the absolute value needs to be taken, and the highest bit is 1 when converted to binary. Since the Z-axis value above is positive, it does not need to be multiplied by -1 again; simply dividing by 8 is sufficient to convert it to the value in the calibration register. Specifically, the chip usage instructions state that if the device is in 2g range mode (sensitivity 0.25mg / count) during calibration, each value will be divided by 8 when storing the calibration value in the calibration register. One count in the calibration register corresponds to eight counts in the output data. For example, if the (calculated) offset result is -12 counts, the corresponding value is 12 / 8 = 1.512 / 8 = 1.5 counts. Therefore, the value to be stored in the register is +1 or +2 counts (to adjust the offset to zero). This is 1 or 2 stored in the calibration register in two's complement form.
[0046] Simultaneously, following the above method, calculate the calibration values for the Y-axis and Z-axis respectively, and write the corresponding calibration values for the X-axis, Y-axis, and Z-axis into the following registers: OFF_X (0x0F), OFF_Y (0x30), OFF_Z (0x031); after writing, read the data registers of the three axes X / Y / Z of the accelerometer in a stationary state, that is, read: OUT_X_MSB (0x01), OUT_X_LSB (0x02), OUT_Y_MSB (0x03), OUT_Y_LSB (0x04), OUT_Z_MSB (0x05), OUT_Z_LSB (0x06); the read values should be the theoretical approximation values, that is, X = 0, Y = 0, Z = 4096.
[0047] In this embodiment, by calibrating the accelerometer before sampling, the 0g offset or bias error can be eliminated, avoiding the impact of the difference between the measured value and the true 0 value on the calculation results, thus laying the foundation for improving the accuracy of position detection in the future.
[0048] S120. Determine the displacement data based on the triaxial acceleration data.
[0049] In this embodiment, the triaxial acceleration data can be filtered multiple times to obtain filtered triaxial acceleration data. The filtering methods in this embodiment may include, but are not limited to, rolling mean low-pass filtering, threshold filtering, and amplitude limiting filtering. After multiple filtering, the filtered acceleration data is integrated once using the first-order approximate trapezoidal rule to obtain the velocity value. Then, the calculated velocity data is integrated again using the first-order approximate trapezoidal rule to obtain the displacement data from n samples. Specifically, the velocity value corresponding to the n samples is determined based on the sum of the triaxial acceleration data obtained from the i-th sample and the triaxial acceleration data obtained from the (i-1)-th sample, and the sampling time interval. From the velocity values of the n samples, the velocity values obtained from the i-th sample and the (i-1)-th sample are determined. The displacement data from the n samples is determined based on the sum of the velocity values obtained from the i-th sample and the (i-1)-th sample, and the sampling time interval. Of course, other data can also be used to determine the displacement data; this embodiment does not impose specific limitations.
[0050] S130. Determine the on / off position of the faucet to be tested based on the displacement data.
[0051] The switch position status of the faucet to be detected can include whether it is in an open or closed state.
[0052] In this embodiment, the displacement data is compared with a preset first threshold and a preset second threshold to determine whether the switch position is closed or open based on the comparison result. In other embodiments, a reference point can be set, and the switch position of the faucet to be detected can be determined using this reference point and the relevant threshold. In this embodiment, after knowing the switch position of the faucet to be detected, it can be determined whether to perform a water temperature off operation or a water temperature on operation to display the water temperature.
[0053] The above-described technical solution of this invention uses an accelerometer to sample the triaxial acceleration data of the faucet to be tested. Based on this, displacement data is determined according to the triaxial acceleration data and a preset trapezoidal law. Based on this, the on / off position of the faucet to be tested is determined according to the displacement data. This solves the problem of easy misjudgment by traditional Hall sensors and magnets, especially when the switch stroke is small, the misjudgment rate is high. This improves the accuracy of position detection. Moreover, the use of an accelerometer to replace the detection method of Hall sensors and magnets is cheaper and helps to reduce production costs.
[0054] In one embodiment, the method further includes:
[0055] The calibrated accelerometer was verified, and the verification results were obtained. The verification included whether the theoretical triaxial acceleration values of the accelerometer in a stationary state were consistent with the actual triaxial acceleration values of the calibrated accelerometer in a stationary state.
[0056] If the verification result is successful, the accelerometer that has passed the verification will be used for sampling.
[0057] If the verification result is unsuccessful, the accelerometer sensor should be recalibrated based on the verification result.
[0058] In this embodiment, after calibrating the accelerometer, to prevent the calibrated accelerometer from being inaccurate again, it needs to be verified. This verification can be done by writing the calibration values to the corresponding register addresses and then reading the values of the data register addresses for the three axes (X, Y, and Z) of the accelerometer. If the read values are the same as the approximate values of the data registers for the three axes (X, Y, and Z) (i.e., the theoretical values of the three axes when the accelerometer is stationary), the verification is successful, and the verified accelerometer is used for sampling; otherwise, the verification fails. If the calibration fails, recalibration is required, followed by verification until the verification passes. This involves returning to the initialization of the accelerometer parameters, reading the stationary triaxial acceleration data from the register address of the initialized accelerometer, performing binary two's complement operations on the triaxial acceleration data to convert it to decimal form to obtain the two's complement calibration value, determining the offset calibration value based on the two's complement calibration value, writing the offset calibration value into the offset register of the accelerometer, and using the offset calibration value to calibrate the triaxial acceleration data to obtain the calibrated accelerometer.
[0059] In one embodiment, Figure 2 This is a flowchart of another faucet switch position detection method provided in an embodiment of the present invention. Based on the above embodiments, this embodiment further refines the determination of displacement data based on triaxial acceleration data and a preset trapezoidal law, and the determination of the switch position state of the faucet to be detected based on the displacement data.
[0060] like Figure 2 As shown, the faucet switch position detection method in this embodiment may specifically include the following steps:
[0061] S210. Sample the accelerometer to obtain triaxial acceleration data at each sampling time; wherein the accelerometer is configured in the faucet to be tested.
[0062] S220. Filter the triaxial acceleration data at least twice to obtain filtered triaxial acceleration data; wherein, the filtered triaxial acceleration data includes: the triaxial acceleration data obtained from the i-th sampling and the triaxial acceleration data obtained from the (i-1)-th sampling in n samplings.
[0063] In this embodiment, the filtering method for triaxial acceleration data can be to first perform rolling average low-pass filtering, also known as rolling average filtering. This filtering method can filter out most of the noise, smooth the data sequence, and improve signal quality. Then, mechanical filtering, also known as threshold filtering, amplitude limiting filtering, etc., is used to filter invalid data in unstable states based on the above filtering. In this embodiment, when in a state of no motion, a small error in acceleration may be treated as a constant velocity because it is not equal to 0 after the sampled values are summed. In the ideal case of no motion, all sampled values should be 0. Therefore, mechanical filtering refers to a filtering algorithm used to distinguish between "valid data" and "invalid data" in a state of no motion.
[0064] S230. Determine the velocity value corresponding to the nth sample based on the sum of the triaxial acceleration data obtained from the i-th sample and the triaxial acceleration data obtained from the (i-1)-th sample, as well as the time interval between the i-th sample and the (i-1)-th sample.
[0065] In this embodiment, the filtered triaxial acceleration data includes: the triaxial acceleration data obtained from the i-th sampling (which can also be understood as the triaxial acceleration data obtained from the current sampling) and the triaxial acceleration data obtained from the (i-1)-th sampling (which can also be understood as the triaxial acceleration data obtained from the previous sampling). The velocity value corresponding to the n-th sampling can be determined by the sum of the triaxial acceleration data obtained from the i-th sampling and the triaxial acceleration data obtained from the (i-1)-th sampling, and the sampling time interval. Specifically, the formula for the velocity value corresponding to the n-th sampling can be expressed as: Among them, V n Let A represent the velocity values corresponding to n samples, where n is the total number of samples. i Let A be the triaxial acceleration data obtained from the i-th sampling. i-1 denoted as the triaxial acceleration data obtained from the (i-1)th sampling; t represents the time interval between the i-th sampling and the (i-1)th sampling.
[0066] S240. From the velocity values obtained from the nth sampling, determine the velocity value obtained from the i-th sampling and the velocity value obtained from the (i-1)-th sampling.
[0067] In this embodiment, the velocity value obtained from the i-th sampling and the velocity value obtained from the (i-1)-th sampling are determined from the velocity values obtained from the n samplings.
[0068] S250. Determine the displacement data of n samples based on the sum of the velocity values obtained from the i-th sample and the (i-1)-th sample, as well as the time interval between the i-th and (i-1)-th samples.
[0069] In this embodiment, the displacement data of n samples can be determined by the sum of the velocity values obtained from the i-th sample and the (i-1)-th sample, along with the sampling time interval. Specifically, after obtaining the velocity values of n samples, the displacement data of n samples can be calculated using a formula, which is expressed as follows: Among them, P n V represents the velocity value corresponding to n samples, where n is the total number of samples. i V represents the velocity value obtained from the i-th sample. i-1 denoted as the velocity value obtained from the (i-1)th sample; t represents the time interval between the i-th sample and the (i-1)th sample.
[0070] S260. The displacement data is compared with a preset first threshold and a preset second threshold respectively; wherein the preset first threshold is greater than the preset second threshold.
[0071] The preset first threshold and the preset second threshold are displacement thresholds set based on experience. The preset first threshold is greater than the preset second threshold. For example, the preset first threshold is 0.2 mm and the preset second threshold is -0.2 mm.
[0072] In this embodiment, after obtaining the displacement data, the displacement data is compared with a preset first threshold and a preset second threshold to obtain the corresponding comparison results. If the displacement data is greater than or equal to the preset first threshold, the switch position is determined to be in the closed state, and the water temperature is turned off. If the displacement data is less than or equal to the preset second threshold, the switch position is determined to be in the open state, and the water temperature is turned on to display the water temperature.
[0073] S270. If the displacement data is greater than or equal to the preset first threshold, the switch position is determined to be closed, and the water temperature is turned off.
[0074] S280. If the displacement data is less than or equal to the preset second threshold, the switch position is determined to be in the open state, and the water temperature is turned on to display the water temperature.
[0075] The technical solution described in this embodiment uses a calibrated accelerometer to sample the faucet under test, obtaining triaxial acceleration data for each sampling. This eliminates 0g offset or bias errors, preventing the difference between the measured value and the true 0 value from affecting the calculation results. By filtering the triaxial acceleration data at least twice, filtered triaxial acceleration data is obtained, effectively eliminating position drift caused by error accumulation and noise interference after long-term use, further improving the accuracy of position detection. Based on this, the velocity value corresponding to the nth sampling is determined by the sum of the triaxial acceleration data obtained from the i-th sampling and the triaxial acceleration data obtained from the (i-1)-th sampling, as well as the time interval between the i-th and (i-1)-th samplings. The sum of the velocity values obtained from the i-th and (i-1)-th samplings, along with the time interval between the i-th and (i-1)-th samplings, determines the displacement data from the n-th sampling. This displacement data is then compared with a preset first threshold and a preset second threshold to determine the switch position. This method further addresses the problem of misjudgment by traditional Hall effect sensors and magnets, especially when the switch travel is small, resulting in a high misjudgment rate. This improves the accuracy of position detection. Furthermore, using an accelerometer instead of a Hall effect sensor and magnet not only accurately determines whether the switch is currently on or off, but also eliminates the need for a magnet, optimizing the manufacturing process, reducing production steps, improving yield, and lowering costs.
[0076] In one embodiment, to facilitate a better understanding of the faucet switch position detection method based on an acceleration sensor, Figure 3 This is a schematic diagram of another method for detecting the position of a faucet switch according to an embodiment of the present invention. Figure 4 This is a schematic diagram of the switch state of a push-button faucet when it is closed and not pressed, according to an embodiment of the present invention. Figure 5 This is a schematic diagram of a push-button faucet that dispenses water when pressed, according to an embodiment of the present invention, and is in the open state.
[0077] In this embodiment, when the user operates the faucet switch, the switch causes the valve core to open and close. Simultaneously, the displacement of the switch is detected by an accelerometer, which detects the switch's displacement in the vertical or horizontal direction. The control system calculates the current position of the switch based on the displacement data detected by the accelerometer, thereby determining whether the valve core is currently open or closed. In this embodiment, the faucet switch position detection device based on an accelerometer can accurately detect the switch's position, solving problems such as misjudgment and position drift existing in the prior art. It also reduces production costs and difficulty, possessing significant practical value. Figure 3As shown in the figure, the process for detecting the position of the faucet switch in this embodiment includes the following description:
[0078] a1. Power on, MCU initializes, and the accelerometer communicates with the MCU via I2C.
[0079] a2. Read the acceleration data from the three axes (X, Y, and Z) of the accelerometer. Use the X, Y, and Z axes to determine whether the faucet is a handle-type or push-button type. For example, if X = 0, Y = 0, and Z = 4096, it indicates gravitational acceleration on the Z-axis. In this case, the circuit board is installed horizontally, corresponding to a push-button type faucet. Similarly, if X = 0, Y = 4096, and Z = 0, it indicates gravitational acceleration on the Y-axis. In this case, the circuit board is installed vertically, corresponding to a handle-type faucet. Configure the faucet type accordingly. The algorithm logic will be explained using a push-button type faucet as an example. The logic principle for handle-type faucets is the same as for push-button faucets; only the Z-axis algorithm needs to be changed to the Y-axis algorithm.
[0080] a3. After configuring the faucet type, begin calibrating the accelerometer and verifying the calibrated accelerometer. The calibration and verification steps include a31-a37.
[0081] a31. The acceleration sensor is mounted on the push-button switch of the faucet, with the faucet facing forward.
[0082] a32. Initialize the accelerometer parameters, set the sampling frequency to 200Hz, start the X, Y, and Z axes, and set the range to ±2g.
[0083] a33. Read the triaxial acceleration data to be calibrated from the accelerometer in a stationary state. The data needs to be calibrated to the ideal values (i.e., theoretical values) of the X, Y, and Z axes, such as X = 0, Y = 0, Z = 4096.
[0084] a34. Calculate the two's complement of the three-axis acceleration data to be calibrated respectively; for example, the MSB data of the X-axis is 0xFF = -1, the LSB data is 0x12 = 18, -1(256)+18 = -238, and the two's complement data of the X-axis is -238.
[0085] a35. Calculate the corresponding offset calibration value based on the two's complement value of each axis. For example, if the two's complement data of the X-axis is -238, the offset calibration value is (-238 / 8)*(-1)=30=0x1E. Another example is that if the two's complement data of the Z-axis is 3998, the offset calibration value is (4096-3998).
[0086] / 8=13=0x0D.
[0087] a36. Set to standby mode and write the offset calibration value, such as OFF_Z(0x31) written as 0x0D.
[0088] a37. Read the XYZ axis data again in the static state. If the read XYZ axis data is consistent with the theoretical value, the calibration result is passed. For example, the current Z axis data is 4096.
[0089] a4. The accelerometer is set to operating mode and continuously samples. The MCU connects to read the accelerometer data, performs rolling average low-pass filtering on the read data to filter out most of the noise, and performs mechanical filtering on the sampled data to filter out invalid data in unstable states.
[0090] a5. Integrate the filtered acceleration data once, and use the first-order approximate trapezoidal rule to obtain the velocity value. The algorithm formula is as follows:
[0091]
[0092] a6. The calculated velocity data is integrated again using the first-order approximate trapezoidal rule. The algorithm formula is as follows:
[0093]
[0094] a7. After the movement is completed, calculate the displacement, determine the current position of the faucet switch, whether it is in the open or closed state, and then execute the action of lighting up or turning off the water temperature digital display.
[0095] In one embodiment, Figure 6 This is a structural block diagram of a faucet switch position detection device according to an embodiment of the present invention. This device is suitable for detecting the switch position of a faucet and can be implemented in hardware or software. It can be configured in an electronic device to implement a faucet switch position detection method according to an embodiment of the present invention. Figure 6 As shown, this device is applied to an electronic device, which communicates with an acceleration sensor through a preset communication method; the device includes: a sampling module 610, a displacement determination module 620, and a state determination module 630.
[0096] The sampling module 610 is used to sample the accelerometer to obtain triaxial acceleration data at each sampling time; wherein the accelerometer is disposed in the faucet to be tested;
[0097] The displacement determination module 620 is used to determine displacement data based on the triaxial acceleration data;
[0098] The state determination module 630 is used to determine the on / off position state of the faucet to be detected based on the displacement data.
[0099] In this embodiment of the invention, the sampling module obtains triaxial acceleration data at the time of sampling by sampling the acceleration sensor. Based on this, the displacement determination module determines the displacement data according to the triaxial acceleration data. Based on this, the state determination module determines the switch position state of the faucet to be detected according to the displacement data. This can solve the problem of high misjudgment rate in switch position detection in the prior art, and improve the accuracy of position detection while reducing production costs.
[0100] In one embodiment, determining the positional relationship between the accelerometer and the faucet to be detected includes:
[0101] Read the initial triaxial acceleration data from the accelerometer before detecting the position of the faucet to be detected;
[0102] The type of faucet to be tested is determined based on the initial triaxial acceleration data; wherein, the faucet type includes: push-button faucet and handle-operated faucet;
[0103] The positional relationship between the accelerometer and the faucet to be tested is determined according to the type of faucet; wherein the positional relationship includes: the accelerometer is installed inside the upper part of the faucet to be tested; the accelerometer is installed inside the side of the faucet to be tested.
[0104] In one embodiment, the device further includes:
[0105] A calibration module is used to calibrate the accelerometer before sampling it.
[0106] The calibration of the acceleration sensor includes:
[0107] Initialize the parameter values of the accelerometer; wherein the parameter values include at least: the sampling frequency of the sampled values and the acceleration range measured by the accelerometer.
[0108] After the positional relationship between the faucet to be tested and the accelerometer is determined, the triaxial acceleration data to be calibrated in a static state is read from the register address of the initialized accelerometer.
[0109] The triaxial acceleration data to be calibrated are subjected to binary two's complement operation and converted into decimal form to obtain the calibration value after two's complement.
[0110] An offset calibration value is determined based on the two's complement calibration value, and the offset calibration value is written into the offset register of the accelerometer. The offset calibration value is then used to calibrate the triaxial acceleration data to be calibrated, resulting in a calibrated accelerometer.
[0111] In one embodiment, the displacement determination module 620 includes:
[0112] A filtering unit is used to filter the triaxial acceleration data at least twice to obtain filtered triaxial acceleration data; wherein, the filtered triaxial acceleration data includes: triaxial acceleration data obtained from the i-th sampling and triaxial acceleration data obtained from the (i-1)-th sampling in n samplings; where i and i-1 belong to n;
[0113] The first velocity value determination unit is used to determine the velocity value corresponding to the nth sample based on the sum of the triaxial acceleration data obtained from the i-th sample and the triaxial acceleration data obtained from the (i-1)-th sample, and the time interval between the i-th sample and the (i-1)-th sample.
[0114] The second velocity value determination unit is used to determine the velocity value obtained from the i-th sample and the velocity value obtained from the (i-1)-th sample from the velocity values obtained from the n-sampled samples.
[0115] The displacement determination unit is used to determine the displacement data of n samples based on the sum of the velocity values obtained from the i-th sample and the (i-1)-th sample, as well as the time interval between the i-th sample and the (i-1)-th sample.
[0116] In one embodiment, the state determination module 630 includes:
[0117] A comparison unit is used to compare the displacement data with a preset first threshold and a preset second threshold, respectively; wherein the preset first threshold is greater than the preset second threshold;
[0118] The first result determination unit is used to determine that the switch position state is closed if the displacement data is greater than or equal to the preset first threshold, and to perform a water temperature extinguishing operation.
[0119] The second result determination unit is used to determine that the switch position state is in the open state if the displacement data is less than or equal to the preset second threshold, and to perform the water temperature lighting operation to display the water temperature.
[0120] In one embodiment, the device further includes:
[0121] The verification module is used to verify the calibrated accelerometer and obtain the verification result; wherein, the verification includes: whether the theoretical triaxial acceleration value of the accelerometer in a stationary state is consistent with the actual triaxial acceleration value of the calibrated accelerometer in a stationary state;
[0122] The verification unit is used to sample the faucet under test using the verified accelerometer if the verification result is passed.
[0123] The verification failure unit is used to recalibrate the accelerometer based on the verification result if the verification result is unsuccessful.
[0124] The faucet switch position detection device provided in this embodiment of the invention can execute the faucet switch position detection method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method.
[0125] In one embodiment, Figure 7 This is a schematic diagram of an electronic device provided for an embodiment of the present invention. The electronic device 10 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0126] like Figure 7 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0127] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0128] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as the faucet switch position detection method.
[0129] In some embodiments, the faucet switch position detection method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the faucet switch position detection method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the faucet switch position detection method by any other suitable means (e.g., by means of firmware).
[0130] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0131] Computer programs used to implement the methods of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to the processor of a general-purpose computer, a special-purpose computer, or other programmable faucet switch position detection device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The computer programs can be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0132] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0133] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0134] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0135] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0136] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0137] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for detecting the position of a faucet switch, characterized in that, The method is applied to an electronic device, wherein the electronic device communicates with an acceleration sensor via a preset communication method; the method includes: The accelerometer is sampled to obtain triaxial acceleration data at each sampling time; wherein the accelerometer is disposed in the faucet to be tested; Displacement data is determined based on the triaxial acceleration data; The on / off position of the faucet to be tested is determined based on the displacement data.
2. The method according to claim 1, characterized in that, Determining the positional relationship between the accelerometer and the faucet to be detected includes: Read the initial triaxial acceleration data from the accelerometer before detecting the position of the faucet to be detected; The type of faucet to be tested is determined based on the initial triaxial acceleration data; wherein, the faucet type includes: push-button faucet and handle-operated faucet; The positional relationship between the accelerometer and the faucet to be tested is determined according to the type of faucet; wherein the positional relationship includes: the accelerometer is installed inside the upper part of the faucet to be tested; the accelerometer is installed inside the side of the faucet to be tested.
3. The method according to claim 1, characterized in that, Before sampling the accelerometer, the method further includes calibrating the accelerometer. The calibration of the acceleration sensor includes: Initialize the parameter values of the accelerometer; wherein the parameter values include at least: the sampling frequency of the sampled values and the acceleration range measured by the accelerometer. After the positional relationship between the faucet to be tested and the accelerometer is determined, the triaxial acceleration data to be calibrated in a static state is read from the register address of the initialized accelerometer. The triaxial acceleration data to be calibrated are subjected to binary two's complement operation and converted into decimal form to obtain the calibration value after two's complement. An offset calibration value is determined based on the two's complement calibration value, and the offset calibration value is written into the offset register of the accelerometer. The offset calibration value is then used to calibrate the triaxial acceleration data to be calibrated, resulting in a calibrated accelerometer.
4. The method according to claim 1, characterized in that, The step of determining displacement data based on the triaxial acceleration data includes: The triaxial acceleration data is filtered at least twice to obtain filtered triaxial acceleration data; wherein, the filtered triaxial acceleration data includes: the triaxial acceleration data obtained from the i-th sampling and the triaxial acceleration data obtained from the (i-1)-th sampling in n samplings; The velocity value corresponding to the nth sample is determined based on the sum of the triaxial acceleration data obtained from the i-th sample and the triaxial acceleration data obtained from the (i-1)-th sample, as well as the time interval between the i-th sample and the (i-1)-th sample. From the velocity values obtained from n samples, determine the velocity value obtained from the i-th sample and the velocity value obtained from the (i-1)-th sample; The displacement data of n samples is determined based on the sum of the velocity values obtained from the i-th sample and the (i-1)-th sample, as well as the time interval between the i-th sample and the (i-1)-th sample.
5. The method according to claim 1, characterized in that, Determining the on / off position of the faucet to be detected based on the displacement data includes: The displacement data is compared with a preset first threshold and a preset second threshold, respectively; wherein the preset first threshold is greater than the preset second threshold. If the displacement data is greater than or equal to the preset first threshold, then the switch position is determined to be in the closed state, and the water temperature is turned off. If the displacement data is less than or equal to the preset second threshold, the switch position is determined to be in the open state, and the water temperature is activated to display the water temperature.
6. The method according to claim 3, characterized in that, The method further includes: The calibrated accelerometer is verified to obtain the verification results; wherein, the verification includes: whether the theoretical triaxial acceleration value of the accelerometer in a stationary state is consistent with the actual triaxial acceleration value of the calibrated accelerometer in a stationary state; If the verification result is passed, then the verified accelerometer is used for sampling; If the verification result is unsuccessful, the accelerometer sensor will be recalibrated based on the verification result.
7. A faucet switch position detection device, characterized in that, An electronic device that communicates with an acceleration sensor via a preset communication method; the device includes: A sampling module is used to sample the accelerometer to obtain triaxial acceleration data at each sampling time; wherein the accelerometer is disposed in the faucet to be tested; The displacement determination module is used to determine displacement data based on the triaxial acceleration data. The state determination module is used to determine the on / off position state of the faucet to be detected based on the displacement data.
8. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the faucet switch position detection method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the faucet switch position detection method according to any one of claims 1-6.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the faucet switch position detection method according to any one of claims 1-6.
Citation Information
Patent Citations
Faucet monitoring device, faucet comprising same and monitoring method
CN102506228A
Acceleration signal measurement displacement method based on numerical integration
CN103604404A
Door state detection method and device
CN110853269A
Door opening-closing detection system based on digital gyroscope
CN111577059A
Backlight display shower disassembly, shower device and backlight display control method
CN111764472A