#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx-xxxx";
char pass[] = "xxxxxxxxxx";
#define rele D7
#define pirPin D8 // Input for HC-S501
int pirValue; // Place to store read PIR Value
int portarele = D0; //digital rele output from LDR
int portaLDR = A0; //Analogical LDR input
void setup()/
{
Serial.begin(115200);
delay(10);
Blynk.begin(auth, ssid, pass);
pinMode(rele, OUTPUT);
pinMode(portarele, OUTPUT); //
pinMode(pirPin, INPUT);
digitalWrite(rele, LOW);
}
void loop()
{
ldr();
getPirValue();
Blynk.run();
}
/***************************************************
* Get PIR data
**************************************************/
void getPirValue(void)
{
pirValue = digitalRead(pirPin);
if (pirValue)
{
Serial.println("==> Motion detected");
Blynk.notify("T==> Motion detected");
}
digitalWrite(rele, pirValue);
delay(500)
}
void ldr()
{
int estado = analogRead(portaLDR); //Read LDR
if (estado < 800)
{
digitalWrite(portarele, HIGH);
Serial.println(portaLDR, DEC);
Blynk.notify(portaLDR, DEC);
}
else
{
digitalWrite(portarele, LOW);
Serial.println(portaLDR, DEC);
Blynk.notify(portaLDR, DEC);
}
Hi, people, I try to make an algorithm for home automatization using a motion sensor and a light LDR sensor.
I made this code and de PIR motion sensor works well, but for home automatization, I have two problems that I can’t solve:
1: The motion sensor is sensitive, that made my relay, that control my lamp, go on and off many times. The best solution that I have to solve this was to put a large delay after my lights go on. But it isn’t a good solution because I lose de control from the ESP8266 and also would be necessary to have, for example, 1 min movement, to have 1 min lights on.
What I want is, when some movement is detected that the light keeps on for 1 min, and then go off, if there are no more movements. It also can’t put my WIFI control out of working.
2: The second problem is that it isn’t really smart to keep de lights on every movement of the day. Then I ask you, isn’t any possibility to turn the movement identification in a specific time of the day? Haw?
And with my LDR sensor, I actually have the same problem explain before. But also that my code doesn’t work correctly when I put the LDR light sensor.
Could anyone help me? I would be really grateful and post the final project in the community library.