Labs / Bipes + MicroPython / 8 Actuators (Outputs / Actuators)

8.8 Control Home Appliances with a Development Board? Safely Switch Table Lamps and Fans! โ€”โ€” A General Relay Module Based on the HF46F

Author: Li Zisheng ยท Source: FreakStudio open documentation ยท License: CC BY 4.0

Contents

Young makers, today let's unlock a "safe switch capable of controlling high current" ๐Ÿ”Œ!

The pins of a development board can only withstand small currents and cannot directly drive high-current devices such as motors and bulbs. However, a common relay module based on the HF46F acts like a "remote control for high-current devices": the development board only needs to send a weak electrical signal to make it snap closed, thereby connecting the high-current circuit โ€” it is both safe and reliable โœจ!

1. Module Introduction

Want to make power-hungry devices like motors and bulbs follow the commands of your development board? A relay is your go-to "safety assistant" for this job!

It is an electromagnetic switch module with the compact HF46F electromagnetic relay as its core component: when the development board inputs a low-current signal to the relay, the internal electromagnet will pull in the contacts to close the high-current circuit (such as the power supply for a motor); when the signal is cut off, the electromagnet releases, the contacts spring open, and the high-current circuit is disconnected accordingly. Simply put, it is a "switch that controls high current with low current".

Compared with direct drive, it has the following characteristics:

In graphical programming, these blocks are commonly used for relays:

In practical projects, it is often used for the following purposes:

Popular Science: What is an Electromagnetic Relay?

A relay contains an electromagnet and a set of metal contacts inside. When the development board supplies power to the electromagnet, the electromagnet generates magnetic force to pull in the contacts, just like pressing the "power switch" of a high-current device; when the power is cut off, the magnetic force disappears, the contacts spring open, and the device is powered off. Throughout this process, the development board only acts like "pressing a remote control" and never directly touches the "high-current socket", making it extremely safe!

2. Wiring Instructions

To make a relay "obedient", the first step remains the same: connect the wires correctly!

We will connect in the following manner:

8.8 Control Home Appliances with a Development Board? Safely Switch Table Lamps and Fans! โ€”โ€” A General Relay Module Based on the HF46F

We will connect the common relay module based on HF46F to the digital interface DIO0 of the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

Pin 6

DOUT

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

Pin 7

NC

-

๐Ÿ“Œ Note

3. Example: Control the motor to stop after rotating for 5 seconds

Test Objective: Energize the relay for 5 seconds to drive the motor to run for 5 seconds before automatically stopping, so as to intuitively experience the safety effect of "small signal controlling large current".

Everyday Insight: The smart plug at home lets you control the on/off of appliances via your phone, which works on a relay principle similar to this. Now let's make a "tiny switch that can control a motor on a timer" ourselves!

The graphical program is as follows:

8.8 Control Home Appliances with a Development Board? Safely Switch Table Lamps and Fans! โ€”โ€” A General Relay Module Based on the HF46F

Building Block Assembly Steps:

  1. Pull-in Relay (Starter Motor)
    • Drag in the set output pin block;
    • Selected Pin: Pin 9 / GPIO6 (corresponding to DIO0 interface);
    • Set to true โ†’ the relay closes and the motor starts running;
  2. Set rotation duration
    • Drag in the delay block and set it to 5 seconds โ†’ make the motor rotate continuously for 5 seconds;
  3. Release the relay (stop the motor)
    • Drag in another set output pin block;
    • Pin retention Pin 9 / GPIO6;
    • Set to false โ†’ the relay is de-energized and the motor stops running.

Experimental Effect:

C2177.MP4 64.0 MB

Graphical blocks will be automatically converted into MicroPython code, and the running results will be displayed:

8.8 Control Home Appliances with a Development Board? Safely Switch Table Lamps and Fans! โ€”โ€” A General Relay Module Based on the HF46F

Directly importable building blocks:

Relay (2).xml 2 KB

Tips

  1. If the relay fails to pull in / the motor does not rotate:
    • Check whether the pins are selected correctly (Pin 9 / GPIO6) and whether the wiring is secure;
    • Verify that the 5V power supply is normal and check whether the motor is stuck by foreign objects;
    • Listen for a "click" sound of the relay pulling in; if there is no such sound, check whether the control signal is normal.
  2. Safety Note:
    • Relays control high-current equipment. Always disconnect the power supply before wiring to avoid electric shock;
    • Do not use a relay to control devices with a current exceeding its rated current (the maximum current of HF46F is typically 1A).
  3. Advanced Gameplay:
    • When paired with a touch key module, it realizes the function of "start the motor as soon as touched, stop it as soon as released";
    • Paired with a light sensor, it will automatically engage the relay to turn on the light when the ambient light is dim.

โœจ Interactive Quiz

  1. Think about it: Why can't we directly use the pins of the development board to drive the motor, but have to use a relay instead?
  2. Try it: Change the delay time from 5 seconds to 10 seconds, and see what changes will happen to the motor rotation duration? Then change it to 2 seconds to experience different control effects.

Summary

  1. The common relay module based on HF46F is an electromagnetic switching module that can realize "controlling high current with small signals";
  2. It switches the contacts on and off via electromagnetic attraction and release, providing safe isolation between the development board and high-current devices to prevent the development board from being burned out.
  3. The basic application is simple control following the sequence of "pull-in โ†’ time delay โ†’ release", while the advanced application enables smart switching in combination with sensors;
  4. It is an essential module for controlling high-current devices such as motors and lights, which is safe and practical.