#include <IRremote.h>
#include <LiquidCrystal.h>
#define PIN_RECEIVER 2 // Signal Pin of IR receiver
IRrecv receiver(PIN_RECEIVER);
const int ledPin3 = 3; // the pin that the LED is attached to
const int ledPin4 = 4; // the pin that the LED is attached to
const int buttonPin5 = 5; // the pin that the LED is attached to
void setup()
{
Serial.begin(9600);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(buttonPin5, INPUT);
receiver.enableIRIn(); // Start the receiver
}
void loop()
{
// Checks received an IR signal
if (receiver.decode()) {
translateIR();
receiver.resume(); // Receive the next value
}
if ((digitalRead(buttonPin5) == HIGH)){
digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,LOW);
Serial.println("GATE STOPPED.");
}
}
void translateIR()
{
// Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 224:
digitalWrite(ledPin3,HIGH);
digitalWrite(ledPin4,LOW);
Serial.println("GATE OPENING...");
break;
case 176:
digitalWrite(ledPin3,LOW);
digitalWrite(ledPin4,LOW);
Serial.println("GATE STOPPED.");
break;
case 144:
digitalWrite(ledPin4,HIGH);
digitalWrite(ledPin3,LOW);
Serial.println("GATE CLOSING...");
break;
default:
Serial.println("UNPROG BUTTON");
}
}