Arduino - 继电器

news2024/9/21 20:46:26

Arduino - 继电器

In a previous tutorial, we have learned how to turn on/off an LED. In this tutorial, we are going to learn how to turn on/off some kind of devices that use the high voltage power supply(such as a light bulb, fan, electromagnetic lock, linear actuator…).
在之前的教程中,我们学习了如何打开/关闭 LED。在本教程中,我们将学习如何打开/关闭某种使用高压电源的设备(例如灯泡、风扇、电磁锁、线性执行器等)。

How To Scan Keypad
如何扫描键盘

What are the common and difference between controlling LED and controlling a light bulb?
控制LED和控制灯泡有什么共同之处和区别?

The common: Just like controlling LED, we use the Arduino’s output pin to turn on/off them.
共同点:就像控制LED一样,我们使用Arduino的输出引脚来打开/关闭它们。

The difference: 区别:

  • For LED, we can use power from the Arduino board (≤ 5v). Therefore, we can connect LED directly to Arduino’s pin.
    对于LED,我们可以使用Arduino板(≤ 5v)的电源。因此,我们可以将 LED 直接连接到 Arduino 的引脚。
  • For the light bulb, we MUST use another power source (high voltage and/or high current), which can burn Arduino. Therefore, we CANNOT connect the light bulb directly to Arduino’s pin. We need to use a relay between Arduino’s pin and light bulb to protect Arduino from high voltage/current.
    对于灯泡,我们必须使用另一种电源(高电压和/或大电流),这可能会烧毁Arduino。因此,我们无法将灯泡直接连接到Arduino的引脚。我们需要在Arduino的引脚和灯泡之间使用继电器来保护Arduino免受高电压/电流的影响。

About Relay 关于Relay

A relay is a programmable electrical switch, which can be controlled by Arduino or any micro-controller. It is used to programmatically control on/off the devices, which use the high voltage and/or high current.
继电器是一种可编程的电气开关,可以由Arduino或任何微控制器控制。它用于以编程方式控制使用高电压和/或高电流的设备的开/关。

It is a bridge between Arduino and high voltage devices.
它是Arduino和高压设备之间的桥梁。

WARNING

When you are making projects that are connected to mains voltage, you need to know what you are doing, otherwise, you may shock yourself. This is a serious topic, and we want you to be safe. If you’re NOT 100% sure what you are doing, do yourself a favor and don’t touch anything. Ask someone who knows!
当您制作连接到电源电压的项目时,您需要知道自己在做什么,否则您可能会震惊自己。这是一个严肃的话题,我们希望您安全。如果您不是 100% 确定自己在做什么,请帮自己一个忙,不要碰任何东西。问问知道的人!

Although some kinds of relays support both DC and AC devices, We highly recommend you to use a DC device (≤24V) for testing.
尽管某些类型的继电器同时支持直流和交流设备,但我们强烈建议您使用直流设备 (≤24V) 进行测试。

Relay Pinout 继电器引脚排列

在这里插入图片描述

Relay has two groups of pins: input (low voltage) group and output (high voltage) group.
继电器有两组引脚:输入(低压)组和输出(高压)组。

  • Pins in the input group are connected to Arduino, including three pins:
    输入组中的引脚连接到Arduino,包括三个引脚:

    • DC- pin: needs to be connected to GND (0V)
      DC- 引脚:需要连接到 GND (0V)

    • DC+ pin: needs to be connected to VCC (5V)
      DC+ 引脚:需要连接到 VCC (5V)

    IN pin: receives the control signal from Arduino
    IN引脚:接收来自Arduino的控制信号

  • Pins in the output group are connected to the high voltage device, including three pins (usually in screw terminal):
    输出组中的引脚连接到高压器件,包括三个引脚(通常在螺丝端子中):

    • COM pin: is the common pin. It is used in both normally open mode and normally closed mode
      COM引脚:是常用引脚。它用于常开模式和常闭模式
    • NO pin: is normally open pin. It is used in the normally open mode
      NO 引脚:是常开引脚。它在常开模式下使用
    • NC pin: is normally closed pin. It is used in the normally closed mode
      NC引脚:常闭引脚。它在常闭模式下使用
  • In practice, we usually do NOT use all of the pins in the high voltage group. We use only two of them:
    在实践中,我们通常不会使用高压组中的所有引脚。我们只使用其中两种:

  • We use only COM pin and NO pin if we use normally open mode.
    如果我们使用常开模式,我们只使用 COM 引脚和 NO 引脚。

  • We use only COM pin and NC pin if we use normally closed mode.
    如果我们使用常闭模式,我们只使用 COM 引脚和 NC 引脚。

  • Additionally, if the relay supports both LOW and HIGH level triggers, there is usually a jumper to select one of two: LOW level trigger or HIGH level trigger.
    此外,如果继电器同时支持低电平和高电平触发,则通常有一个跳线可以选择以下两种触发之一:低电平触发或高电平触发。

  • ※ NOTE THAT: ※ 注意事项:

    The order of the relay module’s pins can vary between manufacturers. ALWAYS use the labels printed on the relay. Look closely!
    继电器模块引脚的顺序可能因制造商而异。始终使用印在继电器上的标签。仔细看!

  • How to Connect the High Voltage Device to Relay
    如何将高压设备连接到继电器
    How to connect relay

  • How It Works 它是如何工作的

  • Depending on manufacturers and user’s installation, a relay can work differently.
    根据制造商和用户的安装,继电器的工作方式可能有所不同。

  • The input mode mode (for IN pin): There are two input modes that make relay works oppositely:
    输入模式模式(用于 IN 引脚):有两种输入模式使继电器相反地工作:

  • LOW level trigger mode 低电平触发模式

  • HIGH level trigger mode HIGH电平触发模式

  • The output mode mode (for output pins): There are two output modes that make relay works oppositely:
    输出模式模式(用于输出引脚):有两种输出模式使继电器相反地工作:

  • normally open mode 常开模式

  • normally closed mode. These modes are the opposite.
    常闭模式。这些模式正好相反。

  • The “normally” means “if IN pin is connected to *LOW* (0V)”.
    “通常”表示“如果 IN 引脚连接到 LOW (0V)”。

  • Before going into detail, let’s see some quick information:
    在详细介绍之前,让我们先看一些快速信息:

  • The normally open and normally closed mode work oppositely
    常开和常闭模式相反

  • The most of relay modules supports both normally open and normally closed mode
    大多数继电器模块支持常开和常闭模式

  • The LOW level trigger and HIGH level trigger mode work oppositely
    低电平触发和高电平触发模式相反

  • NOT all of relay modules supports both LOW level trigger and HIGH level trigger mode
    并非所有继电器模块都支持低电平触发和高电平触发模式

  • At a time, The relay module can work at only one of two LOW level trigger and HIGH level trigger mode
    一次,继电器模块只能在两个低电平触发和高电平触发模式之一下工作

  • The combination of the input modes mode and output modes modes creates many use cases. If you are a beginner, we recommend using HIGH level trigger mode and normally open mode
    输入模式模式和输出模式模式的组合创造了许多用例。如果您是初学者,我们建议您使用 HIGH 级别触发模式和常开模式

  • Because the LOW level trigger and HIGH level trigger mode work oppositely, The next will explain the HIGH level trigger mode in detail. The LOW level trigger works oppositely.
    由于 LOW 电平触发和 HIGH 电平触发模式的工作方式相反,因此接下来将详细解释 HIGH 电平触发模式。LOW 电平触发器的工作方式相反。

  • HIGH Level Trigger - Normally Open Mode
    HIGH 电平触发 - 常开模式

  • To use this mode, we need to connect the high voltage device to the COM pin and NO pin.
    要使用此模式,我们需要将高压设备连接到 COM 引脚和 NO 引脚。

  • If the IN pin is connected to LOW (0V), the switch is open. The device is OFF (or inactive).
    如果 IN 引脚连接到 LOW (0V),则开关断开。设备处于关闭(或非活动状态)。

  • If the IN pin is connected to HIGH (5V), the switch is closed. The device is ON (or active).
    如果 IN 引脚连接到高电平 (5V),则开关闭合。设备处于打开(或活动)状态。

  • How Relay Works - Normally Open

  • HIGH Level Trigger - Normally Closed Mode
    HIGH 电平触发 - 常闭模式

  • To use this mode, we need to connect the high voltage device to the COM pin and NC pin.
    要使用此模式,我们需要将高压器件连接到COM引脚和NC引脚。

  • If the IN pin is connected to LOW (0V), the switch is closed. The device is ON (or active).
    如果 IN 引脚连接到低电平 (0V),则开关闭合。设备处于打开(或活动)状态。

  • If the IN pin is connected to HIGH (5V), the switch is open. The device is OFF (or inactive).
    如果 IN 引脚连接到高电平 (5V),则开关断开。设备处于关闭(或非活动状态)。

  • How Relay Works - Normally Closed

  • There are up to 8 use cases. It may overload you. However, If you are a newbie, you just need to care about the two first cases, where HIGH level trigger and normally open are used. The rest of this tutorial will use those two use cases
    最多有 8 个用例。它可能会使您超负荷。但是,如果您是新手,则只需要关心前两种情况,即使用高电平触发和常开。本教程的其余部分将使用这两个用例

  • Arduino - Relay Arduino - 继电器

  • Arduino controls a high voltage device by controlling a relay.
    Arduino通过控制继电器来控制高压设备。

  • Controlling a relay is simple. We just need:
    控制继电器很简单。我们只需要:

  • Connect an Arduino’s pin to the IN pin of the relay
    将Arduino的引脚连接到继电器的IN引脚

  • Control the relay by programming the pin to LOW or HIGH
    通过将引脚编程为低电平或高电平来控制继电器

Wiring Diagram 接线图

Arduino Relay Wiring Diagram

How To Program For Relay 如何为继电器编程

  • Configure an Arduino’s pin to the digital output mode by using pinMode() function. For example, pin 3:
    使用 pinMode() 函数将 Arduino 的引脚配置为数字输出模式。例如,引脚 3:
pinMode(3, OUTPUT); 
  • Program the pin to LOW (0V) by using digitalWrite() function:
    使用 digitalWrite() 函数将引脚编程为低电平 (0V):
digitalWrite(3, LOW); 
  • Program the pin to HIGH (5V) by using digitalWrite() function:
    使用 digitalWrite() 函数将引脚编程为高电平 (5V):
digitalWrite(3, HIGH); 

Arduino Code Arduino代码

/*

 * Created by ArduinoGetStarted.com
   *
 * This example code is in the public domain
   *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-relay
   */

// constants won't change
const int RELAY_PIN = 3;  // the Arduino pin, which connects to the IN pin of relay

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin as an output.
  pinMode(RELAY_PIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(RELAY_PIN, HIGH);
  delay(500);
  digitalWrite(RELAY_PIN, LOW);
  delay(500);
}

Quick Steps 快速步骤

  • Copy the above code and open with Arduino IDE
    复制上面的代码并使用Arduino IDE打开
  • Click Upload button on Arduino IDE to upload code to Arduino
    单击Arduino IDE上的“上传”按钮,将代码上传到Arduino
  • See LED strip state: blinking
    查看 LED 灯条状态:闪烁

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1869976.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Linux高并发服务器开发(五)终端和守护进程

文章目录 1 概念2 会话基本概念和API3 守护进程(重点)守护进程模型 4 获取当前系统时间 1 概念 终端 进程的集合叫进程组 也称为作业 是执行程序的过程 2 会话基本概念和API 进程组的集合 3 守护进程(重点) 独立于控制…

Linux内核中网络数据的流量控制(TC: Traffic control 和 QDISC)

(个人能力有限,本文如有错误之处,欢迎交流指正) 1 简介 在进行网络数据 接收 和 发送 过程中,网卡设备到L3(网络层) 中间会经历流量控制(Traffic control)。 《BPF之巅.洞悉Linux系统和应⽤性能》P413 qdisc这个可选层可以⽤来管理⽹络包的…

机器学习-数据预处理-聚类-回归-分类-单车数据集

机器学习-数据预处理-聚类-回归-分类-单车数据集 前言一、数据预处理1. 导入数据集2. 数据预处理3. 处理缺失值4. 生成特征用于后续进一步的分析 二、数据分布可视化1. 骑行时长分布2. 起始站和终点站分布可视化3. 高峰期与非高峰期骑行频次分布 三、聚类分析1. K-means聚类 四…

PostgreSQL 连接器:在 SeaTunnel 中的应用与优势

在现代企业中,数据已经成为核心资产,基于开源数据集成平台SeaTunnel,工程师如何高效地连接和管理这些数据源,直接关系到企业的竞争力和运营效率。 本文将给大家介绍如何通过 JDBC PostgreSQL 数据源连接器,在 SeaTunne…

240627_图像24位深度(RGB图)转为8位深度(单通道图)

240627_图像24位深度(RGB图)转为8位深度(单通道图) 在使用网络上下载下来的一部分图像分割数据集时,有些标签图你看着是一个黑白图,但是他还是有可能是一张RGB三通道图,具体怎么区分呢。右击图…

ARM芯片架构(RTOS)

前言:笔记韦东山老师的rtos教程,连接放在最后 #ARM介绍 arm芯片属于精简指令集risc,所用的指令比较简单,ARM架构是一种精简指令集(RISC)架构,广泛应用于移动设备、嵌入式系统、物联网等领域。AR…

英国国王座驾车标的逆向工程

多功能设计和制造解决方案为独特的挑战提供了引人注目的优势。Impossible Creations是一家来自英国的定制扫描、设计和建模公司,专门帮助客户完成无限制得创作任务。在他们最近接到的一个项目中,为了修复象征英国国王座驾的大英帝国吉祥物,Im…

【博士每天一篇文献-综述】Biological underpinnings for lifelong learning machines

阅读时间:2023-12-17 1 介绍 年份:2015 作者:Dhireesha Kudithipudi,Mario Aguilar-Simon,其中通讯作者Josh Bongard教授也是另一篇论文的通讯作者《Neural modularity helps organisms evolve to learn new skills …

widows下 vscode 的 terminal / powershell,ctrl+v失灵,输出^v

问题 原因 最近装了PSReadLine Import-Module PSReadLineSet-PSReadLineOption -PredictionSource History Set-PSReadLineOption -PredictionViewStyle InlineView Set-PSReadLineOption -EditMode Emacsvscode不兼容 解决方法 注释掉最后面的 Import-Module PSReadLineS…

Linux通过expect实现免交互

免交互 Here Document 用于将多行字符串直接传递给命令的方式&#xff0c;不需要人为交互命令界面&#xff0c;实现免交互 当使用Here Document操作文件时&#xff0c;需要借助一个文件结束符 EOF&#xff1a;文件结束符 示例 在脚本文件中写入以下内容 <<&#x…

RabbitMQ安装部署

简介 RabbitMQ一款知名的开源消息队列系统&#xff0c;为企业提供消息的发布、订阅、点对点传输等消息服务。 RabbitMQ在企业开发中十分常见&#xff0c;课程为大家演示快速搭建RabbitMQ环境。 安装 rabbitmq在yum仓库中的版本比较老&#xff0c;所以我们需要手动构建yum仓库…

优刻得首个「国产千卡智算集群」落地,支持智源千亿大模型训练

在人工智能引领的时代浪潮中&#xff0c;算力已成为技术进步与创新的核心驱动力。面对当下AI算力需求的飙升、高端AI芯片供应受限的挑战&#xff0c;加之OpenAI带来的技术封锁&#xff0c;唯有坚定不移的发展自主可控的国产技术方案&#xff0c;持续壮大国产智算集群规模&#…

等保测评中的问题与建议

随着信息技术的广泛使用和飞速发展&#xff0c;网络安全已逐渐演变为威胁经济社会发展的关键议题。信息安全的范围涵盖了政治、商务、军事、教育等多个方面。其中&#xff0c;信息的存储、分享以及管理&#xff0c;主要取决于政府的宏观规划和决策、商业运作的信息、银行的财务…

字节跳动发布的Coze,可以免费使用GPT-4o模型了

Coze是字节跳动推出的一个AI聊天机器人和应用程序编辑开发平台&#xff0c;可以理解为字节跳动版的GPTs。无论用户是否有编程经验&#xff0c;都可以通过该平台快速创建各种类型的聊天机器人、智能体、AI应用&#xff0c;并将其部署在社交平台和即时聊天应用程序中&#xff0c;…

丝杆支撑座:滚珠丝杆稳定运行的守护者!

丝杆支撑座是丝杆和电机之间连接的重要组成部分&#xff0c;发挥着非常重要的功能。提到丝杆支撑座和滚珠丝杆&#xff0c;很多人都会想到支撑关系&#xff0c;但丝杆支撑座作为滚珠丝杆系统中至关重要的角色&#xff0c;其作用远不止于简单的支撑。 丝杆支撑座安装过程非常简单…

解锁横向招聘:创新您的人才搜索

技能差距仍然是面试官面临的问题之一。在这些空缺职位中&#xff0c;很难找到合适的技能候选人&#xff0c;特别是高级职位或以上职位。另一方面&#xff0c;申请人也发现很难找到一份适合自己的工作&#xff0c;因为他们抱怨工作要求太窄或太具体。在具有挑战性的职位招聘环境…

目标检测之YoloV1

一、预测阶段&#xff08;前向推断&#xff09; 在预测阶段Yolo就相当于一个黑箱子&#xff0c;输入的是448*448*3的图像&#xff0c;输出是7*7*30的张量&#xff0c;包含了所有预测框的坐标、置信度和类别 为什么是7*7*30呢&#xff1f; --将输入图像划分成s*s个grid cell&a…

深海电波,智能驾驭:海上发电系统中的先进网关技术

随着技术的不断演进&#xff0c;海上风电场逐渐走向深海&#xff0c;随之而来的高速通信保障成为一大难题。同时&#xff0c;海上风电特殊的环境与部署技术&#xff0c;也给运维带来了作业难、成本高、响应慢等困难。通过在沿海岸边建立高站&#xff0c;结合超远覆盖、载波聚合…

Packer-Fuzzer一款好用的前端高效安全扫描工具

★★免责声明★★ 文章中涉及的程序(方法)可能带有攻击性&#xff0c;仅供安全研究与学习之用&#xff0c;读者将信息做其他用途&#xff0c;由Ta承担全部法律及连带责任&#xff0c;文章作者不承担任何法律及连带责任。 1、Packer Fuzzer介绍 Packer Fuzzer是一款针对Webpack…

SAP 免费退货销售订单类型配置简介

作为一名 SD顾问&#xff0c;必须具备熟悉系统和系统配置&#xff0c;但是之前都是做的PP顾问&#xff0c;现在用户需要新增了一个销售订单类型&#xff0c;所以自己研究销售订单类型的配置&#xff0c;才有了以下的文章&#xff0c;希望对各位学习的同学有所帮助 1、创建销售…