const int recv_pin = 2; // Pin connected to the IR Receiver
const int ledPin = 13; // Pin connected to the LED (Built-in LED)
void setup() {
Serial.begin(9600); // Start serial communication for debugging
pinMode(ledPin, OUTPUT); // Set LED pin as an output
pinMode(recv_pin, INPUT); // Set IR receiver pin as input
Serial.println("Ready to receive IR signals...");
}
void loop() {
if (digitalRead(recv_pin) == LOW) { // Check if the IR receiver is receiving data
int irCode = pulseIn(recv_pin, HIGH); // Read the pulse signal from IR receiver
Serial.print("IR Code: ");
Serial.println(irCode); // Print the IR code to the Serial Monitor
// Example IR codes for specific actions
if (irCode == 500) { // Example: some button press (replace with actual IR code)
Serial.println("IR Code 500 received!");
digitalWrite(ledPin, HIGH); // Turn on the LED
}
else if (irCode == 1000) { // Example: another button press
Serial.println("IR Code 1000 received!");
digitalWrite(ledPin, LOW); // Turn off the LED
}
}
}