int sensorPin = 2;

void setup() {
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  int state = digitalRead(sensorPin);

  if (state == LOW) {
    Serial.println("Magnet detected!");
  } else {
    Serial.println("No magnet");
  }

  delay(200);
}