logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Adding a DHT22 Temperature Sensor to T34/BK7231N for Room Heating Control

Tilator 3003 19

TL;DR

  • Modified a T34/BK7231N heater controller by adding a DHT22 temperature sensor for room-temperature sensing and relay-based heating on/off control.
  • Wired the sensor to the S1/S2 external switch connector: S1 to ground, S2 to GPIO P14/pin 11, removed the sensor’s NC pin, and used jumper power for VCC.
  • Removed the pullup resistor and capacitor on P14 near the relay under marking BC8, and flashed without desoldering the CPU by soldering UART to BR4.
  • The DHT22 reported correct values immediately; a DHT11 also worked only with divider adjustments.
ADVERTISEMENT
📢 Listen (AI):
  • Modified Tuya relay controller with attached DHT22 sensor.
    Hello,

    There seems to be multiple different layouts available of this device.

    My need was to add a temperature sensor in it to make possible to measure room temperature and use the relay to connect heating on and off.

    Smart switch Tuya with DIY modification, label view.

    There is S1 and S2 connectors for external switch. I used those to connect DHT22 sensor. S1 is ground and S2 ic connected to GPIO P14, which is pin11 on the CPU. I just took the NC pin off the sensor. All three other pins are at suitable distance from each other to fit the connector.

    There is a pullup resistor and capacitor between this P14 and VCC. I took them both off. They are located near the relay under marking BC8.

    Modified Tuya relay controller with attached DHT22 sensor.

    Only VCC to the sensor needs to be addeb by jumper.

    I did not desolder the CPU to flash it. One UART wire can be soldered to the BR4 resistor at the end near number 4. For the second one I used a big and sharp normal knitting needle from my wifes reserves. I holded it at the plase simply by hand. It's easier to keep it on the right spot if it is sharp enoug.

    DHT22 sensor gives right values right away. I did try a DHT11 too and it seems to need some dividers to give correct value.

    Here is what it looks like:

    Web interface of the BK7231 controller with DHT22 sensor information

    Here is configuration:

    Screenshot of pin configuration settings for BK7231N/BK7231T controller.

    DHT22 is where originally should be BTN_TGL_ALL to act as external on/off switch.

    Related T34 topic (flashing method): https://www.elektroda.com/rtvforum/topic4036975.html
    For more info, see: https://www.elektroda.com/rtvforum/find.php?q=T34

    Cool? Ranking DIY
    About Author
    Tilator
    Level 12  
    Offline 
    Tilator wrote 130 posts with rating 13, helped 2 times. Been with us since 2023 year.
  • ADVERTISEMENT
  • #2 21095677
    p.kaczmarek2
    Moderator Smart Home
    Yes, this is a good idea. With OBK, such modifications are very easy. We've did similiar thing with DHT11 on our YT channel:
    https://www.youtube.com/watch?v=KEjOPuYd3CE
    The second modification that is worth considering is adding a IR receiver, one could be taken from any scrap board from devices like a sat tuner, etc:



    However, when it comes to IR receivers, I would first check what kind of device we're extending. That's because IR code may not work well with PowerSave, while on the other hand, some devices may straight up require PowerSave because of their low quality power supplies. That's why IR mod may be a little bit more problematic.

    By the way, now you have a temperature values read. This means you could now write some kind of simple script in autoexec.bat to control relay depending on the temperature. For example, turn on heating when it's too cold...
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md

    There is, however, one more important thing that needs to be mentioned. This particular device you have does not provide isolation from the mains, and it means that you can get live mains on like DHT11 ground pin. This means you must exercise EXTREME CAUTION while doing and using such mods. So, of course, modify only devices disconnected from mains and futhermore make sure that your DHT (or any attached sensor) is well secured and won't make contact with user... or anything else. In your case this part needs to be isolated/secured (if that's a final connection):
    Close-up of an electrical circuit with a DHT11 sensor.

    Anyway, that's a good mod, and if you need any help with extending it, let me know.
    Helpful post? Buy me a coffee.
  • #3 21095702
    Tilator
    Level 12  
    p.kaczmarek2 wrote:
    There is, however, one more important thing that needs to be mentioned. This particular device you have does not provide isolation from the mains, and it means that you can get live mains on like DHT11 ground pin. This means you must exercise EXTREME CAUTION while doing and using such mods. So, of course, modify only devices disconnected from mains and futhermore make sure that your DHT (or any attached sensor) is well secured and won't make contact with user... or anything else. In your case this part needs to be isolated/secured (if that's a final connection)


    You are right and I'm aware of it. The cap you can see is only there to demonstrate the connection. Final installation needs some glue between the parts.

    Can you tell me is it possible to read the temperature value by some http command like "http://My_Device/cm?cmnd=?????".
  • #4 21095708
    p.kaczmarek2
    Moderator Smart Home
    I think our OBK channels command should work:
    
    http://192.168.0.163/cm?cmnd=channels
    

    Please try it out and let me know if it works for you.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 21095714
    Tilator
    Level 12  
    p.kaczmarek2 wrote:
    I think our OBK channels command should work:
    
    http://192.168.0.163/cm?cmnd=channels
    

    Please try it out and let me know if it works for you.


    Thanks.
  • ADVERTISEMENT
  • #6 21179203
    Tilator
    Level 12  
    Hello again,

    There seems to be DS18B20/DS1820 support available now.

    Thank you again. This was good add on it.

    I have not tested it yet, but will do it as soon as I have a bit spare time.
  • #7 21180233
    p.kaczmarek2
    Moderator Smart Home
    I'm eager to hear some feedback! Please try and let know.

    PS: Don't use PowerSave 1 with it.
    Helpful post? Buy me a coffee.
  • #8 21223436
    divadiow
    Level 38  
    @Tilator does your DHT22 give readings still with the latest builds? I don't suppose you ever took a pic of the PCB inside the casing? I'm just curious about my one which doesn't seem to work with OBK but does with Tasmota. Maybe mine is fake and the Tasmota driver has different tolerances or something

    Close-up of a PCB with visible electronic components.
  • ADVERTISEMENT
  • #9 21223462
    Tilator
    Level 12  
    divadiow wrote:
    @Tilator does your DHT22 give readings still with the latest builds? I don't suppose you ever took a pic of the PCB inside the casing? I'm just curious about my one which doesn't seem to work with OBK but does with Tasmota. Maybe mine is fake and the Tasmota driver has different tolerances or something


    At least version version 1.17.661 works fine.

    Pictures are available if they anyhow help you.
  • #10 21237109
    Tilator
    Level 12  
    p.kaczmarek2 wrote:
    I'm eager to hear some feedback! Please try and let know.


    Now I had time to try it, but DS18B20 sensor does not come available.

    There are at least two different physical configurations to install this sensor. Which one should I use?

    I installed it by connecting GND + VDD to ground and mid pin to GPIO. Does it need to have power from VDD pin or should GPIO power it as it's supposed to do in this "two wire" connection?
  • #12 21237369
    Tilator
    Level 12  
    >>21237328

    I did try that too without good outcome.

    I have this T34 SOC and I try to use GPIO 11 which is UART TX. Might there be some setting wrong related to that?

    Added after 5 [hours] 11 [minutes]:

    Seems I can't get it working. I did try a couple different pull up resistors and I also tried two different GPIOs. DHT22 sensor works fine connected to both of them, but DS18B20 does not connected to either.
  • #13 21237883
    p.kaczmarek2
    Moderator Smart Home
    So, to sum up, you are using GPIO 11 which is UART TX and:
    - DHT22 works there
    - LED (to blink it, as Rel role or LED role) works as well
    - but DS18B20 doesn't work?

    Added after 34 [seconds]:

    Maybe you have PowerSave on and need to try turning it off?
    Helpful post? Buy me a coffee.
  • #14 21237985
    Tilator
    Level 12  
    p.kaczmarek2 wrote:
    So, to sum up, you are using GPIO 11 which is UART TX and:
    - DHT22 works there
    - LED (to blink it, as Rel role or LED role) works as well
    - but DS18B20 doesn't work?


    Yes, and on top of thet GPIO 9 works with DHT22 too but not with DS18B20.

    p.kaczmarek2 wrote:

    Maybe you have PowerSave on and need to try turning it off?


    How can I find out if it's on?
  • #16 21238199
    Tilator
    Level 12  
    >>21238012

    Can you tell does the driver give sensor enough power by pulling GPIO line up or does it still need other external power and pull up resistor?
  • #17 21238801
    Tilator
    Level 12  
    I took one of those mini relays having BK7231N and connected DS18B20 to it using GBIO 9. Still no temperature reading.

    If I add sensor usin WEB UI there happens nothing. No loaded driver listed on front page. If I put a startup command "startdriver DS1820 9" and reboot it does load driver but temperature reading is always same -1,26 C or something like that.

    I did try one wire connection having only ground and data connected and VDD connected to ground. Then I did try "two wire" connection having power connected to VDD with or without pull up resistor.

    Always same result. T34 device has a power metering component, but this latter device doesn't even have it.

    B.T.W: I made a little modification to make it easier to try adding this sensor. Here are pictures about it in case someone is interested: Small, bent wire on a white surface next to a black handle tool. The image shows the back of a green circuit board with a soldered wire. Colorful circuit board with a thin leg soldered onto it.

    In the first picture there is a tiny "hook". It's originally a leg from one DHT22 sensor. It is narrow enough, soft to bend and easy material to solder.

    In second picture this hook has been soldered to pin 25 (GPIO 9) and third picture has a drop of super glue to attach it firmly.
  • #18 21238822
    divadiow
    Level 38  
    >>21238199

    still requires external power afaik
    so, 3.3v, gpio and ground. 4.7kohm between data and vcc.
  • #19 21238824
    Tilator
    Level 12  
    divadiow wrote:
    >>21238199

    still requires external power. 3.3v, gpio and ground. 4.7kohm between data and vcc.


    Thanks.

    A bit new info:

    I got some readings from BK7231N device and the tric was to give it a bit higher voltage. 4,75V. Even thogh the values it gove were a bit high somewhere above 33 C while actual temperature is about 10 degrees lower.

    Stll nothing from T34. Not even using higher voltage.

    The driver seems to act a bit different for different platforms. Is it sure, it recognizes T34 based platform right? Should it act as a BK7231N too?

    I made some more testing using both those devices and result is same for them: Giving the sensor 3,3V and nothing happens. Giving 4,75V and it comes up. 4,7k pull up resistor in all tests.

    ************************
    Still more testresults:

    It works with 3,3V too if it is set up in both the WEB UI and startup command. Start up command can even be set to a wrong GPIO.

    Does it sound like a timing problem?
    *************************

    B.T.W: How can temperature value be read as a HTTP request?
  • #20 21348605
    Tilator
    Level 12  
    What's this in log:

    Info:SENSOR:DHT start, pin is 6
    Info:SENSOR:DHT checksum failure!

    it keeps repeting about once every second.
📢 Listen (AI):

Topic summary

✨ The discussion focuses on integrating a DHT22 temperature sensor with T34/BK7231N-based devices for room heating control via relay switching. The user connected the DHT22 sensor to S1 (ground) and S2 (GPIO P14/pin 11 CPU) after removing a pull-up resistor and capacitor near the relay (marked BC8). The device firmware supports reading temperature values, enabling relay control through scripts (e.g., autoexec.bat). HTTP commands like "/cm?cmnd=channels" can retrieve sensor data. Later, DS18B20 sensor support was introduced, but users reported difficulties with DS18B20 on T34 devices, including no temperature readings despite correct wiring and driver loading. DS18B20 requires external 3.3V power, ground, data line with a 4.7kΩ pull-up resistor; some users found better results with slightly higher voltage (~4.75V). PowerSave mode may interfere with sensor operation, especially for IR receivers and DS18B20. DHT22 works reliably on GPIO pins including UART TX (GPIO 11) and GPIO 9, while DS18B20 does not. Firmware versions (e.g., 1.17.661) support DHT22 well. Troubleshooting includes checking power supply, pull-up resistor presence, GPIO configuration, and disabling PowerSave. Error logs show occasional DHT checksum failures. Modifications to the PCB and sensor connections were shared with photos for community reference.

FAQ

TL;DR: Adding a DHT22 or DS18B20 sensor to the T34/BK7231N gives ±0.5 °C room-temperature readings and relay control; “such modifications are very easy” [Elektroda, p.kaczmarek2, post #21095677] Use GPIO14 (S2) or GPIO9/11, disable PowerSave, and keep a 4.7 kΩ pull-up [ASAIR AM2302 Datasheet].

Why it matters: One low-cost board can now sense, decide and switch your heating without cloud dependency.

Quick Facts

• BK7231N logic level: 3.3 V [Beken Datasheet]. • DHT22 range −40 – 80 °C, ±0.5 °C accuracy [ASAIR AM2302 Datasheet]. • DS18B20 supply 3.0 – 5.5 V, needs 4.7 kΩ pull-up, 12-bit resolution [Maxim DS18B20 Datasheet]. • OBK HTTP: /cm?cmnd=channels returns JSON with sensor values [Elektroda, 21095708] • T34 relay rating: typical SRD-05 10 A @ 250 VAC [SONGLE Datasheet].

Which T34/BK7231N pins do I use for a DHT22 sensor?

S1 provides GND and S2 goes to GPIO14 (CPU pin 11); add 3.3 V from VCC to the sensor and remove the on-board pull-up/cap at BC8 [Elektroda, Tilator, post #21095664]

Can the external switch header be reused without cutting traces?

Yes. The 3-pin S1/S2 header spacing matches DHT22/DS18B20 leads. Slide the sensor pins in and jumper VCC from the nearest 3.3 V pad [Elektroda, Tilator, post #21095664]

How do I wire a DS18B20 correctly?

  1. Connect VDD to 3.3 V, GND to GND. 2. Join the data pin to GPIO9 or GPIO11. 3. Place a 4.7 kΩ resistor between data and VDD. The sensor needs external power; parasitic two-wire mode fails on this board [Elektroda, divadiow, post #21238822]

Why does DS18B20 show –1.26 °C or stay offline?

OBK reports –1.26 °C when no response is received. Causes: missing 4.7 kΩ pull-up, PowerSave enabled, or supply below 3 V. Tilator restored readings after raising VDD to 4.75 V and disabling PowerSave [Elektroda, 21238824]

How do I auto-switch the relay when the room gets cold?

Create /autoexec.bat:
  1. startDriver DHT22 14
  2. if $CH1<20 then backlog power 1; delay 600; power 0 Upload and reboot; the script re-runs every minute [OBK autoexecExamples].

Is the T34 safe to touch after the mod?

No. The board lacks mains isolation; GND may sit at live potential. Insulate the sensor and wiring with heat-shrink or epoxy and work only when unplugged [Elektroda, p.kaczmarek2, post #21095677]

Can I flash OBK without removing the MCU?

Yes. Solder RX to BR4, press a sharp probe on TX, and use 3.3 V UART at 115 200 bps. Tilator flashed this way successfully [Elektroda, 21095664]

What accuracy should I expect?

DHT22: ±0.5 °C, 2 %RH. DS18B20: ±0.5 °C from –10 °C to +85 °C [ASAIR AM2302 Datasheet; Maxim DS18B20 Datasheet].

Edge case: Log shows “DHT checksum failure!” every second—what now?

Checksum errors point to long leads or noise. Shorten wires, add a 100 nF cap across VCC-GND and keep leads under 20 cm. Replace if humidity has corroded pads [Elektroda, Tilator, post #21348605]
ADVERTISEMENT