I'm trying to create a circuit on Tinkercad that can receive and decode input from an IR Remote. However, it's currently returning an error, "invalid header file", which is quite informative towards locating the problem. I believe the main problem is the usage of the IRremote package, since the problem only came up when I was implementing it, and I'm new to using this package. Any help is greatly appreciated. Thank you!
#include <Adafruit_LiquidCrystal.h>
#include <IRremote.hpp>
// Initialize the LCD, specifying the I2C address (usually 0x27 or 0x3F)
Adafruit_LiquidCrystal lcd(0);
const int irPin1 = 9; // PIR Sensor 1 Output
const int irPin2 = 10; // PIR Sensor 2 Output
const int ledPin1 = 4; // LED for Parking Spot 1
const int ledPin2 = 5; // LED for Parking Spot 2
const int irReceiverPin = 2; // IR receiver pin
int button = 0;
bool manualControl1 = false; // Flag for manual control of LED 1
bool manualControl2 = false; // Flag for manual control of LED 2
// Map the IR code to the corresponding remote button.
int mapCodeToButton(unsigned long code) {
if ((code & 0x0000FFFF) == 0x0000BF00) {
code >>= 16;
if (((code >> 8) ^ (code & 0x00FF)) == 0x00FF) {
return code & 0xFF;
}
}
return -1;
}
int readInfrared() {
int result = -1;
if (IrReceiver.decode()) {
unsigned long code = IrReceiver.decodedIRData.decodedRawData;
result = mapCodeToButton(code);
IrReceiver.resume();
}
return result;
}
void setup() {
Serial.begin(9600);
pinMode(irPin1, INPUT);
pinMode(irPin2, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
IrReceiver.begin(irReceiverPin, ENABLE_LED_FEEDBACK);
lcd.begin(16, 2);
lcd.print("Available Spots:");
}
void loop() {
button = readInfrared();
int availableSpots = 0;
// Read the sensor states
int sensor1State = digitalRead(irPin1);
int sensor2State = digitalRead(irPin2);
// Debouncing delay
delay(50);
// Check parking spot 1
if (sensor1State == LOW && !manualControl1) {
digitalWrite(ledPin1, HIGH); // Parking spot 1 available
availableSpots++;
} else if (!manualControl1) {
digitalWrite(ledPin1, LOW); // Parking spot 1 occupied
}
// Check parking spot 2
if (sensor2State == LOW && !manualControl2) {
digitalWrite(ledPin2, HIGH); // Parking spot 2 available
availableSpots++;
} else if (!manualControl2) {
digitalWrite(ledPin2, LOW); // Parking spot 2 occupied
}
// Process IR remote control buttons
if (button != -1) {
switch (button) {
case 0: // Example button code for turning off LED 1
manualControl1 = true;
digitalWrite(ledPin1, LOW);
break;
case 1: // Example button code for turning on LED 1
manualControl1 = true;
digitalWrite(ledPin1, HIGH);
break;
case 2: // Example button code for disabling manual control of LED 1
manualControl1 = false;
break;
case 3: // Example button code for turning off LED 2
manualControl2 = true;
digitalWrite(ledPin2, LOW);
break;
case 4: // Example button code for turning on LED 2
manualControl2 = true;
digitalWrite(ledPin2, HIGH);
break;
case 5: // Example button code for disabling manual control of LED 2
manualControl2 = false;
break;
}
}
// Print the number of available spots to the Serial Monitor
Serial.print("Available Parking Spots: ");
Serial.println(availableSpots);
// Display the number of available spots on the LCD
lcd.setCursor(0, 1); // Move cursor to the second line
lcd.print(" "); // Clear previous value (optional but may cause flicker)
lcd.setCursor(0, 1);
lcd.print(availableSpots);
delay(500);
}