用电视遥控器控制任何电子必威lol产品|Arduino IR教程

在这个Arduino IR教程中,我们将学习如何使用电视遥控器和Arduino来控制电子设备。我们将从控制简单的LED,然后控制直流风扇速度,以控制高压家电的少数示例。您可以观看以下视频或阅读下面的书面教程。

betway


我们可以注意到我们按下按钮时电视远程闪烁前面的LED。实际上我们只能通过相机看到这一点,因为这是一种红外线,人眼不可见。

电视 - 远程LED-1

因此,闪烁意味着当我们按下一个按钮时,红外LED正发送我们需要使用红外接收器接收的光或脉冲突发。

Arduino-IR-TV-Remote-Control-Whe-Works-2

在本教程中,我们将使用V 34838 IR接收器,其中具有以下框图,我们可以从我们看到它将放大,过滤和解调接收信号并提供清洁的逻辑输出,这是Arduino板的数字输入可以接受的清洁逻辑输出。

V-34838-IR-Receiver-Datasheet

然后使用Ken Shirriff的Arduino-IRremote库和它的演示示例,我们可以从串行监视器看到一个独特的十六进制代码,每个按钮按下,我们可以在制作我们的程序时使用它。

Ken-Shirriff's-urmote  - 图书馆-1

链接到Ken Shirriff的Arduino-urmote图书馆:https://github.com/z3t0/arduino-irremote.

使用电视遥控器控制RGB LED


您可以从以下任何网站获取组件:

必威外围提钱披露:这些是联盟链接。作为亚马逊助理,我从合格购买中获得。

因此,我们将使用电视遥控器的4个彩色按钮控制LED颜色。这意味着首先,我们需要通过上传Irrecvdemo示例并运行串行监视器来查看每个按钮的十六进制代码。我们将按下每个按钮并记下其代码。

Irrecvdemo-erial-monitor-and-tv-remote-RGB-LED控制 - 示例

现在,我们将修改像这样的演示代码,并在按下特定按钮时添加的陈述。因此,对于每个按钮,我们将设置适当的RGB值,以及setcolor()功能将点亮特定颜色的LED。有关更多详细信息,RGB LED如何与Arduino合作,您可以查看我的Arduino RGB教程

/ * *使用电视遥控器控制RGB LED * *修改的Irrecvdemo示例来自Ken Shirriff Irremote Library * Ken Shirriff * https://arcfn.com * *由Dejan Nedelkovski修改,* www.www.mfxpo.com * * / #includebet188官方网站 int recv_pin = 8;// IR接收器 -  Arduino PIN号8 IRRECV IRRECV(RECV_PIN);decode_results结果;int Redpin = 5;int greenpin = 6;int bluepin = 7;void setup() {Serial.begin(9600);irrecv.enableIRIn ();//启动接收器Pinmode(Redpin,输出); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); } void loop() { if (irrecv.decode(&results)) { if (results.value == 0xF21D7D46) { // Red Button setColor(255, 0, 0); // Sets Red Color to the RGB LED delay(100); } if (results.value == 0x87CF1B29) { // Green Button setColor(0, 255, 0); // Green Color delay(100); } if (results.value == 0x6623D37C) { // Yellow Button setColor(255, 255, 0); // Yellow Color delay(100); } if (results.value == 0x854115F2) { // Blue Button setColor(0, 0, 255); // Blue Color delay(100); } if (results.value == 0x1639AB6E) { // Stop Button setColor(0, 0, 0); // OFF delay(100); } irrecv.resume(); // Receive the next value } delay(100); } // Custom made function for activating the RGB LED void setColor(int red, int green, int blue) { analogWrite(redPin, red); // Sends PWM signal to the Red pin analogWrite(greenPin, green); analogWrite(bluePin, blue); }

下面是Arduino红外控制RGB LED电路原理图:

控制A-RGB-LED  - 带电视远程电路 - 模板-2

使用电视遥控器控制DC风扇速度


此示例所需的组件:

在此示例中,将使用电视遥控器的前向和向后按钮来控制DC风扇速度。我们将使用此电路原理图来控制风扇的速度,或者实际上我们将使用按钮控制PWM信号。有关更多详细信息,此电路原理图如何工作,您可以查看我的Arduino Motors教程

控制-A-DC风扇速度与A-TV-Remote-Collection-schemicatics

下面是这个示例的源代码。所以使用Amplwwrite()功能我们将向晶体管的基部发送PWM信号。播放按钮将以最大速度启动电机,或者PWM信号的占空比将是100%,停止按钮将停止。通过增加PWM信号的占空比,向前按钮将增加风扇的速度,并且向后按钮将减小它。

/* * * control a DC Fan Speed with a TV Remote * * Modified IRrecvDemo from Ken Shirriff IRremote Library * Ken Shirriff * https://arcfn.com * * Modified by Dejan Nedelkovski, * www.HowToMechabet188官方网站tronics.com * */ #include  int RECV_PIN = 8;//红外接收器- Arduino Pin Number 8 int pwmPin = 7;// Arduino引脚7到晶体管的底部int pwmValue;IRrecv IRrecv (RECV_PIN);decode_results结果;void setup() {Serial.begin(9600);irrecv.enableIRIn ();//启动接收端pinMode(pwmPin, OUTPUT);pwmValue = 0;void loop() {if (irrecv.decode(&results)) {analogWrite(pwmPin, pwmValue); if (results.value == 0xAFAF8374) { // PLAY Button pwmValue = 255; // 100% Duty Cycle | Max Speed } if (results.value == 0x98519C65) { // STOP Button pwmValue = 0; // 0% Duty Cycke | Turned off } if (results.value == 0x93F1BA08) { // FORWARD Button if(pwmValue <= 245){ pwmValue = pwmValue + 10; // Increases the Duty Cycle of the PWM Signal delay(20); } } if (results.value == 0x71D086FF) { // BACKWARD Button if(pwmValue >= 20){ pwmValue = pwmValue - 10; // Decreases the Duty Cycle of the PWM Signal delay(20); } } Serial.print(pwmValue); Serial.print(" "); Serial.println(results.value, HEX); irrecv.resume(); // Receive the next value } delay(100); }

用电视遥控器控制高压家电


本教程所需的组件:

最终示例将使用电视遥控器控制高压家电。为此,我们需要一个继电器模块。我将使用HL-52S继电器模块,该模块具有250和125 V AC的额定值。这是Arduino IR控制的高压家用电器示例的电路原理图。使用来自Arduino Board的PIN编号7,我们将控制其中有一个用于连接任何高压电子设备的插座的继电器。

控制高压家用电器 - 使用电视 - 远程电路 - 原理图

正如我们将使用高电压,我们必须非常谨慎,我在这里警告您的使用不当或不正确的使用可能导致严重伤害或死亡,并且我对您的行为不承担任何责任。有关更多详细信息,如何使用继电器以及如何制作插座,用于插入您可以查看我的任何电子设备Arduino Relay教程

警告 - 高压

以下是此示例的源代码:

/ * *用电视遥控器控制高压家电* *修改的Irrecvdemo示例来自Ken Shirriff Irremote Library * ken shirriff * https://arcfn.com * *由dejan修改,* www.www.mfxpo.com * * / #includebet188官方网站 int recv_pin = 8;int relayout = 7;int buttonstate;IRrecv IRrecv (RECV_PIN);decode_results结果;void setup() {Serial.begin(9600);irrecv.enableIRIn ();//启动接收器Pinmode(中继,输出);ButtonState =高; // Starts the program with turned off Relay. The relay input works inversly so HIGH state means deactivated relay } void loop() { buttonState = digitalRead(relayOut); if (irrecv.decode(&results)) { if (results.value == 0xAFAF8374) { // PLAY Button digitalWrite(relayOut, LOW); // Activates the relay } if (results.value == 0x98519C65) { // STOP Button digitalWrite(relayOut, HIGH); // Deactivates the relay } irrecv.resume(); // Receive the next value } Serial.print(" "); Serial.println(results.value, HEX); delay(100); }

受到推崇的

2019年初学者和爱好者的最佳进入级示波器

为初学者和爱好者最好的示波器

受到推崇的

8个最好的Arduino入门工具包,适合2019年初学者

初学者的8个最佳Arduino Starter Kits

受到推崇的

用于初学者和爱好者的最佳3D打印机 -  3D打印

初学者和爱好者的最佳3D打印机