IR LED not sending any signal

Hello, I am working on a project to control a TV with an arduino. To mimic a remote, I am trying to use a IR LED to send the signal. However, it is not sending anything. I am running this code on an arduino nano. The following is the code I am using:

#include <IRremote.h>
 
// Define switch pin
const int switchPin = 7;
 
// Define a variable for the button state
int buttonState = 0;
 
// Create IR Send Object
IRsend irsend;
 
void setup()
{
  // Set Switch pin as Input
  pinMode(switchPin, INPUT);
  Serial.begin(9600);
}
 
void loop() {
  
  // Set button state depending upon switch position
  buttonState = digitalRead(switchPin);
  
  // If button is pressed send power code command
   if (buttonState == HIGH) {
    irsend.sendSony(0x24052816, 20); // TV power code
    Serial.print("1");
  }
      
    // Add a small delay before repeating
    delay(200);
 
} 

(Note this is not my code, I am modifying it based on a website I found).

I have also made a IR receiver program using a arduino uno, which is working and shows when I have pressed a button on my TV remote. I've used that program to try and see if my LED is transmitting anything, but it is not showing anything in the serial monitor. If it is helpful, here is the code I used for the receiver:

#include <IRremote.h>
 
// Define sensor pin
const int RECV_PIN = 4;
 
// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;
 
void setup(){
  // Serial Monitor @ 9600 baud
  Serial.begin(9600);
  // Enable the IR Receiver
  irrecv.enableIRIn();
}
 
void loop(){
  if (irrecv.decode(&results)){
    // Print Code in HEX
        Serial.println(results.value, HEX);
        irrecv.resume();
  }
}

I have tried using both a 100 ohm and a 220 ohm resistor with my LED. I know the wiring is not an issue, as it works with ordinary LEDs. Does anybody have any ideas what might be wrong with my code or the circuit itself? If you have any other ideas on how I could make the arduino control my TV, I would also be interested.

Thanks in advance,
Tim

What makes You try sending that code? 20 is the same as 14H, 1110B.

Thank you for the response. I found that my remote is using the Sony set of commands, and Im not sure if it is 20 bit or 12 bit. The hex code is what my receiver shows when I click the power button on my remote.

Im not sure I understand. What do you mean 20 is the same as 14H, 1110B?

Okey. I don't know the syntax. Maybe 20 is the number of bits. My mistake.

That looks like 4 bytes, 32 bits to me.

Good! As already told, it looks like 32 bits.

20 written just like that is in the decimal representation. There's also hexadecimal, octal and binary. Look them up and get comfortable with them! It's really helpful manage the different bit representations.

That's interesting, I will look into that. However, I don't really see how this will help my issue. The LED is not just not properly turning on my TV, it is not transmitting anything (as shows by the receiver). Do you think that's also a matter of an improper bit length? Thanks again for the help.

Please post a link to the datasheet of the IR diode. Your schematics is also interesting.

It surely can be!

I believe this is the link to the datasheet. I bought the LEDs from this link:
https://www.amazon.ca/Gikfun-Infrared-Emission-Receiver-Arduino/dp/B06XYNDRGF/ref=sr_1_1_sspa?crid=324FPL1X676T1&dib=eyJ2IjoiMSJ9.WlbfyYNwqz6uyk4-QaeZjooa9vtAjEh-GIPgewxEdn1xpZD4PDyhjtdrqd7D1Ndst8TzITTIgSXl_cxHTXi9ZzRanSM8GdV3__DdqaOTNGpGaUGaLlsGZli2O0a6cgNmFIUHJ1oX5pyXe7pGrxjxyVCx1zVWImkwu-0NY5oIyv2bR2uN3W794_B9JoU91OBjOuRl4fhc-YL0RnX27_XuYbi_nnJPd7FBctyion_0LO5-HAGkzYWO38OviobtKkOI5AgHWHdVUXkKtb5I1Ml61ILNrcz2nGBkQHnUIVTq2MY.GYTi4wMHKsIcP7wrR86patp7n5ZGNjBeVq-wRXGw1nM&dib_tag=se&keywords=IR+Led&qid=1708993132&sprefix=ir+led%2Caps%2C151&sr=8-1-spons&sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&psc=1

I will look in to the bit length tonight. Thanks for the suggestion!

Do you also know if I need to include the pin number my LED is connected to in my code? I would think it should be in there, but all the code I have looked at does not have the pin number of the LED defined anywhere.

Obviously you haven't given much thought to the " modulated signal " requirements however to see if the IR led is actually working, simply hold in front of a mobile phone.

You definately need to tell the pin being used, or follow mandatory "orders" from the library. Short reply, panic bed time here....

simply hold in front of a mobile phone (camera).

1 Like

How is the diode wired? Pen, paper and some drawing, please.

PRO-TIP on amazonian links... everything from "ref" to the end is just the internet stalking you and other "clickers." This link...

https://www.amazon.ca/Gikfun-Infrared-Emission-Receiver-Arduino/dp/B06XYNDRGF

goes to the same location as this original link...

1 Like

I have done this, and abolutely nothing shows. I made the IR receiver circuit so I would be sure that nothing was being outputted.

I appreciate the tip, never knew that.

I have it connected to digital pin three, in series with a 100 ohm resistor, going to ground. Not sure if this is how you draw it, I don't have much experience doing this.

Where can I find the mandatory "orders"?

Thanks. That circuit will not send enough of current through the diode. It has a maximum of 100 mA and Your circuit will not make more then than 20 - 30 mA of the Arduino output transistors. More powder might be the issue.

Look into the library code or its readme file.

Custom friendly libraries get the pins from a .begin( pin1, pin2 ); defining the pins used. Less friendly libraries might used hard defined pins.

EDIT:
Your first posted code is of the less good type.
The second code initiates, tells, what pin is used.

Interesting, I thought I should have been using at least 100 ohms. What resistor size do you think I would need?
I don't really understand the library code. What do you mean that there is a hard defined pin? Does this mean I can only use the LED with one pin? If so, where can I find what pin it should be connected to? Thanks