But if I remove the two lines, then the led keeps beeing on and the player keeps repeating after I moved my hand over sensor.
I guesss that there need to be something to activate the blinking led and mp3 instead of the pir lines?
Appoligies for that im hard to explain - but I feel your help is getting me to understand better ![]()
void loop() {
digitalWrite (trigger, HIGH); // We send a 10 microsecond pulse //ADDED FROM DISTANCE CODE
delayMicroseconds (10); //ADDED FROM DISTANCE CODE
digitalWrite (trigger, LOW); //ADDED FROM DISTANCE CODE
responsetime = pulseIn (echo, HIGH); // And we wait for a pulse back //ADDED FROM DISTANCE CODE
distance = responsetime / 58; // Distance calculation in cm //ADDED FROM DISTANCE CODE
if (distance <MIN_DISTANCE) {
digitalWrite (led1, HIGH);
delay (35);
digitalWrite (led1, LOW);
if ( isActivated ) {
// blink led
if ( millis() - lastTime >= blinkTime ) {
lastTime = millis();
digitalWrite(led1, !digitalRead(led1));
}
// check if we have been active long enough
if ( millis() - startTime >= pauseTime ) {
isActivated = false; // force PIR to trigger again or not
}
}
if ( isActivated == false ) {
// check PIR
isActivated = true;
startTime = millis();
Serial.println("Sensor Activated");
Serial.println("DFPlayer Working...");
myDFPlayer.play(1);
}
}
}