Merging two codes together as One

I have two codes I want to put together.
One is a IR LED code that is suppose to send a HEX to a DVD player, the other code is a motion detector (HC-SR501)that when it senses motion it turns a led on. so instead of turning the LED on. I want the IR LED to send a HEX code to the DVD player. I think i need a “if” statement but I’m not for sure as I’m new to Arduino

IR LED Code

#include <IRremote.h>

IRsend irsend;

void setup() {
}

void loop() {
    irsend.sendSony(0xD0B92, 20);
    delay(50);
    irsend.sendSony(0xD0B92, 20);
    delay(50);
    irsend.sendSony(0xD0B92, 20);
    delay(20000);
}

Motion Detector Code

//Henry's Bench
// HC-SR501 Motion Detector
// Sample Sketch

int ledPin = 13;  // LED on Pin 13 of Arduino
int pirPin = 7; // Input for HC-S501

int pirValue; // Place to store read PIR Value


void setup() {
  
  pinMode(ledPin, OUTPUT);
  pinMode(pirPin, INPUT);
 
  digitalWrite(ledPin, LOW);
  
  
  
}

void loop() {
  pirValue = digitalRead(pirPin);
  digitalWrite(ledPin, pirValue);

}

My attempt to merge the two codes

#include <IRremote.h>
int irsend = 13;  // LED on Pin 13 of Arduino
int pirPin = 7; // Input for HC-S501
IRsend irsend;
int pirValue; // Place to store read PIR Value


void setup() {
  
  pinMode(irsend, OUTPUT);
  pinMode(pirPin, INPUT);
 
  digitalWrite(irsend, LOW);
  
  
  
}

void loop() {
  pirValue = digitalRead(pirPin);
  digitalWrite(irsend, pirValue);    
    irsend.sendSony(0xD0B92, 20);
    delay(50);
    irsend.sendSony(0xD0B92, 20);
    delay(50);
    irsend.sendSony(0xD0B92, 20);
    delay(20000);

}
void loop() {
  pirValue = digitalRead(pirPin);

Right, and then you want to do something IF pirValue is HIGH..

if(pirValue == HIGH) {

And then put all the stuff you want to have happen conditionally on that if statement inside the { and } that follow it. It's just a basic if statement. Look anywhere for more examples of how to write one.

Thank you for the reply. I attempted to put in the "if" statement and it threw an error code.

Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

Motion_LED:5:8: error: conflicting declaration 'IRsend irsend'

 IRsend irsend;

        ^~~~~~

C:\Users\Timothy McMahon\Documents\Arduino\Motion_LED\Motion_LED.ino:3:5: note: previous declaration as 'int irsend'

 int irsend = 13;  // LED on Pin 13 of Arduino

     ^~~~~~

C:\Users\Timothy McMahon\Documents\Arduino\Motion_LED\Motion_LED.ino: In function 'void loop()':

Motion_LED:24:12: error: request for member 'sendSony' in 'irsend', which is of non-class type 'int'

     irsend.sendSony(0xD0B92, 20);

            ^~~~~~~~

Motion_LED:26:12: error: request for member 'sendSony' in 'irsend', which is of non-class type 'int'

     irsend.sendSony(0xD0B92, 20);

            ^~~~~~~~

Motion_LED:28:12: error: request for member 'sendSony' in 'irsend', which is of non-class type 'int'

     irsend.sendSony(0xD0B92, 20);

            ^~~~~~~~

Motion_LED:29:18: error: expected '}' at end of input

     delay(20000);}

                  ^

Multiple libraries were found for "IRremote.h"
 Used: C:\Users\Timothy
 Not used: C:\Users\Timothy
exit status 1
conflicting declaration 'IRsend irsend'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Ok. Post the code that threw that error. This may surprise you, but from where I’m sitting I can’t see what you wrote when you tried to put that if in there.

#include <IRremote.h>
int irsend = 13;  // LED on Pin 13 of Arduino
int pirPin = 7; // Input for HC-S501
IRsend irsend;
int pirValue; // Place to store read PIR Value


void setup() {
  
  pinMode(irsend, OUTPUT);
  pinMode(pirPin, INPUT);
 
  digitalWrite(irsend, LOW);
  
  
  
}

void loop() {
  pirValue = digitalRead(pirPin);
  digitalWrite(irsend, pirValue);
    if(pirValue == HIGH) { 
    irsend.sendSony(0xD0B92, 20);
    delay(50);
    irsend.sendSony(0xD0B92, 20);
    delay(50);
    irsend.sendSony(0xD0B92, 20);
    delay(20000);}
int irsend = 13;  // LED on Pin 13 of Arduino
int pirPin = 7; // Input for HC-S501
IRsend irsend;

Only one of those things can be named irsend. The other one needs a different name.

digitalWrite(irsend, pirValue);

If that’s the pin your remote is on then you probably should let the library handle the pin. Writing to it like that will probably throw off the code that’s being sent.

We have no error messages after trying what you’ve told us but I’m getting a Invalid Library Message. We think that changing the irsend to ir is now conflicting with the library. again thanks for helping as we been working on this for 8 hours. Here is the code we have now

#include <IRremote.h>
int ir = 7;  // LED on Pin 13 of Arduino
int pirPin = 8; // Input for HC-S501
IRsend irsend;
int pirValue; // Place to store read PIR Value


void setup() {
  
  pinMode(ir, OUTPUT);
  pinMode(pirPin, INPUT);
 
  digitalWrite(ir, LOW);
  
  
  
}

void loop() {
  pirValue = digitalRead(pirPin);  
  digitalWrite(ir, pirValue);
    if(pirValue == HIGH) { 
    irsend.sendSony(0xD0B92, 20);
    delay(50);
    irsend.sendSony(0xD0B92, 20);
    delay(50);
    irsend.sendSony(0xD0B92, 20);
    delay(20000);}}

Post the error where we can see it. Copy and paste it.

Invalid library is usually just a warning. It doesn’t normally stop you from compiling the code.

You can name that thing anything you want. The library doesn’t care.

We can upload the code to the arduino with no problems but it’s not sending the IR command to the DVD player when motion is detected and at the bottom of the screen it says this:

Invalid library found in C:\Users\Timothy McMahon\Documents\Arduino\libraries\SoftSerialTest

Thanks for your help!

Ignore that invalid library baloney. That’s the IDE complaining that the library doesn’t have some stuff not related to code.

Ok. We've uploaded the code to the Arduino but the IR LED it not turning on (we checked with a phone camera). We have also already checked that our PIR Sensor and IR LED are connected to the Arduino properly.
Any suggestions?

Thanks

mcmahont:
Ok. We've uploaded the code to the Arduino but the IR LED it not turning on (we checked with a phone camera). We have also already checked that our PIR Sensor and IR LED are connected to the Arduino properly.
Any suggestions?

Thanks

Try without the PIR code. What happens when you run some example code for the IR?

Aren't you supposed to have a begin() in setup somewhere for that IR library? Somewhere you need to tell it what pin to use.