I have combine the circuit:
And the code:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define LDR A0
#define PIR1 11
#define LED1 12
#define PIR2 8
#define LED2 13
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "******************************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Redmi 3s";
char pass[] = "*********";
int pirState1; // define numeric variables val for PIR1
int ldrValue;
int pirState2 = 0;// define numeric variables val for PIR2
//int buzzer = D1 ;// define buzzer Interface
int flame = 2; // define the flame sensor interface
int analoog = A1; // define the flame sensor interface
int val ;// define numeric variables val
float sensor; //read analoog value
BlynkTimer timer;
void readSensor1()
{
ldrValue = analogRead(LDR);
if (ldrValue <= 270) { // dark
digitalWrite(LED1, HIGH);
}
else {
pirState1 = digitalRead(PIR1);
if (pirState1 == HIGH) {
digitalWrite(LED1, HIGH);
delay(1000);
digitalWrite(LED1, LOW);
delay(1000);
}
else { // pirState1 == LOW
digitalWrite(LED1, LOW);
}
}
void readSensor2()
{
pirState2 = digitalRead(PIR2);
digitalWrite(LED2,pirState2);
if (pirState2 == 1)
digitalWrite(LED2,LOW);
}
void readSensor3()
{
sensor = analogRead(analoog);
Serial.println(sensor); // display temperature
//long uptime = millis() / 60000L;
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V1, millis() / 1000);
val = digitalRead (flame) ;// digital interface will be assigned a value of 3 to read val
if (val == HIGH) // When the flame sensor detects a signal, buzzer beep
{
//digitalWrite (buzzer, HIGH);
Blynk.email("nurlela.dabukke@gmail.com", "Flame!!!", "Sensor activated");
}
//else
//{
// digitalWrite (buzzer, LOW);
//}
// Actually send the message.
// Note:
// We allow 1 notification per 15 seconds for now.
//Blynk.notify(String("Running for ") + uptime + " minutes.");
}
void setup()
{
pinMode(LED, OUTPUT);
pinMode(PIR1, INPUT);
digitalWrite(LED1, LOW);
pinMode (LED2,OUTPUT);
pinMode (PIR2, INPUT);
//pinMode (buzzer, OUTPUT) ;// define buzzer as output interface
pinMode (flame, INPUT) ;// output interface defines the flame sensor
pinMode (analoog, INPUT) ;// output interface defines the flame sensor
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
// Notify immediately on startup
Blynk.notify("Device started");
// Notify immediately on startup
if(val==HIGH){
//Blynk.notify("Flame!!!");
//Blynk.email("nurlela.dabukke@gmail.com", "Flame!!!", "Sensor activated");
// Setup a function to be called every minute
timer.setInterval(10L, readSensor);
}
// Setup a function to be called every 200ms Costas
timer.setInterval(150L, readSensor); // Costas
//Blynk.email("nurlela.dabukke@gmail.com", "Flame!!!", "Sensor activated");
}
void loop()
{
Blynk.run();
timer.run();
}
I want to combine Wemos to Arduino, but I still don’t know how to call the function if I have three functions. By the way, the LDR and both PIR don’t need connect to WiFi. Could you help me to fix it?