Issues with IR receiving/sending programming n00b

This is for a school final project and I've run into a snag.

I'm trying to have a single remote send a signal to my Arduino UNO, and then have the Arduino send out a different IR signal to multiple devices (ex. projector and sound system turn on at the same time).

I'm having issues with getting my code to send the signal. So far I haven't been able to get it to repeat sending the signal every time. I press the power button once on my remote and the Arduino IR module indicates it is receiving a signal however my test LED does not send out any signal.

Eventually I want to use a photo resistor to sense that the projector light is on and turn on my stereo system, then turn it off when it senses the projector is off.

I've been using this as a resource but I can't seem to combine code from the different scripts: Using IR Remote Controls with the Arduino - YouTube

Any help would be greatly appreciated.
Thank you

Edit: I have also verified, using the blink tutorial, that the IR LED I'm using does work to turn on my projector.

// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>

// Define sensor pin
const int RECV_PIN = 4;

// Define LED pin constants  (these are to test if I'm actually getting a signal and also will be used for a different aspect of the project)
const int redPin = 8; 
const int whitePin = 9;
const int bluepin =10;

// Define integer to remember toggle state & IR state
int togglestate = 0;
int IRstate =0;

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

//create IR send object
IRsend irsend;

void setup(){
 // Enable the IR Receiver
 irrecv.enableIRIn();
 // Set LED pins as Outputs
 pinMode(redPin, OUTPUT);
 pinMode(whitePin, OUTPUT);
}

void loop(){
 IRstate = irrecv.decode(&results);
 if (IRstate == (0xFF6897)){  //0 on remote
   irsend.sendNEC(0xFFA25D,32);// power on projector
   IRstate=1;
 }
}
 
 

//void loop(){
   //if (irrecv.decode(&results)){

       //switch(results.value){
       //  case 0xFF6897: //Red Keypad Button & 0 on remote
       // Turn on LED for 2 Seconds
       //digitalWrite(redPin, HIGH);
       //irsend.sendNEC(0xFFA25D,32);// 0 on remote
       //delay(500);
       //digitalWrite(redPin, LOW);
       //break;
  
       
       
//    }
//    irrecv.resume(); 
//  }

//}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Hello everyone,

I'm working on a home theater project where I use a single remote to send an IR signal to my Arduino UNO and that triggers the Arduino to send IR codes to control the components of my entertainment system.

I currently have a projector and separate stereo system that use an IR signal.

I have already been able to read the HEX code for all my remotes to the Serial Monitor.

However, when I try to have my Arduino receive an IR code it won't send a different code.
And if I do get it to send a code it only sends it once and never again.

I've tried different variations of combining the scripts form this source https://dronebotworkshop.com/using-ir-remote-controls-with-arduino/

I've verified that my connections work and and the circuits are correct.

I would really appreciate the help as I'm simply dumbfounded and rather new at this.

Thank you

@beardman90, please do not cross-post. Threads merged.

Are you sure that your device uses NEC encoding checkout that. Also make sure your ir led is working check it out with the help of a mobile camera

@m_k_akash Yeah I verified it was NEC from the first example in the linked tutorial.
I also modified the blink tutorial to send out the power NEC signal constantly and it works just fine.

I did find a possible solution in the comments of this post
http://forum.arduino.cc/index.php?topic=198593.msg1467387#msg1467387

However, when I try to implement that code it receves and sends the signal but for some reason my projector isn't reading it.

I tested the regular remote, verified it's code, and it still won't work from the Arduino.
My first guess is the i value in the code but I'm not sure.

Here's the modified code I'm using:

#include <IRremote.h>
#include <IRremoteInt.h>

IRsend irsend;
int RECV_PIN = 5;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {
 
     if (irrecv.decode(&results)) {
       Serial.println(results.value, HEX);
       switch (results.value) {
         case 0xFF30CF: // ON OFF
         Serial.println("receved on command");
            for (int i = 0; i < 6; i++) {
            irsend.sendNEC(0xFFA25D, 32); // projector ON/OFF
            Serial.println("Projector on sent");
            irrecv.enableIRIn();
           
            }
            Serial.println("Projector On-off");
            break;

           
         }
   irrecv.enableIRIn();
   irrecv.resume();
   }
}

this line should be corrected

irsend.sendNEC(0xFFA25D, 32);

As

irsend.sendNEC(0xFFA25D, 24);

also add a delay

Hope it helps please try it

Did you consider what happens if the first remote and Arduino send IR at the same time?
A second Arduino could be used to verify what is received near the controlled device.

@m_k_akash I just tried it and still no effect so I switched back to 32.

Turns out I had to elevate the location of my led (I just lifted up the breadboard/whole unit) and it worked!

I'm wondering if there's a way to brighten the intensity of the transmitting IR LED. perhaps that would work more efficiently?

Also now that it works, does anyone have an idea on how I could trigger the photoresistor to send a mute signal to my stereo (812442BD, NEC)?

for better intensity reduce the value of the current limiting resistor of the led or add a ir led in parellel and ofcourse you could use the same led to send the mute signal send me the code that you have included the photoresistor details i will help you

@m_k_akash Thank you!

The sterio is all NEC, the mute signal is 812442BD, and the power signal is 81CE728D.

I currently have a 100ohm resistor on the positive side of the IR LED. I'm not sure if I could go any lower, but I do have extra IR LED's if this one shorts out.

These are the IR LED's I'm using (the clear ones in the pack): https://www.amazon.com/gp/product/B01HGIQ8NG/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=1

For the photoresistor I have it going through pin A0 but I don't have any code for that part yet. I planned on following the Arduino tutorial for photoresistors but I'm not sure how to implement it.

@m_k_akash
This is the code I previously used for my photoresistor. We took the gathered serial monitor data and put it into a .csv to graph it.
But to apply it to the previous code I'm not sure at this point.

int sensor_analog = A0;
int sensor_digital = 2;
unsigned long t;

// the setup routine runs once when you press reset:
void setup() {
  
  pinMode(sensor_analog,INPUT);
  pinMode(sensor_digital,INPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  //int sensorValue = analogRead(A0);
  int sensorValueA = analogRead(sensor_analog);
  int sensorValueD = digitalRead(sensor_digital);
  // print out the value you read:
  t = millis( );
  //Serial.print(sensorValue);
  float voltageA = sensorValueA* (5.0/1023.0);
  float voltageD = sensorValueD ;
  //Serial.print("Time: ");
  Serial.print(t);
  Serial.print(",");
  //Serial.print(" ,Pin_A0: ");
  //Serial.print(voltageA);
 // Serial.print(" ,Pin_2: ");
  //Serial.print(",");
  Serial.print(voltageD);
  Serial.println("\t"); //makes the display scroll downward
  delay(1000);        // delay in between reads for stability
}
#include <IRremote.h>
#include <IRremoteInt.h>
#define photoresistor_pin A0 
int threshold_value=10; // value below which it gets triggered
bool flag=0;

IRsend irsend;
int RECV_PIN = 5;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(photoresistor_pin,INPUT_PULLUP);
}

void loop() {
 
     if (irrecv.decode(&results)) {
       Serial.println(results.value, HEX);
       switch (results.value) {
         case 0xFF30CF: // ON OFF
         Serial.println("receved on command");
            for (int i = 0; i < 6; i++) {
            irsend.sendNEC(0xFFA25D, 32); // projector ON/OFF
            Serial.println("Projector on sent");
            irrecv.enableIRIn();
           
            }
            Serial.println("Projector On-off");
            break;

           
         }
   irrecv.enableIRIn();
   irrecv.resume();
   flag=0;
   }
 If(analogRead(photoresistor_pin)<threshold_value&&flag==0){

   Serial.println("turning on the stereo");
   irsend.sendNEC(0x81CE728D,32);//turn on the stereo
   delay(5000);
   Serial.println("muting");
   irsend.sendNEC(0x812442BD,32);//sends mute signal
   flag=1;
 }

}

Modify it for your convince. Exclude the turning the stereo on part if it is already turned on. The photoresistor should be connected between ground and A0, lower the threshold value if it is so sensitive to the light and the flag variable is used to send the mute signal once a time when you turn on the projector without it, it keeps on sending untill the projector it is off. Feel free to post any questions

All the best

@m_k_akash

I went ahead and lowered the resistance to 30ohms in line with the IR LED and the range works great.

I also used your code and it turns the projector on/off flawlessly.

However, I'm having issues with getting the photoresistor to trigger.

The method you used is different than what I'm familliar with.

How do I tell what value I should set the photoresistor trigger to?

Also is there some way to have another led turn on/off to indicate a signal is being sent?

I have 3 regular LED's on pins 8 9 and 10 that I'm later going to use to indicate if the room temperature is within 72degF with a thermistor on pin A1.

I'm also wondering how the trigger works. Will the stereo turn on when the photoresistor is above or below the threshhold?

thanks again

void setup(){
pinMode(A0,INPUT_PULLUP);
Serial.begin(9600);
}

void loop(){ 
 Serial.println(analogRead (A0));
 delay(100);
}

Use this code to callibrate the threshold value. For bright light lower the value and for dim light increase the value . For the indicator led ,to keep it simple just connect the normal led with parallel to the ir led so the signal flashes through the ir and also from the led hence you can see when the signal was send

The 30 Ohm resistor already overloads the Arduino output pin. Another LED in parallel will increase the current even more or only the LED with the lower threshold voltage will ever shine.

Thanks again @m_k_akash

My instructor just informed me I should skip the receving IR signal and focous on the 3 regular LED temperature indicator (which I am now able to get perfectly in the below code), and having the stereo turn on when the photoresistor senses light.

I was able to find a threshhold with your previous script. However, I'm having difficulty getting the Arduino to turn the stereo off when it senses the light is low.

Like, after it senses the projector light is on it would turn it on, then after that look for a lower light level and turn it off like a memory.

How can I go about this?

This is the code I'm using to experiement but it has an error where it keeps turning the stereo on/off over and over.

#include <IRremote.h>
//#include <IRremoteInt.h>

IRsend irsend;
int RECV_PIN = 5;
int ledPinB = 10; //blue led
int ledPinW = 9;  //white led
int ledPinR = 8;  //red led
IRrecv irrecv(RECV_PIN);
decode_results results;

int sensor_analog = A1;
int sensor_analogP = A0;
unsigned long t;
unsigned long R;
bool flag=0;

// the setup routine runs once when you press reset:
void setup() {
  pinMode(ledPinB,OUTPUT);
  pinMode(ledPinW,OUTPUT);
  pinMode(ledPinR,OUTPUT);
  pinMode(sensor_analog,INPUT);
  pinMode(sensor_analogP,INPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  int sensorValueA = analogRead(sensor_analog);
  int sensorValueB = analogRead(sensor_analogP);
  // print out the value you read:
  t = millis( );
  float voltageA = sensorValueA * (5.0/1023.0);
  float voltageB = sensorValueB * (5.0/1023.0);
  R = (50000/voltageA) - 10000;
  float tempC = ((1/(0.001129148 + 0.000234125 * log(R) + 0.0000000876741 * pow(log(R), 3))) - 273.15)-3;
  float tempF= (9*tempC/5+32);  //calebrated from existing digital thermometor
  //Serial.print(t);
  //Serial.print(",");
  Serial.print(sensorValueB);
  //Serial.print(voltageB);
  Serial.print(", ");
  Serial.print(tempC);
  Serial.print(" C");
  Serial.print(", ");
  Serial.print(tempF);
  Serial.print(" F");
  //Serial.print((9*tempC/5+32)-2);
  Serial.println("\t");
  delay(1000);        // debouncing
  

  //Red LED
  if(tempF >73){
    digitalWrite(ledPinR,HIGH);
    
  }
  if (tempF < 73){
    digitalWrite(ledPinR,LOW);
  }
  
  //White LED
  if((tempF<=73) && (tempF>=71)){
    digitalWrite(ledPinW,HIGH);
    
  }
  if ((tempF>=73) or (tempF<=71)){
    digitalWrite(ledPinW,LOW);
  }

  //blue LED
  if(tempF < 71){
    digitalWrite(ledPinB,HIGH);
    
  }
  if (tempF > 71){
    digitalWrite(ledPinB,LOW);
  }

  //stereo sensig projector on
  //if (voltageB > 0.25){
    //irsend.sendNEC(0x81CE728D,32); //turn on stereo
    //Serial.print("Stereo on/off triggered");
    //flag=1;
  //}
  if (sensorValueB > 29){
    irsend.sendNEC(0x81CE728D,32); //turn on stereo
    Serial.print("Stereo on/off triggered");
  }
}

PS I should also add my ardino now has an error where any receved IR signal is jumbled up and not consistent anymore. Which is another reason why I'm switching to the other way.

#include <IRremote.h>
//#include <IRremoteInt.h>

IRsend irsend;
int RECV_PIN = 5;
int ledPinB = 10; //blue led
int ledPinW = 9;  //white led
int ledPinR = 8;  //red led
IRrecv irrecv(RECV_PIN);
decode_results results;

int sensor_analog = A1;
int sensor_analogP = A0;
unsigned long t;
unsigned long R;
bool flag=0;

// the setup routine runs once when you press reset:
void setup() {
  pinMode(ledPinB,OUTPUT);
  pinMode(ledPinW,OUTPUT);
  pinMode(ledPinR,OUTPUT);
  pinMode(sensor_analog,INPUT);
  pinMode(sensor_analogP,INPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  int sensorValueA = analogRead(sensor_analog);
  int sensorValueB = analogRead(sensor_analogP);
  // print out the value you read:
  t = millis( );
  float voltageA = sensorValueA * (5.0/1023.0);
  float voltageB = sensorValueB * (5.0/1023.0);
  R = (50000/voltageA) - 10000;
  float tempC = ((1/(0.001129148 + 0.000234125 * log(R) + 0.0000000876741 * pow(log(R), 3))) - 273.15)-3;
  float tempF= (9*tempC/5+32);  //calebrated from existing digital thermometor
  //Serial.print(t);
  //Serial.print(",");
  Serial.print(sensorValueB);
  //Serial.print(voltageB);
  Serial.print(", ");
  Serial.print(tempC);
  Serial.print(" C");
  Serial.print(", ");
  Serial.print(tempF);
  Serial.print(" F");
  //Serial.print((9*tempC/5+32)-2);
  Serial.println("\t");
  delay(1000);        // debouncing
 

  //Red LED
  if(tempF >73){
    digitalWrite(ledPinR,HIGH);
   
  }
  if (tempF < 73){
    digitalWrite(ledPinR,LOW);
  }
 
  //White LED
  if((tempF<=73) && (tempF>=71)){
    digitalWrite(ledPinW,HIGH);
   
  }
  if ((tempF>=73) or (tempF<=71)){
    digitalWrite(ledPinW,LOW);
  }

  //blue LED
  if(tempF < 71){
    digitalWrite(ledPinB,HIGH);
   
  }
  if (tempF > 71){
    digitalWrite(ledPinB,LOW);
  }

  //stereo sensig projector 

  if (sensorValueB > 29&&flag==0){
    irsend.sendNEC(0x81CE728D,32); //turn on stereo
    Serial.print("Stereo on triggered");
  flag=1;
  }
 
  else if (sensorValueB < 25&&flag==1){
    irsend.sendNEC(0x81CE728D,32); //turn off stereo
    Serial.print("Stereo off triggered");
    flag=0;
  }
  
}

This code only sends the signal only once and also added the turn off part when the photoresistor value does below 25 (adjust for accuracy). The jumbling up of ir receiving part may be due to the constantly send signal to turn on/off stereo which may be fixed here.try this code