int sensorValue = LOW;
long previousMillis = 0;
int sensorPin = 3;
long interval = 1000;
void setup() {
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
sensorValue = digitalRead(sensorPin);
if (sensorValue == HIGH) {
Serial.println("Moving detected");
} else {
Serial.println("Not Moving");
}
}
}