Labs / Electronic modules

GraftSense - PT334-based Flame Sensor Module (Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation, v1.4 · License: CC BY 4.0 · Driver code (sensors/flame_driver): MIT License

Contents
PT334 LM393
PT334 U2 LED1 R1 R8 C1 C4 v1.1

I. Module Introduction

The flame sensor module based on PT334 takes PT334-6B as the core sensing element, is equipped with circuits including the LM393 comparator, operates on a + 5V power supply, and can simultaneously output digital signals (DIN) and analog signals (AIN). It can effectively detect flames, is easy to interface with devices such as microcontrollers, and is suitable for flame detection application scenarios.

II. Introduction to Major Chips

2.1 Chip Overview

PT334-6B is a high-speed, high-sensitivity NPN phototransistor encapsulated in black epoxy resin, which is sensitive to infrared radiation and can be applied in infrared application systems, cameras, printers and other devices.

2.2 Pin Definition

DY-PT334-6B 0.25mm 2.2

2.3 Functional Block Diagram

None.

2.4 Performance Parameters

PT334 25 RH60
PT334 0 25 75mW 85 700nm 1300nm 900nm PT334-6B
PT334-6B 1 2 3 4
PT334 30V 5V 20mA
PT334 2 30W 300 3
PT334

2.5 Reference Circuit

None.

2.6 Chip Configuration

None.

None.

2.8 PCB Routing Precautions

None.

III. Circuit Engineering

3.1 Circuit Source Engineering

To obtain the source project of the circuit, please follow the official account [Freak Embedded]

3.2 Module Usage Instructions

The schematic diagram of this module is shown below:

SCH_Flame Sensor Module Based on PT334_v1.1_2025-10-09.pdf 2.3 MB

PT334 LED2 LED3 R1 R2 R3 C1 C2 U2 LED1
PT334 v1.1

It also features a dual indicator design: the power indicator (LED2) remains steadily on to indicate the module is powered on; the flame indicator (LED3) lights up to indicate that flame is detected.

This module adopts digital output DIN: which can output the flame detection result in the form of high and low levels. When a flame is detected, after being compared with the reference voltage by the LM393 comparator, the DIN terminal will output a low level; otherwise, it will output a high level.

PT334 LED1 PT334-6B C2 100nF U2.1 LM393 3 2 R1
PT334 5V R6 4.7k LED2 NCD0603G1 LED3 C3 10 C4

The core circuit consists of a flame sensor probe and LM393 comparator:

3.3 Application Experiment

Here, we use the GraftPort-RP2040 development board for testing, and the PT334-based flame sensor module uses the AIN interface to communicate with the main controller.

Here, we first use the HY2.0-4P cable to connect the module to the GraftPort-RP2040 development board's AIN0 interface:

PT334 GraftPort-RP2040 AIN0 R1

The module connections are shown in the following table:

Development Board Pins

Module Pins

Description

Pin 26

AIN

Analog Output of Flame Sensor

Pin 19

DIN

Digital output of the flame sensor analog signal after passing through the comparator

Based on the PT334 flame sensor working principle (the sensor realizes induction by detecting the specific infrared radiation released by the flame), the core function of the adjustable resistor on the module (i.e. R1 in the figure win the bidding) is to set the detection threshold : the smaller the resistance value (usually adjusted clockwise), the lower the trigger threshold of the sensor and the more sensitive it is to the flame; the larger the resistance value (adjusted counterclockwise), the stricter the trigger conditions and the stronger the ability to resist environmental stray light interference.

First, turn this adjustable resistor clockwise to gradually lower the trigger threshold until the sensor's trigger indicator LED2 lights up — at this point, the ambient infrared signal (or the target flame signal) just reaches the sensor's trigger critical state; to avoid false triggers caused by ambient stray infrared light, then gently turn the adjustable resistor counterclockwise for a slight adjustment, and wait until LED2 goes out, the sensor's threshold will accurately fall within a reasonable range that "approaches the flame trigger condition while being able to avoid false triggers".

PT334 R1

Here, we need to search for the relevant driver packages on uPyPI: https://upypi.net/zh/

106

Enter flame_driver to search, and the following will be displayed:

1.0.0 2020 2 12

Click to copy the local installation command:

1.0.0 2020 2 12 PT334

Here, we can use the mip tool to import module driver library code. The following are the usage commands for the mpremote tool:

mpremote mip install github:FreakStudioCN/GraftSense-Drivers-MicroPython/sensors/flame_driver

Import the flame sensor module based on PT334 - MicroPython driver code, then copy the following main.py code into our project:

# MicroPython v1.23.0
# -*- coding: utf-8 -*-   
# @Time    : 2025/8/23 5:55 PM
# @Author  : 缪贵成
# @File    : main.py
# @Description : Flame sensor driver test file

# ======================================== Import Modules =========================================

import time
from machine import Pin
from flame_sensor import FlameSensor

# ======================================== Global Variables =============================================

# ======================================== Functions =============================================

def flame_detected_callback() -> None:
    """
    Flame detection callback function. Called by micropython.schedule when the digital pin DO triggers.

    Notes:
        The callback runs in the main thread, so it is safe to print or control the LED.

    ==========================================

    Callback function triggered on flame detection.
    Called by micropython.schedule when digital pin DO triggers.

    Notes:
        Safe to perform printing or LED control in main thread.
    """
    print("Flame detected!")

# ======================================== Custom Classes =============================================

# ======================================== Initialization configuration ===========================================

print("FreakStudio:Testing Flame Sensor")
time.sleep(3)

# Initialize the flame sensor object, assuming the analog output pin is 26 and the digital output pin is 19
flame_sensor = FlameSensor(analog_pin=26, digital_pin=19, callback=flame_detected_callback)
# Enable the digital pin interrupt
flame_sensor.enable()

# ======================================== Main Program ==============================================

print("=== Flame Sensor Initialized. Monitoring AO voltage... ===")

try:
    while True:
        # Get the AO analog value and convert it to voltage
        voltage = flame_sensor.get_voltage()
        print("AO Voltage: {:.2f} V".format(voltage))
        time.sleep(1)
except KeyboardInterrupt:
    print("=== Test Stopped by User ===")
    flame_sensor.disable()

Burn the code, open the terminal, and use the mpremote tool to connect to the main controller. The output is as follows:

PT334 3.30 3.30V

As you can see, when the flame of a lighter triggers our sensor module, the trigger callback will print on the terminal Flame detected!

IV. Drivers

flame_driver.zip 12 KB

None.

VI. Revision History

Document Version

Date of Modification

Modifier

Modified Content

v1.0

2025-08-31

Hou Junhan

Ling Gaoxing

Complete the initial design and the preparation of hardware documents

v1.1

2025-10-09

Li Zisheng

Added PCB routing precautions for Version 2.8

Revised Section 3, Instructions for Circuit Source Project and Module Usage, and added a secondary heading:

3.1 Circuit Source Engineering, 3.2 Module Usage Instructions, 3.3 Application Experiments

The BOM sheet has not been finally checked, the driver has not been re-verified, and the 3.3 application experiment

Not yet specified.

v1.2

2025-12-29

Li Zisheng

Added application experiments and production files

v1.3

2025-12-31

Xin Ruili

Create an open version of the document based on the internal document version v1.2.

v1.4

2026-03-29

Xin Ruili

Modified the application experiment section

VII. Relevant Materials

7.1 Chip Datasheet

PT334 Datasheet.pdf 497 KB

C351428_Comparator_LM393_Datasheet_WJ131819.PDF 1.0 MB

7.2 Unique Icons for PCB Silkscreen

PT334