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