int sensorPin = A0; // Potentiometer connected
int ledPin = 9; // LED connected to pin 9
int threshold = 512; // Threshold level
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = analogRead(sensorPin); // Read sensor value
if (sensorValue > threshold) {
digitalWrite(ledPin, HIGH); // Turn on LED
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
Serial.print("Sensor Value: ");
Serial.println(sensorValue); // Print sensor value
delay(100); // Delay for stability
}