title: How do I receive a HIGH or LOW signal from an IR sensor on an Arduino?
body: <p>I'm trying to use an IR sensor with my Arduino Uno and only want a HIGH or LOW signal without decoding making any IR signal turn the state to a 1 or 0.   There is also a motion sensor but that code has been removed.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int ledPin = 13; // choose the pin for the LED
  int inputPin = 2; // choose the input pin (for PIR sensor)
  int pirState = LOW; // we start, assuming no motion detected
  int val = 0; // variable for reading the pin status
  int relayPin = 4; //PIN FOR RELAY OPERATION
  int irPin = 7; //IR Sensor pin
  int lightState = 0;
  int irVal = 0;
  
  void setup() {
    pinMode(ledPin, OUTPUT); // declare LED as output
    pinMode(inputPin, INPUT); // declare sensor as input
    pinMode(relayPin, OUTPUT);
    pinMode(irPin, INPUT);
    Serial.begin(9600);
  }
  
  void loop() {
    irVal = digitalRead(irPin);
    if (irVal == HIGH) {
      lightState = 1;
      Serial.println("IR received");
      while(irVal == HIGH) {
        irVal = digitalRead(irPin);
        if(irVal == HIGH) {
          irVal = LOW;
        } else {
          irVal = HIGH;
      }
    }
  }
  </code></pre>