How can I make a PIR motion sensor work only at night?
i.e I want this to work time based like 6.00 PM to 6.00 AM using Program and not using LDR.
Chinese PIR sensors sold on Ali have a light setting - you can set it to work only in the dark, for example
Sorry, do not seen that you not want to use LDR...
Which board are you using ?
A universal solution would be to use a Real Time Clock (RTC) and ignore the PIR outside of the required hours
If you use the right board then the RTC would not be needed and you could get the time from the Internet
No, I want a Arduino code to Work in time based and not by hardware
Can you send me the Arduino Code for time based working
This forum is not used in this way. Try to write the code yourself and if there are problems - ask questions
No I can't
You are expected to do some work for yourself. If you have problems then you will get help here but no work on your part equals no help I am afraid
If you want to pay someone to write the code for you I can move it to the appropriate forum section. Is that what you want ?
Okay, no LDR, no RTC… s'gonna be hard.
Is it OK to use wifi and get time from the internets?
a7
Yes
Yes to what ?
Keep track of time on a 24 hour basis, and use an if statement something like this one
if (hour < 6 or hour >= 18) check_sensor();
#include <NTPClient.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int pirPin = 14;
int relayPin = 5;
int pirValue;
const char *ssid = "Redmi_router";
const char *password = "123567";
const long utcOffsetInSeconds = 3600;
char auth[] = "Auth_Token";
// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
void setup(){
Serial.begin(115200);
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 );
Serial.print ( "." );
}
timeClient.begin();
Blynk.begin(auth, ssid, pass);
pinMode(pirPin, INPUT);
pinMode(relayPin, OUTPUT);
}
void loop() {
timeClient.update();
Serial.print(timeClient.getHours());
Serial.print(":");
Serial.print(timeClient.getMinutes());
Serial.print(":");
delay(1000);
if(Hour<6 or Hour>=18){
{
Blynk.run();
pirSensor();
if (pirValue == HIGH)
{
digitalWrite(relayPin, LOW);
}
else
digitalWrite(relayPin, HIGH);
}
}
}
void pirSensor()
{
pirValue = digitalRead(pirPin);
Blynk.virtualWrite(V0, pirValue);
}
just a sketch. Posted in the wrong format. No question.
If you declared the variable Hour in your code I don't see it.
If you did anything in your code to make Hour be related in any way to the time of day, I don't see it.
Where are those two completely necessary and essential steps being taken?
Are you getting compiler errors telling you anything?
a7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.