Cannot figure out my tv's power IR code or sum wrong with emitter

75 Views Asked by At

Alright guys so I'm trying for the life of me to emulate my tv remote so I can use my arduino to turn on my tv. However, i got my SONY tv remote code and its A90 so in my code when i want to send that signal out I put

irsend.sendSony(0xA90, 12);

But that does nothing. I know my code is programmed correctly because I put an LED there and ran the code and it flickered. I've narrowed it down to a few questions

  1. What resistor (if any) do I put for an IR Emitter?
  2. Is the hex format or bit amount incorrect?
  3. Did I just waste my money on ChatGPT who coded it for me?

Here I'm going to give the code that allowed me to figure out what my infared codes were and then I'll give the code I used to send it.

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
    }
  }
}

Thanks yall please help tho bc its for a project and its due soon

1

There are 1 best solutions below

0
ChipChop Gizmo On

You are missing the "address" in your sendSony

Do this in your receiver code:

if(irrecv.decode()) {
    irrecv.printIRResultShort(&Serial); // Print complete received data in one line
    irrecv.printIRSendUsage(&Serial);   // Print the statement required to send this data
}

This will show you in the serial monitor what address you need and then in your send (for example on my Samsung TV)

irsend.sendSamsung(0x707, 0x59, 0); //(address, code, number of repeats)

The address can be different even if it's the same manufacturer as it could be a TV, aircon, washing machine, that's why you need to specify it explicitly. The sendSony, sendSamsung, sendLG, sendNEC... just handle the raw protocol, things like frequency, pulse distance etc.