使用WiFi Node MCU和继电器模块控制家庭灯光的物联网项目

2025年4月25日 | 3 分钟阅读

在这个项目中,我们将使用Wi-Fi网络或互联网(移动数据)构建一个家庭灯光控制系统。通过这个项目,我们可以从世界任何地方控制我们的家庭灯光。在这个项目中,我们将使用Wi-Fi Node MCU、4通道继电器模块等。

硬件要求

  1. Wi-Fi Node MCU ESP8266
  2. 标准USB电缆,用于连接Node MCU
  3. 4通道继电器模块 (5V)
  4. 跳线,母对母
  5. 家庭灯 (灯泡)
  6. 灯泡座
  7. Wire
  8. 交流 220v/120v 家用电器或 9v 高瓦特电池

软件要求

  1. Arduino 软件
  2. Blynk应用程序

该项目的工作原理 (Node MCU, 继电器模块)

在这个项目中,使用了三个主要组件:Android Blynk应用程序、Wi-Fi Node MCU和4通道继电器模块。

IoT project of controlling home light using WiFi Node MCU, and Relay module

Android Blynk应用程序通过单击ON按钮将串行数据发送到Wi-Fi Node MCU。 Wi-Fi Node读取输入数据并根据上传到其中的程序进行处理,并向4通道继电器模块生成输出。

当Blynk应用程序的按钮打开时,它会打开家庭灯,当Blynk应用程序的按钮关闭时,它会关闭家庭灯。

从Play商店下载Blynk应用程序并将其安装在您的设备上。

IoT project of controlling home light using WiFi Node MCU, and Relay module IoT project of controlling home light using WiFi Node MCU, and Relay module
IoT project of controlling home light using WiFi Node MCU, and Relay module IoT project of controlling home light using WiFi Node MCU, and Relay module
IoT project of controlling home light using WiFi Node MCU, and Relay module IoT project of controlling home light using WiFi Node MCU, and Relay module
IoT project of controlling home light using WiFi Node MCU, and Relay module IoT project of controlling home light using WiFi Node MCU, and Relay module
IoT project of controlling home light using WiFi Node MCU, and Relay module IoT project of controlling home light using WiFi Node MCU, and Relay module
IoT project of controlling home light using WiFi Node MCU, and Relay module IoT project of controlling home light using WiFi Node MCU, and Relay module
IoT project of controlling home light using WiFi Node MCU, and Relay module

一个用Arduino IDE编写的程序,用于使用WiFi Node MCU、4通道继电器模块控制家庭灯

将电路板类型添加到您的Arduino IDE

如果之前未添加电路板类型,请将其添加到您的Arduino IDE。转到文件 > 首选项 > 设置,并将http://arduino.esp8266.com/stable/package_esp8266com_index.json添加到“附加电路板管理器URLs”中,然后单击“确定”。

IoT project of controlling home light using WiFi Node MCU, and Relay module

在编译上述代码之前,包含esp8266 board community,否则会生成错误。

要包含库,请单击工具 > 板 > 板管理器...

IoT project of controlling home light using WiFi Node MCU, and Relay module

搜索esp8266并安装它。

IoT project of controlling home light using WiFi Node MCU, and Relay module

选择您的电路板类型

现在,选择您的电路板类型,转到工具 > 板: > NodeMCU 1.0

IoT project of controlling home light using WiFi Node MCU, and Relay module

添加库

https://github.com/blynkkk/blynk-library/releases/latest下载最新的Blynk库并将其添加到程序中

IoT project of controlling home light using WiFi Node MCU, and Relay module

如果无法在您的程序中添加Blynk库,请将其解压缩并将所有目录粘贴到Arduino库的C:\Program Files (x86)\Arduino\libraries中。

现在,使用标准USB电缆将Node MCU设备与您的个人计算机连接,以连接Node MCU并在其中上传程序。

IoT project of controlling home light using WiFi Node MCU, and Relay module

数字电路图

4通道继电器模块              Node MCU

GND   -------------------------------->      GND

IN1   -------------------------------->     D0

IN2   -------------------------------->     D1

IN3   -------------------------------->     D2

IN4   -------------------------------->     D3

VCC   -------------------------------->     Vin

继电器模块、灯泡和输入电源之间的连接

  1. 将继电器模块的公共点 (com) 连接到家庭灯。
  2. 将继电器模块的常开 (no) 连接到电源。
  3. 将剩余的一根家庭灯线与电源连接。

该项目已使用Wi-Fi和移动数据运行。

输出

IoT project of controlling home light using WiFi Node MCU, and Relay module IoT project of controlling home light using WiFi Node MCU, and Relay module