// Define pin numbers
const int potPin = A0; // Potentiometer connected to analog pin A0
const int irPin = 2; // IR sensor connected to digital pin 2
const int ledPin = 9; // LED connected to PWM pin 9 (optional)
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Set IR sensor pin as input
pinMode(irPin, INPUT);
// Set LED pin as output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the potentiometer value (0 to 1023)
int potValue = analogRead(potPin);
// Map potentiometer value to LED brightness (0 to 255)
int brightness = map(potValue, 0, 1023, 0, 255);
// Set the LED brightness (optional)
analogWrite(ledPin, brightness);
// Read IR sensor state (HIGH when object detected, LOW when not)
int irState = digitalRead(irPin);
// Print values for debugging
Serial.print("Potentiometer Value: ");
Serial.print(potValue);
Serial.print(" | LED Brightness: ");
Serial.print(brightness);
Serial.print(" | IR Sensor State: ");
Serial.println(irState);
// Add a delay for better readability
delay(200);
}