Is this the right way to control IR transmitter?

Hi all~
I’m trying to control IR transmitter which sends a short burst of a 38kHz carrier signal to the two IR receivers.
I’m using the following code to send burst of a 38kHz carrier signal.

#include <IRremote.h>
#define PIN_IR 3
IRsend irsend;
void setup()
  //Serial.begin(9600);
  irsend.enableIROut(38);
  irsend.mark(0);
}
void loop() {
}

The problem is, it sends continuously if I use above code which is not power efficient.
I want it send 38kHz carrier signal when motion is detected by PIR sensor. I modified the code as below.
But it doesn’t work, it keeps sending even PIR sensor is LOW. Any help would be appreciated!

#include <IRremote.h>

#define PIN_IR 3
IRsend irsend;

int pirPin = 9;  // pin for PIR output
int pirStat = 0;  // PIR status

void setup()
{
  pinMode(pirPin, INPUT);
//  irsend.enableIROut(37.9);
//  irsend.mark(0);
  Serial.begin(9600);
}

void loop() {
  pirStat = digitalRead(pirPin);
  if (pirStat == HIGH) {
    irsend.enableIROut(37.9);
    irsend.mark(0);
    Serial.println("Motion detected");
    }
   else {
    Serial.println("Are you there?");
    }
}
 irsend.mark(0);

starts and endless IR output.

Call

 irsend.space(0);

to disable the IR output.

digitalWrite(PIN_IR, LOW); did the trick for me, but I will try irsend.space(0);
which looks better.
Thanks for your comment!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.