#include <IRremote.h>
// Define pins for IR receiver and LEDs
const int IR_PIN = 11;
const int LED_PIN_1 = 22;
const int LED_PIN_2 = 23;
const int LED_PIN_3 = 24;
const int LED_PIN_4 = 25;
const int LED_PIN_5 = 26;
const int LED_PIN_6 = 27;
const int LED_PIN_7 = 28;
const int LED_PIN_8 = 29;
const int LED_PIN_9 = 30;
// Define variables to store sensor readings
int sensor1 = 0;
int sensor2 = 0;
int sensor3 = 0;
int sensor4 = 0;
int sensor5 = 0;
int sensor6 = 0;
int sensor7 = 0;
int sensor8 = 0;
int sensor9 = 0;
// Define variables to store LED states
int ledState1 = LOW;
int ledState2 = LOW;
int ledState3 = LOW;
int ledState4 = LOW;
int ledState5 = LOW;
int ledState6 = LOW;
int ledState7 = LOW;
int ledState8 = LOW;
int ledState9 = LOW;
// Define IR remote codes
const long CODE_RED = 16736925;
const long CODE_YELLOW = 16754775;
const long CODE_GREEN = 16720605;
// Define IR remote object
IRrecv irrecv(IR_PIN);
decode_results results;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize IR remote
irrecv.enableIRIn();
// Initialize LED pins
pinMode(LED_PIN_1, OUTPUT);
pinMode(LED_PIN_2, OUTPUT);
pinMode(LED_PIN_3, OUTPUT);
pinMode(LED_PIN_4, OUTPUT);
pinMode(LED_PIN_5, OUTPUT);
pinMode(LED_PIN_6, OUTPUT);
pinMode(LED_PIN_7, OUTPUT);
pinMode(LED_PIN_8, OUTPUT);
pinMode(LED_PIN_9, OUTPUT);
}
void loop() {
// Check for IR remote input
if (irrecv.decode(&results)) {
// Store the received code
long code = results.value;
// Clear the receive buffer
irrecv.resume();
// Check the received code and update LED states
if (code == CODE_RED) {
ledState1 = HIGH;
ledState2 = LOW;
ledState3 = LOW;
ledState4 = HIGH;
ledState5 = LOW;
ledState6 = LOW;
ledState7 = HIGH;
ledState8 = LOW;
ledState9 = LOW;
}
else if (code == CODE_YELLOW) {
ledState1 = LOW;
ledState2 = HIGH;
ledState3 = LOW;
ledState4 = LOW;
ledState5 = HIGH;
ledState6 = LOW;
ledState7 = LOW;
ledState8 = HIGH;
ledState9 = LOW;
}
else if (code == CODE_GREEN) {
ledState1 = LOW;
ledState2 = LOW;
ledState3 = HIGH;
ledState4 = LOW;
ledState5 = LOW;
ledState6 = HIGH;
ledState7 = LOW;
ledState8 = LOW;
ledState9 = HIGH;
}
}
}