Hello!
I have connected a microwave sensor with Arduino Uno. I want to turn on my lamp (with relay board) through the sensor.
I want to make my code such that when the microwave sensor does not sense motion, then after 10 seconds, it should turn on the Lamp for 30 minutes. If it senses motion in between, then it should immediately turn off the Lamp. However, I cannot make that as it is out of my knowledge. Can someone please help me to complete my code?
Please find my code below:
/*
Microwave sensor
*/
int Sensor = A2; //Input Pin
int led = 13;
int period = 5000;
unsigned long time_now = 0;
void setup() {
Serial.begin(9600);
pinMode(Sensor, INPUT); //Define Pin as input
pinMode(led , OUTPUT);
}
void loop()
{
int val = digitalRead(Sensor); //Read Pin as input
Serial.println(val);
if (val == 1){
digitalWrite(led, LOW);
Serial.print("OFF");
}
if (val == 0) {
delay(1000);
if(millis() > time_now + period){
time_now = millis();
Serial.print(time_now+period);
digitalWrite(led, HIGH);
Serial.print("ON");
}
else {
digitalWrite(led, LOW);
Serial.print("OFF");
}
}
}
PLEASE SUPPORT ME AS I AM NOVICE IN CODING.