logo elektroda
logo elektroda
X
logo elektroda

[BK7231T] Tuya switch with multiple buttons on single ADC pin

rishabmehta7 1719 12
ADVERTISEMENT
  • #1 20523046
    rishabmehta7
    Level 6  
    Hi Team,

    I have a 3 gang touch switch from Tuya similar to '3 Gang Switch (DS-103)' in the list. I was able to use this profile to install the Open Beken using Cloud Cutter.
    The problem is the pin layout of the device in the profile did not work. I manually figured out the pins for WiFi LED along with the 3 Relays. What I noticed was all 3 touch buttons are connected to the same GPIO PIN P23.
    This is the Analog pin, Seeting this to Temp I was able to measure the values as follows.
    no button 4095 C
    1st button 1604 C
    2nd button 897 C
    3rd button 2 C
    1st and 2nd 602 C
    1st and 3rd 4 C
    2nd and 3rd 3 C

    Is there any way to use the touch switch reliably?

    I am attaching the factory bin file along with the PCB pictures.

    Current Pin
    P7 Relay 1
    P8 Relay 2
    P22 WiFiLED
    P24 Relay 0

    Added packaging pictures.

    -Rishab
    Attachments:
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230419_193500.jpg (3.62 MB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230419_193505.jpg (3.47 MB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230419_193523.jpg (3.33 MB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230419_193557.jpg (1.15 MB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230419_193510.jpg (3.74 MB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230419_193517.jpg (3.33 MB) You must be logged in to download this attachment.
    • dump_3gang.bin (2 MB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin Screenshot_20230401-233710.jpg (133.1 KB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230331_123334.jpg (853.05 KB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230331_123330.jpg (1.01 MB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230403_185933.jpg (5.7 MB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230331_123339.jpg (992.14 KB) You must be logged in to download this attachment.
    • [BK7231T] Tuya switch with multiple buttons on single ADC pin IMG_20230403_190227.jpg (4.41 MB) You must be logged in to download this attachment.
  • ADVERTISEMENT
  • #2 20523162
    p.kaczmarek2
    Moderator Smart Home
    Hello, I haven't seen such a switch yet, but using ADC to handle multiple buttons is a known practice.

    I can add support for such mechanism for you, I'd just need a few days.

    Futhermore, can you give us more information where did you get that switch and what kind of switch model is it?

    It would be also also helpful if you've checked the way resistors are arranged on ADC pins, but that's not necessary.

    PS: If you want a temporary, quick solution, it should be also possible to create a simple script mechanism for that, but I don't think it's necessary.
    Helpful post? Buy me a coffee.
  • #3 20523180
    rishabmehta7
    Level 6  
    Appreciate all your help. Will find the Alibaba listing for the same.
  • ADVERTISEMENT
  • #5 20538721
    rishabmehta7
    Level 6  
    >>20523162
    Hi

    Any update?
  • #6 20538794
    p.kaczmarek2
    Moderator Smart Home
    I will try to look into it today. Yesterday I had some work with TM1637/GN6932 driver.
    Helpful post? Buy me a coffee.
  • #7 20538806
    rishabmehta7
    Level 6  
    Did not mean to rush you. Please take ur time.
  • ADVERTISEMENT
  • #8 20539846
    p.kaczmarek2
    Moderator Smart Home
    Hello, I didn't have time to test, but I will push a test version of a driver.

    Steps to setup:
    1. check ADC values for buttons

    You already gave me this:
    no button 4095 C
    1st button 1604 C
    2nd button 897 C
    3rd button 2 C

    2. Create margins between values (as average values):

    no button 4095 C
    2900
    1st button 1604 C
    1250
    2nd button 897 C
    450
    3rd button 2 C

    3.

    Set role ADCButton for ADC in Configure Module

    4. Write autoexec.bat:

    
    // start driver - always first
    startDriver ADCButton
    // setup map to choose button
    AB_Map 450 1250 2900
    
    // setup event handlers for buttons
    // when got "no button" reading - do nothing
    // addEventHandler OnADCButton 0 
    // on 1st button
    addEventHandler OnADCButton 1 toggleChannel 1
    // on 2nd button
    addEventHandler OnADCButton 2 toggleChannel 2
    // on 3rd button
    addEventHandler OnADCButton 3 toggleChannel 3
    

    Tested only in simulator:
    [BK7231T] Tuya switch with multiple buttons on single ADC pin

    Please test and let me know if it works

    I hope you know our scripting syntax.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #9 20539908
    rishabmehta7
    Level 6  
    Very new to OpenBeken, but I think I can figure this out (worked with Tasmota for a long time already). I will try this first thing in the morning (it's already 1 am).

    Thanks for all the help.
  • #10 20539998
    p.kaczmarek2
    Moderator Smart Home
    I will be pushing it to repository in 15 minutes.

    Autoexec.bat can be created in Web Application, LittleFS tab.
    Helpful post? Buy me a coffee.
  • #11 20541200
    rishabmehta7
    Level 6  
    So I tried with the latest build and the bat file. Seems to have some issues. Let me get a detailed video tomorrow.

    Should I use channel 1 2 3 for relay instead of 0 1 2? and leave 0 for ADC button?
  • Helpful post
    #12 20541682
    p.kaczmarek2
    Moderator Smart Home
    It doesn't matter, I think. You can use channel 10 for button to keep it far from relays, it won't be used anyway by firmware, firmware will read ADC internally.

    On the other hand, I've realized something and added a fix. Please update to latest version.
    Helpful post? Buy me a coffee.
  • Helpful post
    #13 20541973
    rishabmehta7
    Level 6  
    All Fixed!!!!!

    -----Pin Config-----
    P22WiFiLed0
    P24Relay0
    P07Relay1
    P08Relay2
    P23ADC_Button5


    -----Below is the final script-----
    // start driver - always first
    startDriver ADCButton
    // setup map to choose button
    AB_Map 450 1250 2900
    // setup event handlers for buttons
    // when got "no button" reading - do nothing
    // addEventHandler OnADCButton 0 
    // on 1st button
    addEventHandler OnADCButton 0 toggleChannel 2
    // on 2nd button
    addEventHandler OnADCButton 1 toggleChannel 1
    // on 3rd button
    addEventHandler OnADCButton 2 toggleChannel 0

Topic summary

✨ A user inquired about a 3 gang touch switch from Tuya, specifically the '3 Gang Switch (DS-103)', which they successfully flashed with Open Beken using Cloud Cutter. However, they encountered issues with the pin layout, discovering that all three touch buttons are connected to a single ADC pin (P23). The user measured ADC values for each button and sought a reliable method to utilize the switch. Community members discussed the feasibility of using ADC for multiple buttons and provided a step-by-step guide to configure the switch, including setting up ADC values, creating margins, and writing an autoexec.bat script for button event handling. After several iterations and troubleshooting, a final configuration was established, successfully mapping the buttons and relays.

FAQ

TL;DR: 3 thresholds let one ADC pin drive 3 buttons; "start driver - always first" with OpenBeken’s ADCButton, AB_Map, and event handlers. [Elektroda, p.kaczmarek2, post #20539846]

Why it matters: This helps OpenBeken users make Tuya BK7231T 3‑gang touch switches work reliably without extra hardware.

Quick Facts

How do I make three Tuya touch buttons on one ADC pin work in OpenBeken?

Use the ADCButton driver and AB_Map to split the ADC range into three buckets. Bind OnADCButton events to your relay channels. Start the driver, set AB_Map 450 1250 2900, then add handlers that toggle the relays. This approach was validated by the developer. [Elektroda, p.kaczmarek2, post #20539846]

How do I configure it end-to-end? (3-step How‑To)

  1. In Configure Module, set P23 to ADC_Button.
  2. In autoexec.bat: startDriver ADCButton, then AB_Map 450 1250 2900.
  3. Add handlers: OnADCButton 0→toggleChannel 2, 1→toggleChannel 1, 2→toggleChannel 0. Adjust channel numbers if needed. [Elektroda, rishabmehta7, post #20541973]

What thresholds should I use for AB_Map?

Measure raw counts, then set boundaries at midpoints between clusters. Example counts: 4095 (no press), 1604, 897, 2. Boundaries used: 450, 1250, 2900. These split the ADC space into three stable button zones. “Create margins between values (as average values).” [Elektroda, p.kaczmarek2, post #20539846]

Where do I put autoexec.bat in OpenBeken?

Create autoexec.bat via the Web Application under the LittleFS tab. Save the file there so it runs at boot. This is the supported method for persistent scripts and driver startup. [Elektroda, p.kaczmarek2, post #20539998]

Why do my button events look off by one?

Update to the latest firmware. A fix adjusted behavior, so event indexes may differ from earlier builds. After updating, remap your OnADCButton handlers if necessary to match the observed indexes. [Elektroda, p.kaczmarek2, post #20541682]

What pin mapping worked on a DS‑103‑like 3‑gang switch?

Verified mapping: P22 WiFiLed0, P24 Relay0, P07 Relay1, P08 Relay2, P23 ADC_Button5. This configuration, combined with AB_Map 450 1250 2900 and event handlers, delivered stable control. [Elektroda, rishabmehta7, post #20541973]

How do I read ADC counts to choose thresholds?

Temporarily assign P23 to Temp to view raw ADC counts. Example readings observed: 4095 (no press), 1604, 897, 2 for buttons. Use these to compute midpoints for AB_Map. Revert P23 to ADC_Button after measuring. [Elektroda, rishabmehta7, post #20523046]

What happens if I press two touch buttons at once?

Combined presses can yield blended counts like ~602, ~4, or ~3. Treat multi-press as an edge case and ignore or handle separately. Keep thresholds centered on single-press clusters to minimize false triggers. [Elektroda, rishabmehta7, post #20523046]

Does the ADC button channel number matter in OpenBeken?

No. You can place the ADC_Button on an unused channel, even channel 10. As the developer notes, “firmware will read ADC internally.” This keeps it separate from relay channels. [Elektroda, p.kaczmarek2, post #20541682]

Can I flash OpenBeken without opening the device?

Yes. The user flashed with Cloud Cutter using a DS‑103 profile, then corrected pins manually. Once OpenBeken runs, configure the ADC and relays as described. This approach avoids soldering. [Elektroda, rishabmehta7, post #20523046]

Is using one ADC pin for multiple buttons reliable?

Yes, with proper thresholds and the ADCButton driver. The developer confirms it is “a known practice.” Use AB_Map midpoints and event handlers for stable control. Real hardware testing reported success. [Elektroda, p.kaczmarek2, post #20523162]

Which product was this tested on?

A Tuya 3‑gang touch switch sourced as “WiFi Smart Light Switch Glass Panel” was referenced. The method applies to similar BK7231T boards that multiplex buttons on one ADC pin. [Elektroda, rishabmehta7, post #20534003]

How do I prevent false triggers near thresholds?

Pick boundaries at the average between measured clusters to add margin. For the shared ADC case, AB_Map 450 1250 2900 separated the zones cleanly. Re-measure after installation and tweak if needed. [Elektroda, p.kaczmarek2, post #20539846]
ADVERTISEMENT