You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Arduino模拟索尼电视红外遥控失效问题求助

Arduino模拟索尼电视红外开机无响应问题排查与解决

问题背景

我正在用Arduino模拟索尼电视遥控器实现开机控制,已通过红外接收器获取到电视开机的红外码为A90,在发送代码中使用irsend.sendSony(0xA90, 12);发送信号,但电视无响应。已通过LED闪烁验证代码逻辑(触摸触发、信号发送流程)是正常的,现在有三个疑问需要解决:

  • 红外发射器需要搭配多大阻值的电阻?
  • 十六进制格式或位数是否设置错误?
  • ChatGPT生成的代码是否无效?

用于识别红外码的Code 1

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

// Define sensor pin
const int RECV_PIN = 11;
const int LED_PIN = 12; // Define LED pin

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

// Set the LCD address
#define I2C_ADDR 0x27
// Define LCD columns and rows
#define LCD_WIDTH 16
#define LCD_HEIGHT 2
// Create an instance of the LCD class
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_WIDTH, LCD_HEIGHT);

bool welcomeDisplayed = false; // Flag to track if welcome message is displayed

void setup() {
  // Initialize Serial Monitor
  Serial.begin(9600);

  // Initialize the LCD
  lcd.init();
  lcd.backlight(); // Turn on the backlight

  // Display "Welcome home Demarko" only once
  lcd.setCursor(0, 0);
  lcd.print("Welcome home");
  lcd.setCursor(0, 1);
  lcd.print("Demarko");
  delay(3000); // Display for 3 seconds
  lcd.clear();

  // Initialize LED pin
  pinMode(LED_PIN, OUTPUT);

  // Enable the IR Receiver
  irrecv.enableIRIn();
}

void loop() {
  if (!welcomeDisplayed) {
    // If welcome message displayed, set the flag
    welcomeDisplayed = true;
  } else {
    // Normal IR receiver functionality
    if (irrecv.decode(&results)) {
      // Blink the LED when a signal is received
      digitalWrite(LED_PIN, HIGH); // Turn LED on
      delay(100); // Keep LED on for 0.1 second
      digitalWrite(LED_PIN, LOW); // Turn LED off

      // Print IR code on Serial Monitor
      Serial.println(results.value, HEX);

      // Clear the LCD screen
      lcd.clear();
      // Print the received IR code on the LCD
      lcd.setCursor(0, 0);
      lcd.print("IR Code: ");
      lcd.print(results.value, HEX);

      // Determine and print IR manufacturer type on the LCD
      lcd.setCursor(0, 1);
      switch (results.decode_type) {
        case NEC: lcd.print("NEC"); break;
        case SONY: lcd.print("SONY"); break;
        case RC5: lcd.print("RC5"); break;
        case RC6: lcd.print("RC6"); break;
        case SHARP: lcd.print("SHARP"); break;
        case JVC: lcd.print("JVC"); break;
        case SAMSUNG: lcd.print("SAMSUNG"); break;
        case LG: lcd.print("LG"); break;
        case WHYNTER: lcd.print("WHYNTER"); break;
        case PANASONIC: lcd.print("PANASONIC"); break;
        case DENON: lcd.print("DENON"); break;
        default: lcd.print("UNKNOWN"); break;
      }

      // Resume IR receiver
      irrecv.resume();
    }
  }
}

用于发送信号的Code 2

#include <IRremote.h>

const int touchSensorPin = 2; // Pin connected to the capacitive touch sensor
const int irLedPin = 3;       // Pin connected to the IR LED
const unsigned long debounceDelay = 1000; // Debounce delay in milliseconds

IRsend irsend; // Create an instance of the IRsend class

void setup() {
  Serial.begin(9600);
  pinMode(touchSensorPin, INPUT);
  irsend.begin(irLedPin); // Initialize IRsend with the IR LED pin
}


void loop() {
  static unsigned long lastTouchTime = 0; // Time when the last touch was detected
  int sensorValue = digitalRead(touchSensorPin);

  if (sensorValue == HIGH) {
    if (millis() - lastTouchTime > debounceDelay) {
      Serial.println("touch received");
      lastTouchTime = millis(); // Update the last touch time

      // Send the IR code
      irsend.sendSony(0xA90, 12); // Send the IR code A90 with a length of 32 bits
      delay(100); // Short delay after sending the code
    }
  }
}

疑问解答与修复建议

1. 红外发射器需要搭配多大阻值的电阻?

  • 常见3mm/5mm红外发射管的限流电阻选220Ω~330Ω即可,适配Arduino 5V引脚输出。
  • 电阻过小会导致LED过流烧毁,过大则削弱信号强度,导致电视接收不到。优先选220Ω测试,若信号仍弱可尝试减小到180Ω。

2. 十六进制格式或位数是否设置错误?

  • 先纠正代码注释错误:sendSony的第二个参数是码的位数,你代码里传的是12,但注释标注32位,这是明显矛盾。
  • 打开Code 1的串口监视器,接收原装遥控器开机码时,除了results.value(即0xA90),还要看results.bits的数值——索尼协议常用12、15、20位,必须保证发送时的位数和接收的完全一致。
  • 部分索尼设备存在字节顺序反转要求:若接收的是0xA90,可尝试反转后发送0x09A,部分机型需要这样匹配。

3. ChatGPT生成的代码是否无效?

  • 代码核心逻辑(触摸触发、红外发送框架)是可行的,但存在细节错误:
    • 注释与参数矛盾,易造成混淆;
    • 未考虑索尼协议的位数匹配和字节顺序问题,这是无响应的核心原因;
    • 未明确硬件接线要求:红外LED阳极必须通过电阻连接到Arduino引脚,阴极接地,反向接线会导致无信号输出。

额外调试步骤

  1. 用手机验证红外信号:打开手机摄像头对准红外LED,触发触摸时,摄像头中应能看到红外LED发出的紫光(肉眼不可见,手机摄像头可捕捉),若没有则检查接线和电阻。
  2. 增加发送次数:部分电视需要连续接收3-5次红外码才能响应,修改Code 2的发送逻辑:
    // 替换原发送代码
    for(int i=0; i<3; i++){
      irsend.sendSony(0xA90, 12); // 替换为你确认的正确码值和位数
      delay(100);
    }
    
  3. 重新确认红外码:用Code 1多次接收原装遥控器的开机码,确保results.value和results.bits的数值稳定,避免单次接收的误差。

内容的提问来源于stack exchange,提问作者DemarKo Santos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 17:20:57