Hi everyone.
I´m new to arduino and its language I saw a nice code for IR remotes and start editing when I went to verify he doesn´t give errors, but when I upload it to my arduino he doesn´t work like he was suppose to.
When I click the button "0x52A3D41F" he has suppose to blink but he just stays on can some one tell me how to fix it
I appreciate your help.
Pedro Bessa
#include <IRremote.h>
int bright;
int before;
int out=9; //connect your LED to pin 9
int steps=5; //dimmer steps, vary those to increase/decrease the steps between full brightness and turned off
int RECV_PIN = 11; //data out of IR receiver connects to pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn(); // start the receiver
before=0; //LED is turned off
bright=255; //brightness value is at maximum (255)
pinMode(out,OUTPUT);
}
void loop() {
if (irrecv.decode(&results)) {
if (results.value==0xFFA25D){ //Code to turn the LED ON/OFF
if(before==0){ // if the LED was turned off, then we turn it on
digitalWrite(out,HIGH);
before=1; //LED is now turned on
}
else{
digitalWrite(out,LOW); //if the LED was turned on, then we turn it off
before=0;
bright=255;
}}
if (results.value==0x52A3D41F) {
if(before==1){
digitalWrite(out, HIGH);
delay(1000);
digitalWrite(out, LOW);
delay(1000);
}
else{
digitalWrite(out, HIGH);
}}
irrecv.resume();
}}
Looks like she is not working.
Put some Serial.print() statements in your code to prove things are happening as you think they are.
How are things wired?
What remote are you using?
Hi Larry every things is hook up correctly because part of the code works.
My remote doesnt have a serial number so i cant tell you that
I´m gonna try put the Serial.print() statement to see
Thanks
What do you get when you run this sketch (which prints the value for the key pressed)?
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}
Now it work but he doesn´t blink he just turns on when i press the button and then turns off something is wrong and i still dont no what. It was suppose to blink when i press the button
The on and off key is= FFA25D
The blink key is= FF22DD
#include <IRremote.h>
int bright;
int before;
int out=9; //connect your LED to pin 9
int steps=5; //dimmer steps, vary those to increase/decrease the steps between full brightness and turned off
int RECV_PIN = 11; //data out of IR receiver connects to pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // start the receiver
before=0; //LED is turned off
bright=255; //brightness value is at maximum (255)
pinMode(out,OUTPUT);
}
void loop() {
if (irrecv.decode(&results))
{
if (results.value==0xFFA25D){ //Code to turn the LED ON/OFF
if(before==0){ // if the LED was turned off, then we turn it on
digitalWrite(out,HIGH);
before=1; //LED is now turned on
}
else{
digitalWrite(out,LOW); //if the LED was turned on, then we turn it off
before=0;
bright=255;
}
}
// if (results.value==0xFF22DD) {
// if(before==1){
// digitalWrite(out, HIGH);
// delay(1000);
// digitalWrite(out, LOW);
// delay(1000);
// before=0; //LED is now turned off
// }
// else{
// digitalWrite(out, HIGH);
// before=1; //LED is now turned on
// }
// }
if (results.value==0xFF22DD) {
if(before==1){
digitalWrite(out, LOW);
delay(1000);
digitalWrite(out, HIGH);
delay(1000);
before=1; //LED is now turned on
}
else{
digitalWrite(out, HIGH);
delay(1000);
digitalWrite(out, LOW);
delay(1000);
before=0; //LED is now turned off
}
}
irrecv.resume();
}
}
#include <IRremote.h>
boolean isBlinking = false;
int bright;
boolean before;
int out=9; //connect your LED to pin 9
int steps=5; //dimmer steps, vary those to increase/decrease the steps between full brightness and turned off
int RECV_PIN = 11; //data out of IR receiver connects to pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // start the receiver
before=false; //LED is turned off
bright=255; //brightness value is at maximum (255)
pinMode(out,OUTPUT);
}
void loop() {
if (irrecv.decode(&results))
{
if (results.value==0xFFA25D){ //Code to turn the LED ON/OFF
isBlinking = false;
if(before==false){ // if the LED was turned off, then we turn it on
digitalWrite(out,HIGH);
before=true; //LED is now turned on
}
else{
digitalWrite(out,LOW); //if the LED was turned on, then we turn it off
before=false;
bright=255;
}
}
if (results.value==0xFF22DD)
{
isBlinking = !isBlinking;
}
irrecv.resume();
}
if(isBlinking == true)
{
before = !before;
digitalWrite(out, before);
delay(500);
}
}
My advice would be to split up your sketch into simple parts. Get each bit working first and when you have all individual bits working, start combining them together one at a time.
This process is often called debugging your sketch....everybody does it to some extent.
Also, as mentioned earlier, using the serial.println(".....") throughout will help greatly in this debugging process.
Once you manage to debug this sketch as above, you will have far less similar issues in future.