Hi there, I need help with my project (Smart Pillow) using Blynk app.
Let me brief a little bit about my project.
-
- User can set alarm
-
- After 20 sec alarmed, (if the user still sleep) it will notify to the phone using the motion sensor (rcwl-0516).
-
- After 40 sec, it will turn off sensor and will not notify again.
The problem that i had is at the “3)” which I cant turn off the sensor.
need help with the code.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
BlynkTimer timer;
WidgetRTC rtc;
WidgetLED led1(V10);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "a7d4522186464dd297870f2ab8e53250";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "NabiL";
char pass[] = "limaringgitlimapuluhsen";
int flag = 0;
int buzzer = 12;
int motor = 13;
int sensor = 4;
int saat;
int on_delay;
int off_delay;
int ok_delay;
int get1 = 0;
int get2 = 0;
int nilai_sensor = 0;
void blinkLedWidget()
{
if (led1.getValue()) {
led1.off();
Serial.println("LED on V1: off");
} else {
led1.on();
Serial.println("LED on V1: on");
}
}
void clockDisplay()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details
String currentTime = String(hour()) + ":" + minute() + ":" + second();
String currentDate = String(day()) + "/" + month() + "/" + year();
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print("Current Time: ");
Serial.print(currentDate);
Serial.println();
// Send time to the App
Blynk.virtualWrite(V1, currentTime);
// Send date to the App
Blynk.virtualWrite(V2, currentDate);
}
BLYNK_CONNECTED() {
// Synchronize time on connection
rtc.begin();
}
BLYNK_WRITE(V5) // Timer
{
Serial.println(param.asStr());
if (param.asInt())
{
on_delay = saat + 20; //20Saat
off_delay = saat + 10; //10Saat
ok_delay = saat + 40; //40Saat
digitalWrite(buzzer, HIGH);
digitalWrite(motor, HIGH);
}
}
BLYNK_WRITE(V6) // Timer
{
Serial.println(param.asStr());
if (param.asInt())
{
on_delay = saat + 20; //20Saat
off_delay = saat + 10; //10Saat
ok_delay = saat + 40; //40Saat
digitalWrite(buzzer, HIGH);
digitalWrite(motor, HIGH);
}
}
BLYNK_WRITE(V0){
Serial.println(param.asStr());
if (param.asInt())
{
digitalWrite(buzzer, HIGH);
digitalWrite(motor, HIGH);
}
else
{
digitalWrite(buzzer, LOW);
digitalWrite(motor, LOW);
}
}
BLYNK_WRITE(V12){
Serial.println(param.asStr());
if (param.asInt())
{
digitalWrite(buzzer, HIGH);
}
else
{
digitalWrite(buzzer, LOW);
}
}
BLYNK_WRITE(V13){
Serial.println(param.asStr());
if (param.asInt())
{
digitalWrite(motor, HIGH);
}
else
{
digitalWrite(motor, LOW);
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
// Display digital clock every 1 seconds
timer.setInterval(1000L, clockDisplay);
timer.setInterval(1000L, blinkLedWidget);
// Setup notification button on pin D1
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(4, INPUT);
}
void loop()
{
saat = millis() / 1000;
if(saat == off_delay)
{
digitalWrite(buzzer, LOW);
digitalWrite(motor, LOW);
}
if(saat == on_delay)
{
Serial.println("Time Up");
get1 = 1;
}
if(get1 == 1)
{
Serial.println("Program Sensor");
nilai_sensor = digitalRead(sensor);
if(nilai_sensor == HIGH)
{
Serial.println("Still sleeping");
Blynk.notify("Still sleeping");
//delay(5000);
}
}
if(saat == ok_delay)
{
Serial.println("Shut Down Sensor");
get2 = 1;
}
if(get2 == 1)
{
Serial.println("turn off Sensor");
nilai_sensor = digitalRead(sensor);
digitalWrite(nilai_sensor, LOW);
}
Blynk.run();
timer.run(); // Initiates BlynkTimer
}