const int potPin = A0; // Pin where potentiometer is connected
const int ledPin = 9; // Pin where LED is connected
int threshold = 512; // Set the threshold value (change as needed)
int sensorValue = 0; // Variable to store the ADC value
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Start serial communication for debugging
}
void loop() {
// Read the value from the potentiometer
sensorValue = analogRead(potPin); // Read ADC value (0-1023)
// Print the sensor value to the serial monitor
Serial.println(sensorValue);
// Compare the sensor value with the threshold
if (sensorValue > threshold) {
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(100); // Delay for stability
}