Hi,
I am working on a project where when the PIR detects movement and the ultrasonic sensor reads below a given value it triggers a relay and a media player off a digital output pin.
If during the playing of the video the PIR sensor detects no movement it stops the video and releases the relay
Currently I have this in a loop by which if the value of the PIR is equal to 1023 and the ultrasonic sensor give the correct value it will start the video and trigger the relay.
The issue i have is that if the PIR gives a false reading or the user stops moving the video will stop immediately, i need to implement something so that it doesn't stop on the first reading. How would you recommend i could achieve this?
int pirPin = A5; //digital 5
int Screen = 7;
int Play = 2;
int Stop = 3;
int ez1Analog = 0;
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(Screen,OUTPUT);
pinMode(ez1Analog,INPUT);
pinMode(Play, OUTPUT);
pinMode(Stop, OUTPUT);
}
void loop(){
int pirVal = analogRead(pirPin);
int val = analogRead(ez1Analog);
if(pirVal > 0){ //was motion detected
Serial.println(pirVal);
if (pirVal = 1023);
if (val < 40) //Value set from Sensor Test File
{Serial.print(val);
digitalWrite(Play, HIGH);
delay(100);
digitalWrite(Play, LOW);
{digitalWrite(Screen, HIGH);
delay(2000);
} }
else{ delay (2000);
if (pirVal < 5); //pir value set to a minimum of 5 based on readings from PIR Test file
{digitalWrite(Stop, HIGH);
delay(200);
digitalWrite(Stop, LOW);
digitalWrite(Screen, LOW);
}
}}}
Many Thanks