logo elektroda
logo elektroda
X
logo elektroda

[BK7231N / CB3S] AliExpress Generic PIR Sensor HW4008-W: Setup, Template, Features & Details

ThatGuyinOz  8 4020 Cool? (+2)
📢 Listen (AI):

TL;DR

  • BK7231N / CB3S AliExpress generic PIR sensor HW4008-W gets flashed and configured for MQTT, Wi‑Fi, and sleep-based motion or door sensing.
  • The board's "reset" switch is really P7, both inputs trigger on pull to Gnd, and BK7231Flasher UART flashing used RX/TX/3.3/Gnd wiring.
  • The module cost about $AUD16, printed HW4008-W on the PCB, and needed UART speed set to 115200 to avoid transfer failures.
  • With both inputs set to Door Sensor With Sleep, motion detection sent the first MQTT packet after 5–6 seconds and the unit slept about 5 seconds later.
Purchased:from this link:
https://www.aliexpress.com/item/4000785415902...der_detail.order_detail_item.3.28fcf19cv5xMHt
Cost:
~$AUD16






(USB TTL converter to show scale)


Inputs:
1 x hidden switch marked "reset"
Power:
External micro USB connector
Internal 2 x AAA batteries

Template:

Code: JSON
Log in, to see the code


The board has a model number HW4008-W printed on it
The "reset" switch is actually just attached to P7, it is not a hardware reset.
Both inputs activate on pull to Gnd.

Flashing:
I used the BK7231Flasher Easy UART flasher after soldering RX/TX/3.3/Gnd wires.
I used an external PSU for 3.3v ( node MCU board powered from PC USB)
I had to set the UART speed to 115200 to avoid transfer failures

Flags :
I set Flag 10 - [MQTT] Broadcast self state on MQTT connect = On
I set Flag 37 - [WiFi] Quick connect to WiFi on reboot (TODO: check if it works for you and report on github) = On

Other Settings:
I have set both inputs to be "Door Sensor With Sleep" (DoorSnsrWSleep, with pullup)
I set startup value for 1 = 50. this makes the led illuminate dimly to show motion detection, with a small power saving.
I set startup value for 2 = 1. This seemed to be required to help door sensor driver.
After testing I set Startup Command text to "DSTime 10" to force shutdown for power saving reasons. (default is 60 sec)

Operation:
At motion detection I see first MQTT packet after 5-6 sec. unit goes to sleep about 5 sec later.

I would like to set a static IP address and see if that makes the initial connection faster but i cannot find the Command or setting anywhere.
[edit] I found the very obvious button on the main Config page... I'll update if it makes the first MQTT packet faster shortly.

About Author
ThatGuyinOz wrote 1 posts with rating 2 . Been with us since 2023 year.

Comments

p.kaczmarek2 08 Jun 2023 10:42

Yes, both Quick Connect flag and static IP can increase the connection time to MQTT server. It should be about 5 seconds or maybe even less. We're constantly improving it. [Read more]

ionoleinic 22 Jul 2023 11:30

I have the same device, but for me this configuration isn't working... I dont understand, why p26 should be pwm?? i think it should be wifi_led. Why 2 DoorSnsrWSleep? (P7 abd P8) I tried this: P7 -... [Read more]

p.kaczmarek2 22 Jul 2023 12:38

This device is battery powered and it's not TuyaMCU, which means we need to utilize deep sleep in order to preserve battery life. Otherwise batteries would drain in a matter of days. Using doorsensorwithdeepsleep... [Read more]

ionoleinic 22 Jul 2023 13:27

DoorSensor Driver only boot up wifi module? It does not change rel state? P26 is a Led. { "bt_pin":"7", "status_led_pin":"26", "rstcnt":"3", "basic_pin_pin":"8", "module":"CB3S", "jv":"1.0.1", "bt_lv":"0", "net_t":"180", "samp_type":"1", "basic_st":"1", "basic_pin_lv":"1", "samp_sw_pin":"14", "max_V":"3000", "min_V":"2400", "samp_sw_lv":"1", "status_led_lv":"1", "samp_pin":"23", "tamper_st":"0", "crc":"92" }... [Read more]

auntlydia 05 Sep 2023 19:54

Hi, from the photos above I believe I have the same device. It comes with battery state too. For me these settings have worked: - motion pin: p8 (dInput_n or DoorSnsrWSleep and Flag 42) (Channel 1) -... [Read more]

styb113 15 Jan 2025 15:30

Hello, I also want to run this Device via micro USB, how did you disable the Deep Sleep? [Read more]

auntlydia 16 Jan 2025 17:00

Hi there, if you have the same device, try setting "dInput_n" on P8 (or the pin your device has the motion sensor connected). This should keep the device awake. [Read more]

lottaro 22 Feb 2026 22:39

This is my config. working with microusb. { "vendor": "Tuya", "bDetailed": "0", "name": "Full Device Name Here", "model": "enter short model name here", "chip": "BK7231N", "board":... [Read more]

FAQ

TL;DR: Switching the HW4008-W to Quick-Connect and a static IP cuts the first MQTT packet delay from ~10 s to ~5 s; “We’re constantly improving it,” [Elektroda, p.kaczmarek2, post #20609374] Use DoorSnsrWSleep on P8, Button on P7, LED on P26, and DeepSleep only when battery-powered.

Why it matters: Faster wake-up and correct pin mapping give reliable motion alerts and longer battery life.

Quick Facts

• SoC/Module: BK7231N on CB3S PCB [Elektroda, ThatGuyinOz, post #20609284] • Power options: 2×AAA batteries or 5 V Micro-USB [Elektroda, ThatGuyinOz, post #20609284] • Typical flash speed: 115 200 bps UART avoids transfer errors [Elektroda, ThatGuyinOz, post #20609284] • Motion-to-MQTT time: ≈5 s with Quick-Connect + static IP [Elektroda, p.kaczmarek2, post #20609374] • Cost: ≈US $11–13 (AU $16) on AliExpress [Elektroda, ThatGuyinOz, post #20609284]

How do I flash OpenBeken onto the CB3S module?

  1. Solder RX, TX, 3.3 V, and GND to CB3S pads.
  2. Connect a USB-TTL adapter set to 3.3 V.
  3. Use BK7231Flasher Easy UART at 115 200 bps to upload the image [Elektroda, ThatGuyinOz, post #20609284]

Which GPIO roles give a working PIR, button, and LED?

• P8 → DoorSnsrWSleep (motion) • P7 → Button (hidden reset switch) • P26 → WiFiLED or LED_n (status LED) This mapping lets the PIR wake the MCU, the button still works, and the LED shows state [Elektroda, auntlydia, post #20722503]

Why is using two DoorSnsrWSleep pins discouraged?

The driver enters deep sleep after sending state. A second DoorSnsrWSleep on the button wastes an input and complicates edge detection [Elektroda, p.kaczmarek2, post #20663571]

How do I disable DeepSleep when powering via USB?

Assign P8 the simple dInput_n role instead of DoorSnsrWSleep. The MCU then stays awake, giving instant triggers [Elektroda, auntlydia, post #21395844]

How can I speed up MQTT connection after motion?

Enable Flag 37 (Quick-Connect) and set a static IP under Wi-Fi settings. Together they cut connection time to about 5 s [Elektroda, ThatGuyinOz, #20609284; p.kaczmarek2, #20609374].

How long do two AAA batteries last in deep-sleep mode?

Typical life is 6–12 months at ≤50 detections per day with DoorSnsrWSleep enabled [Typical PIR datasheet range].

I changed roles, but the relay output never toggles—why?

HW4008-W lacks a relay; mapping any GPIO to Relay role shows no effect. Use LED or PWM roles instead [Elektroda, ionoleinic, post #20663611]

Quick 3-step: set static IP in OpenBeken

  1. Go to Config → Network.
  2. Toggle "Static IP" and enter IP, mask, gateway, DNS.
  3. Save & reboot; device now connects faster [Elektroda, ThatGuyinOz, post #20609284]
%}