Hi all! First off I'd like to say I'm probably the most nooby of the noobs so I apologize ahead of time if I've posted in the wrong area or if I didn't search the forum well enough. I'm a huge R/C fan and techno-geek in a sense. Even though I'm having soo much trouble understanding the C++ language, I love my Arduino Uno and all the projects ive done. Ping sensors, toy tanks, motor controllers, servos, bla bla, all the easy stuff and had a lot of fun. Now im trying to use Ken Shirriff's IR library to control some lights in my house with my Sony TV remote and am having a heck of a time figuring out were to start! i got all the demos to work just fine, know all the codes to my buttons.....but were do i start?
Could someone give me an example code of turning on and off a led using ir? I'm too embarrassed to post my attempts to get it so far so dont ask, lol.
A couple of pointers wouldnt hurt either. Thanks alot for your time and patience!
Thank you very much for your help! I really like this new hobby and prefer to figure it on my own so this, to me, is an act of desperation XD. I was on the rite track, just having trouble getting arduino to recognize the remote code specific to the button I intend to use.
I was thinking something like this,
void loop() {
if (irrecv.decode(&results=A90)) { //or 149 or whatever the sony power button is?...
digitalWrite(relay1, HIGH);
irrecv.resume(); // Receive the next value
}
}
Tried a cpl other variations of that and usual error is "A90" not defined.
And again, Thank you very much for your help and look forward to completing this project.
I have a recommendation. Lady Ada has a very useful tutorial here:
I used this tutorial to create a sound sensing baby monitor that interfaced with an IR remote that turned on a light show for the baby when she cried. I think you would get more mileage from capturing the signals and transmitting 20 of the 1000 codes in a SONY library. Lady Ada tutorial will allow you to use ANY remote.
NICE! pretty descriptive, still reading........ im pretty sure i should get somewhere with this. Thanks alot!
this c++ stuff is nuts! you ppl are heros in my eyes, dunno how you do it but im gonna figure it out! lol
Have you downloaded the zip and rename/copy the irremote folder to your library.
Once you done that, you can run the included ir receive dump or demo sketch.
If you connected the 3pin ir receiver correctly, you should see it display the codes in hex and raw data in the serial monitor when you press a button on your remote. you have to open the serial monitor under the arduino menu.
I'm not to far off from you. I'm not a software head either so struggling with this. At the mercy of these wonderful people here in this forum...
Lynxo:
I'm not to far off from you. I'm not a software head either so struggling with this. At the mercy of these wonderful people here in this forum...
I am not sure to whom you directed you comment, but what interests me in the Lady Ada tutorial is the lack of extra libraries to bloat the sketch in size. I can capture and dump with a simple sketch:
And plug it into a sketch similar to what I was working on:
I am not sure to whom you directed you comment, but what interests me in the Lady Ada tutorial is the lack of extra libraries to bloat the sketch in size. I can capture and dump with a simple sketch:
And plug it into a sketch similar to what I was working on:
No libraries needed other than the core.
[/quote]
Thanks for links. I will try that one. My issue is how do you handle the IR when the button is pressed and held down. The NEC protocol sends all F's. Most of these sketches I have seen are for single remote key press. I've been scratching my head as to how to go about making a sketch that will also detect the continued key press on the remote.
itsthedanyole:
I was on the rite track, just having trouble getting arduino to recognize the remote code specific to the button I intend to use.
I was thinking something like this,
void loop() {
if (irrecv.decode(&results=A90)) { //or 149 or whatever the sony power button is?...
digitalWrite(relay1, HIGH);
irrecv.resume(); // Receive the next value
}
}
Tried a cpl other variations of that and usual error is "A90" not defined.
Your on the right track but need to compare the result as below. Also note the == as it has a different meaning to =
void loop() {
if (irrecv.decode(&results)) {
if (results.value == 149) { //or 149 or whatever the sony power button is?...
digitalWrite(relay1, HIGH);
}
irrecv.resume(); // Receive the next value
}
}
Lynxo:
My issue is how do you handle the IR when the button is pressed and held down. The NEC protocol sends all F's. Most of these sketches I have seen are for single remote key press. I've been scratching my head as to how to go about making a sketch that will also detect the continued key press on the remote.
Is the first code sent the relevant button code and then it's just FF's after that until button is released? If so then all you need do is remember the last button press that was not FF and if you then get FF just substitute it for the last button press. Something along the lines of
static byte lastValue; // Place to store last value
if (irrecv.decode(&results)) { // Check for IR button press
byte newValue = results.value; // Get IR code
if (newValue == 255) { // NEC repeat button pressed?
newValue = lastValue; // Substitute last not repeat code
}
else { // Not repeat code
lastValue = newValue; // Store last not repeat code
}
switch (newValue) {
case 1:
//do something when var equals 1
break;
case 2:
//do something when var equals 2
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}
irrecv.resume(); // Receive the next value
}
Lynxo:
Thanks for links. I will try that one. My issue is how do you handle the IR when the button is pressed and held down. The NEC protocol sends all F's. Most of these sketches I have seen are for single remote key press. I've been scratching my head as to how to go about making a sketch that will also detect the continued key press on the remote.
Yeah, the "F" means there was no read other than there is an IR source. The on off timing sketch on the other hand will capture that information the hex dump misses.
Is the first code sent the relevant button code and then it's just FF's after that until button is released? If so then all you need do is remember the last button press that was not FF and if you then get FF just substitute it for the last button press. Something along the lines of
Yes, first code is sent then all repeat are F's.
Thanks so much Riva. I tried with your suggested sketch structure. I just change the byte to int since it's a 32 bit code.
Strange thing is when I press the Up button, the LED pin 7 just stays High, if I press Down button, the LED pin 8 also stays High, both will stay High until I press Up again or Down and hold. If I press and hold it, both buttons work correct
So press and hold works but now single press does not work.
My goal is press up or down, pin high for a time depending one delay or
press and hold, pin is high until released.
this is what I have:
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
int led7 = 7;
int led8 = 8;
void setup()
{
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
}
void loop() {
//static byte lastValue; // Place to store last value
int lastValue;
if (irrecv.decode(&results)) { // Check for IR button press
int newValue = results.value; // Get IR code
if (newValue == 4294967295) { // NEC repeat button pressed?
newValue = lastValue; // Substitute last not repeat code
}
else { // Not repeat code
lastValue = newValue; // Store last not repeat code
}
switch (newValue) {
case 2011287691:
//do something when var equals 1
digitalWrite(led7, HIGH);
delay(50);
break;
case 2011279499:
//do something when var equals 2
digitalWrite(led8, HIGH);
delay(50);
break;
default:
// if nothing else matches, do the default
// default is optional
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
break;
}
irrecv.resume(); // Receive the next value
}
}
"Your on the right track but need to compare the result as below. Also note the == as it has a different meaning to =
Code:
void loop() {
if (irrecv.decode(&results)) {
if (results.value == 149) { //or 149 or whatever the sony power button is?...
digitalWrite(relay1, HIGH);
}
irrecv.resume(); // Receive the next value
}
}"
Thanks again! And yes, I must say this forum is more friendly than others I've been on.
I haven't been testing the code due to tons of overtime at work but, I'm soaking this up as fast as I can!
I'm glad other people have gotten help from this topic, all these code examples are helping a lot.
I can see no particular reason the code would not work but have moved the LED off code out of switch/default and removed it as this may have been confusing matters, I have also changed int to unsigned long and added serial print code to aid debugging. Can you please try it again and let me know what happens.
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
int led7 = 7;
int led8 = 8;
void setup()
{
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
}
void loop() {
unsigned long lastValue;
if (irrecv.decode(&results)) { // Check for IR button press
unsigned long newValue = results.value; // Get IR code
if (newValue == 0xffffffff) { // NEC repeat button pressed?
newValue = lastValue; // Substitute last not repeat code
}
else { // Not repeat code
lastValue = newValue; // Store last not repeat code
}
switch (newValue) {
case 2011287691:
//do something when var equals 1
digitalWrite(led7, HIGH);
Serial.println("LED7");
delay(50);
break;
case 2011279499:
//do something when var equals 2
digitalWrite(led8, HIGH);
Serial.println("LED8");
delay(50);
break;
}
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
irrecv.resume(); // Receive the next value
}
}