Labs / Electronic modules

GraftSense - Common Relay Module Based on HF46F (Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation, v1.3 · License: CC BY 4.0 · Driver code (misc/relay_driver): MIT License

Contents
HF46F
LED1 R1 R2 R3 R4 R5 R6 C1 C2 U1

I. Module Introduction

Ordinary relay module based on HF46F Ordinary relay module based on HF46F-G , the core is composed of HF46F-G ultra-small medium power relay, PC817 optocoupler, transistor drive circuit, etc.

On the right side of the module, there are GND / VCC power supply interfaces, a NC (normally closed) pin and a DOUT control interface. The A / B terminals at the bottom can be connected to an external load, enabling convenient on-off control of high-power circuits via digital signals, which is both safe and practical.

II. Introduction to Main Chips

2.1 Chip Overview

2.1.1 HF46F-G Ultra-compact Medium-power Relay

HF46F-G 20.5 7.2 15.3mm 10A 7.2mm 10kV VDE0631 200mW

2.1.2 PC817 Optocoupler Isolation Chip

PC817 is a commonly used optocoupler, whose core consists of a GaAs light-emitting diode and an NPN phototransistor. It realizes electrical isolation between circuits through the "electricity-light-electricity" signal conversion (this is the core function of an optocoupler, which can isolate high and low voltages and suppress circuit interference).

PC817 2.54mm

2.2 Pin Definition

2.2.1 HF46F-G Ultra-compact Medium-power Relay

HF46F-G HS1 20.5mm 15.3mm 0.8mm 11.5mm

From the wiring diagram of the bottom view of the HF46F-G relay, it can be seen that its pins are divided into two categories: coil pins and contact pins:

2.2.2 PC817 Optocoupler Isolation Chip

PC817 1 2 3 4

PC817 the pinout definition of the optocoupler is consistent across DIP and SOP packages, with a total of 4 pins, whose functions are as follows:

In use, pins 1 and 2 are connected to a control signal (to drive the light-emitting diode to emit light), and pins 3 and 4 are connected to the load circuit (to receive the optical signal and convert it into an electrical signal for output), thereby achieving electrical isolation between the control end and the load end.

2.3 Functional Block Diagram

2.3.1 HF46F-G Ultra-compact Medium-power Relay

None.

2.3.2 PC817 Optocoupler Isolation Chip

None.

2.4 Performance Parameters

2.4.1 HF46F-G Ultra-compact Medium-power Relay

HF46F-G

HF46F-G The key performance parameters of the relay can be understood from three aspects: contacts, coil, and insulation/mechanical properties:

HF46F-G 250VAC AgSnO2 10A 7A

These three performance curves respectively reflect HF46F-G the operating characteristics of the relay in different dimensions:

2.4.2 PC817 Optocoupler Isolation Chip

PC817 25

This table presents PC817 the maximum absolute ratings of the optocoupler at room temperature (25℃), and each parameter should be understood in combination with its structure of "light-emitting diode (input) + phototransistor (output)":

PC817

This table presents PC817 optocoupler's optoelectronic characteristics at room temperature (25°C), and the meaning of each parameter should be understood in combination with its "light-emitting diode - phototransistor" structure:

PC817 50 100 80 160 130 260 200 400 300

CTR refers to the conversion efficiency of an optocoupler from "input light-emitting diode current to output photosensitive transistor current (CTR = IC/IF × 100%), and different grades correspond to different conversion efficiency ranges:

PC817 7 8 5mA 5V 30 100 25 60 20mA

These two characteristic curves reflect the influence of ambient temperature on PC817 the core parameters of the optocoupler:

9 PC817 20V 25 100 10

These two characteristic curves respectively reflect the influences of ambient temperature and load resistance on PC817 optocoupler's key parameters:

PC817

This set of diagrams illustrates PC817 the frequency response characteristics of the optocoupler and the corresponding test circuit, with analysis combined with the meaning of the parameters as follows:

Together with the circuit, these curves clearly demonstrate that the high-frequency transmission capability of the PC817 is affected by the load resistor: a smaller load resistor can increase its bandwidth, and the test circuit serves as the standard configuration for verifying these dynamic characteristics.

2.5 Reference Circuit

2.5.1 HF46F-G Ultra-compact Medium-power Relay

None.

2.5.2 PC817 Optocoupler Isolation Chip

None.

2.6 Chip Configuration

2.6.1 HF46F-G Ultra-compact Medium-power Relay

None.

2.6.2 PC817 Optocoupler Isolation Chip

None.

2.7.1 HF46F-G Ultra-compact Medium-power Relay

None.

2.7.2 PC817 Optocoupler Isolation Chip

None.

2.8 PCB Routing Notes

2.8.1 HF46F-G Ultra-compact Medium-power Relay

None.

2.8.2 PC817 Optocoupler Isolation Chip

None.

3. Instructions for Circuit Engineering and Module Usage

3.1 Circuit Source Engineering

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

3.2 Module Usage Instructions

The schematic diagram is shown as follows:

SCH_General Relay Module Based on HF46F_v1.0_2025-11-26.pdf 2.3 MB

HF46F Q2 S9013 Q1 U1 U2 U3 U4 U5 U6
v1.0

This module provides the DOUT interface:

When in use, we can just connect them in the following form:

HF46F Q2 S9013 U1 U2 U3 U4 R1 R7 C1

The detailed analysis and explanation of the circuit principle are as follows:

SS8550
PC817 S9013 R1 R2 S8550

At the same time, we also tested the relevant power:

HF46F 0.09W 0.30W

3.3 Application Experiment

Here, we use the GraftPort-RP2040 development board for testing, and connect the common relay module based on HF46F to communicate with the main controller via the DIO interface.

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

HF46F GraftPort-RP2040 3.3

The module connections are shown in the following table:

Development Board Pins

Module Pins

Description

Pin 14

DOUT

The pins connected to the MCU output high and low levels.

Pin 15

NC

-

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

106

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

1.0.0 2020 2 12

Click to copy the local installation command:

168 1.0.0

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

mpremote mip install github:FreakStudioCN/GraftSense-Drivers-MicroPython/misc/relay_driver

After importing the relay module driver - MicroPython driver code, copy the following main.py code into our project:

# Python env   : MicroPython v1.23.0
# -*- coding: utf-8 -*-
# @Time    : 2024/7/28 3:00 PM
# @Author  : Li Qingshui
# @File    : main.py
# @Description : Relay test example

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

# Import time-related modules
import time
# Import the relay module
from relay import RelayController

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

# If it is a 'normal' type relay, use GP14
RELAY_TYPE = 'normal'   # 'normal' or 'latching'
RELAY_PIN1 = 14           # Control pin 1
RELAY_PIN2 = 15           # Control pin 2

# Music rhythm definition (unit: ms)
# Each tuple represents (duration, whether to toggle at the end)
MUSIC_NOTES = [
    # Strong rhythm in the intro
    (50, True), (50, False), (50, True), (50, False),  # 4 fast consecutive beats
    (100, True), (100, False),  # Slow down for 2 beats
    (50, True), (50, False), (50, True), (50, False),  # Repeat 4 fast beats

    # Verse section
    (150, True), (50, True), (200, False),  # Strong-light-long pause
    (100, True), (100, True), (100, True), (100, False),  # Three consecutive hits
    (80, True), (80, True), (160, False),  # Double beat + long pause
    (60, True), (60, True), (60, True), (60, True), (120, False),  # Four fast consecutive hits

    # Chorus climax
    (40, True), (40, False), (40, True), (40, False),  # Ultra-fast eighth notes
    (40, True), (40, False), (40, True), (40, False),
    (200, True), (200, False),  # Strong downbeat
    (300, True), (100, True), (200, False),  # Long-short combination

    # Bridge tempo change
    (120, True), (80, True), (120, True), (80, False),
    (200, True), (50, True), (50, True), (200, False),

    # Ending slows down gradually
    (150, True), (150, False),
    (200, True), (200, False),
    (300, True), (300, False)
]
# ======================================== Functions ============================================

# Simple music playback function
def play_relay_music():
    for duration, should_toggle in MUSIC_NOTES:
        # Toggle the relay state
        relay.toggle()
        time.sleep_ms(duration)
        if should_toggle:
            # Toggle back again
            relay.toggle()
            # Add a small interval to prevent toggling too fast
            time.sleep_ms(50)

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

# ======================================== Initialization ==========================================

# Power-on delay of 3 s
time.sleep(3)
# Print debug information
print("FreakStudio: Using GraftPort to control relay")

# Initialize the relay controller
if RELAY_TYPE == 'latching':
    relay = RelayController(RELAY_TYPE, RELAY_PIN1, RELAY_PIN2)
else:
    relay = RelayController(RELAY_TYPE, RELAY_PIN1)

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

# Turn on the relay
relay.on()
print('relay.on')
# Delay 1s
time.sleep(5)
# Turn off the relay
relay.off()
print('relay.off')

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

GraftSense - Common Relay Module Based on HF46F (Open Version)

We can hear that the relays close and release in a certain regular pattern, just like music.

It can be observed that when the relay is closed, the motor starts to rotate; after 5 seconds, the relay opens and the motor stops.

IV. Drivers

relay_driver.zip 11 KB

None.

VI. Revision History

Document Version

Date of Revision

Modifier

Modify Content

v1.0

2025-11-26

Li Zisheng

Initialize the document

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.1

2025-12-29

Li Zisheng

Added application experiments and production files

v1.2

2025-12-31

Xin Ruili

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

v1.3

2026-03-29

Xin Ruili

Modified the application experiment section

VII. Relevant Materials

7.1 Chip Datasheet

C3008369_Transistor Output Optocoupler_PC817C-S_Datasheet_WJ644212.PDF 461 KB

C5274026_Power Relay_HF46F-G-5-HS1T_Datasheet_WJ36712.PDF 126 KB

7.2 Unique Icons for PCB Silk Screen

HF46F