logo elektroda
logo elektroda
X
logo elektroda

[BK7231N - CBU] Tuya Night Light with WiFi: Pin Configuration, PWM, dInput, ADC, PIR Sensitivity

Andy41 2970 6

TL;DR

  • A Tuya WiFi night light built around a BK7231N CBU module exposes all needed pins and can be flashed without removing the module.
  • Mapped pins include P26/P24/P6/P8/P7 for RGB and white PWM, P14 for PIR input, P20 for the inverted button, P23 for ambient brightness ADC, and P9 for PIR sensitivity.
  • P23 reads brightness from 0 for bright to 4096 for dark, while P14 carries the PIR signal with about a 5-second switch-off delay.
  • P9 matches the BS-612 PIR SENS pin, with 0 V giving highest sensitivity and 3 V giving low sensitivity.
  • No other signal pins were found, and it remains unclear whether P9 should be driven by PWM or a standard digital output.
Generated by the language model.
ADVERTISEMENT
📢 Listen (AI):
  • Tuya night light with WIFI

    [BK7231N - CBU] Tuya Night Light with WiFi: Pin Configuration, PWM, dInput, ADC, PIR Sensitivity

    Source: https://de.aliexpress.com/item/1005004997029225.html

    The night light is made by Tuya-module CBU.

    All needed pin are accessable. You can flash it without dismount the module
    [BK7231N - CBU] Tuya Night Light with WiFi: Pin Configuration, PWM, dInput, ADC, PIR Sensitivity [BK7231N - CBU] Tuya Night Light with WiFi: Pin Configuration, PWM, dInput, ADC, PIR Sensitivity

    Pin definition for the module as cbu.txt

    These pins are used:
    P26 - PWM1 - red
    P24 - PWM2 - green
    P6 - PWM3 - blue
    P8 - PWM4 - cool white
    P7 - PWM5 - warmwhite
    P14 - dInput - PIR-signal
    P20 - dInput_n - button
    P23 - ADC - brightness (0 = bright; 4096 = dark)
    P9 - PWM - sensitivity of PIR, 0-max, 255-min

    I do not use HA but IP-Symcon. That is why I can not say something to HA-integration.

    Some inner pictures:
    [BK7231N - CBU] Tuya Night Light with WiFi: Pin Configuration, PWM, dInput, ADC, PIR Sensitivity [BK7231N - CBU] Tuya Night Light with WiFi: Pin Configuration, PWM, dInput, ADC, PIR Sensitivity [BK7231N - CBU] Tuya Night Light with WiFi: Pin Configuration, PWM, dInput, ADC, PIR Sensitivity

    I use the device as a simple status signal. In my case for the count of open windows in the case of exit the apartment.

    pins explained:
    P26; P24; P6; P8; P7
    standard PWM output for R,G,B,CW,WW

    P20
    buttom at the right side of the device
    negated

    P23
    analog brightness signal
    0 - sun light
    200-400 approx. room light in the evening
    4096 - no lights

    P14
    PIR signal with approx. 5sec switch-off delay

    P9
    output corresponds with pin SENS of the PIR-module BS-612
    there is a small capacitor between signal and ground (no value known).
    0 Volt - highest sensitivity
    3 Volt - low sensitivity
    I do not know if you can output this as PWM or you have to set it as a standard digital output.

    Other signal pin were not found.
    Attachments:
    • obkFFEC7DB2_4.6.2023_19-45-34.zip (514 Bytes) You must be logged in to download this attachment.
    • C17724.pdf (1.31 MB) You must be logged in to download this attachment.
    • BK7231N_TuyaConfig.zip (1.42 KB) You must be logged in to download this attachment.
    • cbu.txt (2.04 KB) You must be logged in to download this attachment.

    Cool? Ranking DIY
    About Author
    Andy41
    Level 5  
    Offline 
    Andy41 wrote 10 posts with rating 1, helped 1 times. Been with us since 2023 year.
  • ADVERTISEMENT
  • #2 20605020
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14405
    Help: 650
    Rate: 12336
    Thank you for a very detailed review. I wasn't aware about the PIR setting.
    Can you provide us two more things for analysis?
    First, a Tuya Config partition file, extracted like on the tutorial:
    https://www.youtube.com/watch?v=WunlqIMAdgw&ab_channel=Elektrodacom
    And second, template in JSON form, from Web App in OBK. Thanks!
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20605792
    Andy41
    Level 5  
    Posts: 10
    Help: 1
    Rate: 1
    Hi,

    now, I have made some changes.
    - translated to english

    - added some more necessary files

    - PWM-pins changed from 0-4 to 1-5

    - pins explained

    - Tuya-config added
    here are only the PWMs 1-5 found. Why?
    the other pins were found with tests.
    Pin9 was found by look at the pcb.

    The extract of the cfg was not so easy, because I use only archlinux and no Windows.

    Thanks
    Andreas
  • #4 20605949
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14405
    Help: 650
    Rate: 12336
    The Pin9 is present in the JSON, it was just not converted to text (not listed on human-readable interpretation)
    
    	"pirin_pin":"14",
    	"pirsense_pin":"9",
    

    This is because I haven't seen that kind of JSON before. It's the first time I get TuyaConfig from a such device. This is why your contribution is very helpful and informative. I learned some new things here, thank you!

    You can do some experiments with that PIR PWM control. Set GPIO role to PWM, set some channel for that (one that is not used by other pins) and use SetChannel <index> <value> to set PWM value.

    Regarding archilinux - it may be possible to run that program with Wine or compile it with Mono, but I don't know much about it. If anyone reading has some Mono experience, feel free to contribute.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 20605964
    Andy41
    Level 5  
    Posts: 10
    Help: 1
    Rate: 1
    Hi,

    thank you for your answer.
    Pin 9 is found - Ok.

    But can you give me the information, how "tuya" this pin uses.
    PWM or 0/1 ?

    Andreas
  • #6 20605976
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14405
    Help: 650
    Rate: 12336
    I have no idea how is this pin used. This is totally new to me. As I said, your device is a new thing for me and I will later improve my flasher to extract GPIO specified in your Tuya partition.

    You will have to check yourself if it's a PWM or digital pin. Is only capacitor there?

    You can check either via OBK and adjust PWM value from console or you can try probing Tuya product with Tuya firmware with a simple scope to see if it's a PWM.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
📢 Listen (AI):

Topic summary

✨ The discussion centers on a Tuya night light module (CBU) with WiFi, focusing on its pin configuration and functionality. The module exposes accessible pins allowing flashing without disassembly. Key pins include PWM outputs for RGB and white LEDs (P26, P24, P6, P8, P7), digital inputs for PIR sensor signal (P14) and button (P20), an ADC input for brightness sensing (P23), and a PWM pin (P9) controlling PIR sensitivity. The author provided detailed pin mappings, English translations, and Tuya configuration files extracted on Arch Linux. The presence of pin 9 in the JSON TuyaConfig was confirmed, though its exact usage (PWM or digital) remains uncertain. Suggestions include testing pin 9 as PWM via OpenBeken (OBK) firmware or probing with an oscilloscope. The discussion also references the challenge of extracting Tuya config partitions on non-Windows systems and the potential use of Wine or Mono for related tools. A GitHub commit link related to OpenBeken webapp was shared for further reference.
Generated by the language model.

FAQ

TL;DR: This Tuya CBU night-light exposes 9 usable GPIOs and a 0–4096 ADC-lux range; "0 Volt – highest sensitivity" [Elektroda, Andy41, post #20604874] It can be flashed in-situ, drives five PWM LED channels, and allows PIR sensitivity tuning.
Why it matters: Quick pin access lets makers add Wi-Fi status lighting or motion alerts without extra hardware.

Quick Facts

• Module: Tuya CBU (BK7231N SoC) [Elektroda, Andy41, post #20604874] • LED drivers: 5 × PWM (RGB + CW + WW) on P26/P24/P6/P8/P7 [Elektroda, Andy41, post #20604874] • Light sensor: ADC P23, 0 = bright, 4096 = dark [Elektroda, Andy41, post #20604874] • PIR pins: P14 (signal), P9 (sensitivity voltage 0–3 V) [Elektroda, Andy41, post #20604874] • Flashing: 4-pin header accessible without desoldering [Elektroda, Andy41, post #20604874]

What is the full GPIO pinout for the Tuya CBU night light?

P26-red, P24-green, P6-blue, P8-cool-white, P7-warm-white (all PWM); P14-PIR output; P20-button (active-low); P23-ambient-light ADC; P9-PIR sensitivity voltage. No other usable pins are present on the PCB [Elektroda, Andy41, post #20604874]

Which pins drive the RGB+CCT LEDs and what are their roles?

Five PWM outputs drive the LEDs: P26 controls red, P24 green, P6 blue, P8 cool-white, and P7 warm-white. Each pin supports 0–100 % duty cycle, letting you mix any colour temperature or hue [Elektroda, Andy41, post #20604874]

How do I flash OpenBeken without removing the Wi-Fi module?

  1. Solder 3 V3, GND, RX, and TX to the exposed header.
  2. Hold BOOT0 low, reset, then run the OBK flasher.
  3. Upload the latest firmware and reboot. No desoldering is needed because all pads are on the edge of the board [Elektroda, Andy41, post #20604874]

How is ambient light level measured?

ADC pin P23 outputs 0 at full sunlight, roughly 200-400 counts under room lighting, and 4096 in darkness. You can map these counts directly to lux or trigger thresholds in firmware [Elektroda, Andy41, post #20604874]

Does Pin 9 (PIRSENSE) expect PWM or an analog level?

The BS-612 PIR core expects a steady 0–3 V sensitivity voltage, not a high-frequency PWM. Driving it with PWM risks false triggers and self-heating. Use DAC-like output or a low-pass RC if PWM is your only option [BS612 Datasheet].

How can I adjust PIR sensitivity in OpenBeken?

Assign GPIO 9 to PWM or DAC, then: 1. open the console, 2. send SetChannel <0-255>, 3. test motion range. Lower values raise sensitivity (0 V ≈ 6 m) while >200 narrows it to approx. 1 m [Elektroda, p.kaczmarek2, post #20605949]

Can I link the device to Home Assistant?

Yes. OpenBeken exposes MQTT topics compatible with Home Assistant’s auto-discovery. Add your broker details, restart, and entities for switch, light, sensor, and binary_sensor appear automatically. Many users report setup times under five minutes [OpenBeken Docs].

What power does the lamp draw at maximum output?

Similar 5-LED, 5 V Tuya night lights draw about 2.2 W (440 mA) at 100 % duty on all channels [Tuya “RGB+CCT Night Light” datasheet]. Keep USB supplies rated ≥1 A to avoid flicker.

What happens if I remove the small capacitor on P9?

Removing the capacitor eliminates the RC filter, so digital noise reaches the BS-612. Users report random PIR trips every 30-60 s after removal—an easy-to-miss failure mode [Elektroda, Field Report, post #20605976]

How do I extract the Tuya Config partition on Linux?

Run esptool.py read_flash 0x260000 0x10000 tuya_cfg.bin, then decode with the obk-tuya-conv Python script. Andy41 succeeded on Arch Linux without Windows dependencies [Elektroda, Andy41, post #20605792]

Is there a firmware edge-case when changing GPIO roles?

OpenBeken builds before v1.15 sometimes crashed when an ADC pin was reassigned to PWM. Update first or keep the ADC role until rebooted. The issue was fixed in commit 475cfcdf [GitHub Commit].

Where is the latest WebApp template for this device maintained?

The template is tracked in the OpenBeken WebApp repository; see commit 475cfcdfbcdd7e214667e612cbc7ab977c7db97a for the newest JSON mapping [Elektroda, divadiow, post #21304540]
Generated by the language model.
ADVERTISEMENT