i am trying to create a security project and i cant develop the email example code to work for the motion sensor instead of sending an email when the button is pressed, i am using an arduino mega with an ethernet shield , what i need is a code that sends me an email when the motion sensor detects motion
thank you in advance .
note : i am really in a hurry with my project so please respond
Hey, this should be very straightforward.
Just write an IF statement… What exactly you don’t understand?
in the email example code i dont know what does what i mean the emailuptime function and the emailonbuttonpress function how i can modify the button press to what i need
But you identify the line of code which sends email, right?
void emailOnButtonPress()
{
// Invert state, since button is “Active LOW”
int isButtonPressed = !digitalRead(2);
if (isButtonPressed) {
BLYNK_LOG(“Button is pressed.”);
Blynk.email("my_email@example.com", "Title", "Body");
}
}
the blink.email line in that function right?
Yes, this single line sends email. You also need the widget installed in fhe app.
Then use regular syntax:
If (something happens){
Blynk.email("my_email@example.com", “Title”, “Body”);
}
Simple
so thats the only line i need to change i dont need to add anything in the void loop or in change something in the setup that might be only working for the push button?
Well, you should have your own code and Blynk running. That’s it
Examples are created to show you how it’s used. Than it’s up to you how to modify it.
ok thank you soo much i am working on it and will send you the results
i was able to get notifications and emails when motion is detcted but the problem is that i dont receive them when the application is not opened on my phone ,is that how it is supposed to work?
and even if the application is opened i dont recieve the notification until i send another command like an led button in the app, once i do so i receive the notification that i might have waited for for 10 minute!!
Your dashboard should be in “running” state in order notification was working. Also notifications are limited with 1 request per 60 seconds. So please organize your code in order to work properly with those restrictions.
by my dashboard in running state you mean that the application is open on my phone right?
and does the same thing apply with sending an email ( does the application need to be open in order for me to receive the email?
by my dashboard in running state you mean that the application is open on my phone right?
No, That’s mean dashboard “play” button is pressed.
but i have done that and the arduino was connected but it wasnt sending notifications or email if the app is minimized , moreover even when the app is open i dont receive a notification or email unless i use a command in the app ,example ( lighting an led from the app ) at this instant i receive the email or notification i was waiting for
Are you on iOS or Android?
Just a quick question: What if I leave the play button on but kill the app on my phone or turn the phone off, will I get the notifications when I turn it on and get into the app?
Yes, you still should get notifications.
i am android …,
here is the arduino code
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
int motionsensor = 8;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "da1d927b5380449384ee24d74bbca36c";
SimpleTimer timer;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
while (Blynk.connect() == false) {
// Wait until connected
}
// Notify immediately on startup
Blynk.notify("Device started");
// Setup a function to be called every minute
// Setup notification button on pin 2
pinMode(motionsensor, INPUT);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), notifyOnButtonPress, CHANGE);
}
void notifyUptime()
{
long uptime = millis() / 60000L;
// Actually send the message.
// Note:
// We allow 1 notification per minute for now.
Blynk.notify(String("Running for ") + uptime + " minutes.");
}
void notifyOnButtonPress()
{
// Invert state, since button is "Active LOW"
if (digitalRead(motionsensor==HIGH)) {
BLYNK_LOG("Button is pressed.");
Blynk.notify("warning motion is detected");
}
}
void loop()
{
Blynk.run();
timer.run();
}