hey there i am working on a lighting system for my room controlled by an IR remote but my problem is that I want it to broadcast to two sides of the room so I got another Arduino and programmed the first one to send an IR signal through a transmitting module and it works fine but the moment I press one of the buttons that are supposed to turn on or off the light the led will do its thing and then it would just stop receiving signals.
my code is:
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
IRsend irsend;
const int RECV_PIN = 7;
const int redPin = 12;
const int greenPin = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(12, OUTPUT);
}
void loop(){
if (irrecv.decode(&results)){
switch(results.value){
case 0xFFA25D: //Keypad button "ch-"
digitalWrite(redPin, LOW);
}
switch(results.value){
case 0xFFE21D: //Keypad button "2"
digitalWrite(greenPin, HIGH);
}
irrecv.resume();
}
}
void send_on() {
irsend.sendNEC(0xFFA857, 32); // Sony TV power code
}
void send_off() {
irsend.sendNEC(0xFFE01F, 32); // Sony TV power code
}
hope you can help
thank u
tank1334:
hope you can help
First, read this: Read this before posting a programming question .... As the title says, you should have read it before posting. Read it all, but pay particular attention to Item #6. Post your code correctly using Code Tags.
Your switch/case structure was kinda messed up. I cleaned that up but I'm not really sure what you're trying to do. You have both red and green LEDs on the same pin...
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
const int RECV_PIN = 7;
const int redPin = 12;
const int greenPin = 12;
IRsend
irsend;
IRrecv
irrecv(RECV_PIN);
decode_results
results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(12, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
switch(results.value)
{
case 0xFFA25D: //Keypad button "ch-"
digitalWrite(redPin, LOW);
break;
case 0xFFE21D: //Keypad button "2"
digitalWrite(greenPin, HIGH);
break;
}//switch
irrecv.resume();
}//if
}//loop
void send_on()
{
irsend.sendNEC(0xFFA857, 32); // Sony TV power code
}//send_on
void send_off()
{
irsend.sendNEC(0xFFE01F, 32); // Sony TV power code
}//send_off
I was messing around with a lot of code before and I took bits of code from different files so there are two variables that have the same value.
basically I am trying to create a system which the led will turn on when I press the CH+ button on my remote and will turn off when I press CH-, but then it will send an IR signal to a diffrent ir receiver that what the extra functions are for. my problem is that I was able to pair it with my IR emission(IR blaster/ emitter ) sensor but it will only work once and then I would have to reset the Arduino for it to receive a signal again.
my remote is a nec protocol remote like the one here: https://goo.gl/images/HoYkkn
i am conectiong the led to pin 12.
the data pin on the IR reciver is pin 7.
and the data pin on the ir blaster is connected to pin 3.
thanks a lot
my code:
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
const int RECV_PIN = 7;
const int redPin = 12;
const int greenPin = 12;
IRsend
irsend;
IRrecv
irrecv(RECV_PIN);
decode_results
results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(12, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
switch(results.value)
{
case 0xFFA25D: //Keypad button "ch-"
digitalWrite(redPin, LOW);
break;
case 0xFFE21D: //Keypad button "2"
digitalWrite(greenPin, HIGH);
break;
}//switch
irrecv.resume();
}//if
}//loop
void send_on()
{
irsend.sendNEC(0xFFA857, 32); // Sony TV power code
}//send_on
void send_off()
{
irsend.sendNEC(0xFFE01F, 32); // Sony TV power code
}//send_off
by the way, the code for the CH+ is:0xFFE21D
and CH- is:0xFFA25D
Why do you have two names for the same pin? One name you only ever switch on and other name is only switched off. That's just designed to confuse.
And you have two functions that are never called...so it's no wonder nothing is ever sent.
Steve
this is my code:
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
IRsend irsend;
const int RECV_PIN = 7;
const int redPin = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(12, OUTPUT);
}
void loop(){
if (irrecv.decode(&results)){
switch(results.value){
case 0xFFA25D: //Keypad button "ch-"
digitalWrite(redPin, LOW);
send_off();
irrecv.resume();
}
switch(results.value){
delay(1000);
case 0xFFE21D: //Keypad button "2"
digitalWrite(redPin, HIGH);
send_on();
}
irrecv.resume();
}
}
void send_on() {
irsend.sendNEC(0xFFA857, 32); // Sony TV power code
irrecv.resume();
}
void send_off() {
irsend.sendNEC(0xFFE01F, 32); // Sony TV power code
irrecv.resume();
}
but my problem is that it will work fine but the moment i press the CH+ button the led will turn on and then the Arduino seems to not get any ir signal. i tried switching my sensors but nothing worked.
i would be very thank full if you can help me fix the code or find the bug
That's not the way that switch case is normally used. Try
switch(results.value){
case 0xFFA25D: //Keypad button "ch-"
digitalWrite(redPin, LOW);
send_off();
break;
case 0xFFE21D: //Keypad button "2"
digitalWrite(redPin, HIGH);
send_on();
break;
}
and since you have now added irrecv.resume() to both sendOn and sendOff take all the others out. There's no point calling it two or three times.
Your problem description is confusing because according to your code comments there is no "ch+" key. All you have is "ch-" and "2". So I'm not sure if those changes will help but they might make the code cleaner.
Steve
The 2 is CH- I just didn't bother to change the notes(big mistake) sorry about that
And thanks allot
so I tried it and the same thing seems to happen, the Arduino will receive a signal once and then would not do anything.
the code:
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
const int RECV_PIN = 7;
const int redPin = 12;
const int greenPin = 12;
IRsend
irsend;
IRrecv
irrecv(RECV_PIN);
decode_results
results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(12, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
switch(results.value){
case 0xFFA25D: //Keypad button "ch-"
digitalWrite(redPin, LOW);
send_off();
break;
case 0xFFE21D: //Keypad button "2"
digitalWrite(redPin, HIGH);
send_on();
break;
}
irrecv.resume();
}//if
}//loop
void send_on()
{
irsend.sendNEC(0xFFA857, 32); // send out to turn on
}//send_on
void send_off()
{
irsend.sendNEC(0xFFE01F, 32); // send out to turn off
}//send_off
so I tried it and the same thing seems to happen, the Arduino will receive a signal once and then would not do anything.
What are the symptoms of this ?
Does the built in LED blink when you send a code ?
What do you see if you print the value of results.value ?
tank1334:
The 2 is CH- I just didn't bother to change the notes(big mistake) sorry about that
So you have 2 codes called ch- and still none called ch+? And you still didn't bother changing the comment.
BTW why do you have ir_Lego_PF_BitStreamEncoder.h in there? What does that do for you?
Successful programming tends to need a fairly precise approach to things not just changing any old stuff at random.
Steve