int sensorPin = 31; // Pin connected to the inductive sensor output
int ledPin = 13; // Pin connected to an LED (for indication)
void setup() {
pinMode(sensorPin, INPUT); // Set sensor pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Start serial communication for debugging
}
void loop() {
int sensorValue = digitalRead(sensorPin); // Read the sensor output
if (sensorValue == HIGH) { // Object detected
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Metal Object Detected!");
} else {
digitalWrite(ledPin, LOW); // Turn off LED
Serial.println("No Object Detected");
}
delay(100); // Delay to avoid excessive serial prints
}