My project uses ESP8226 to allow: 1) user to set an alarm. 2) after 20 sec of the alarm ringing, it will notify to phone via blynk app using motion sensor. 3) after 40 sec it will turn off sensor and will not send notification again. There are two problems that I have:
- Got error with coding (digitalRead(nilai_sensor, LOW);) "too many arguments to function 'int digitalRead(uint8_t)"
- I need help with coding for turn off the sensor and will not nofify again.
Below is my Arduino 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);
digitalRead(nilai_sensor, LOW);
}
Blynk.run();
timer.run(); // Initiates BlynkTimer
}