Arduino Email Sending

Is solidity like cryptocurrency? i mean i am not aiming for the money but with C++ i can build new projects by reusing Arduino and they are not that expensive!

How long does it usually take to learn C++ in time? Do you have any good websites that teach C++?

Yes.

Yes blockchain Smart Contracts.

Yes C++ is spot on for Arduino and the new and improved ESP8266 MCUā€™s, which generally cost less than Arduinoā€™s.

Good questions.
For a keen 14 year old then you should be able to learn enough in a couple of months to build decent Blynk projects. You also need to learn ā€œhow to Blynkā€. I donā€™t have any recommendations for C++ tutorials but any that appear towards the top of a Google / Yahoo search should be fine, but not the paid for ads.

So is there anyway you can help me with the code ? so i will send my already code and you somehow add on it the thing and tell me what widget i should place.

sketch

/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT SwSerial


//#include <SoftwareSerial.h>
//SoftwareSerial SwSerial(6, 11); // RX, TX
    
#include <BlynkSimpleStream.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "************************";

BlynkTimer timer;

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int pinSpeaker = 10;            //Set up a speaker on a PWM pin (digital 9, 10, or 11)
long lastTrigger;                     // wait at least 15s before sending email / push again
unsigned int pir = LOW; // declare variable to store PIR status
char Mail[] = "Dankharl12345678@gmail.com";            //  ENTER YOUR EMAIL ADDRESS
String Subject = "Security System Alarmed";     // subject message
String MsgBody = "Intruder detected has been detected!"; // message content

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
  pir = digitalRead(inputPin);
  if (pir == HIGH) // If alarm enabled
  {
      digitalWrite(ledPin, HIGH);  // turn LED ON
      Blynk.virtualWrite(V0, 255);
      if(lastTrigger == 0 || millis() > lastTrigger + 15123L)
      {         
        Blynk.email(Mail, Subject, MsgBody);  
        lastTrigger = millis();       
      }  
  } 
  else
  {
    digitalWrite(ledPin, LOW); // turn LED OFF
    Blynk.virtualWrite(V0, 0);
  }
}

void setup()
{
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(pinSpeaker, OUTPUT);
  // Debug console
  //SwSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  // Setup a function to be called every 473ms
  timer.setInterval(473L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

I think you have V1 available. Add a display widget on V1 set to PUSH frequency and a label name of Email Count. As you are a Blynk semi-pro now avoid using any frequency other than PUSH, the other frequencies are for noobs.

Code to follow.

what do you mean exactly by label name of email count? like put 100 in the name?

No, put ā€œEmail countā€ without the " ".
Iā€™m doing the coding for the 100, it doesnā€™t go in the app.

ok.

Add a Blynk button on V2 for you to use to manually reset the email count once a day, set as PUSH not SWITCH mode. With more coding experience you can code this to be automatic when the day rolls over.

I have improved the email code so you donā€™t need it in the sketch as you have your email address in the email widget. Just add your token and flash it to the Arduino. Search the sketch for each entry of ā€œCostasā€ and ask yourself what the code / comment is for.

// DubaiPIR.ino 7 March 2018 PIR with email notification, limited to 90 emails per day
/* Comment this out to disable prints and save space */
//#define BLYNK_PRINT SwSerial               // Costas, SwSerial entries can only be used with a USB2TTL adaptor with USB connection to Blynk server
//#include <SoftwareSerial.h>
//SoftwareSerial SwSerial(6, 11); // RX, TX
// Costas V0 LED, V1 value display of email count, V2 email count reset button, V5 value display of millis     
#include <BlynkSimpleStream.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "************************";  // Costas, never show your actual token in written or image format to the public

BlynkTimer timer;

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
//int pinSpeaker = 10;            // Costas, no longer required WAS Set up a speaker on a PWM pin (digital 9, 10, or 11)
long lastTrigger;                     // wait at least 15s before sending email / push again
unsigned int pir = LOW; // declare variable to store PIR status
//char Mail[] = "not required";  //  Costas, I have improved the email section so you don't need anything here
String Subject = "Security System Alarmed";     // subject message
String MsgBody = "Intruder detected has been detected!"; // message content
unsigned int emailsSentToday;    // Costas, count how many emails sent today

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
  pir = digitalRead(inputPin);
  if (pir == HIGH) // If alarm enabled
  {
      digitalWrite(ledPin, HIGH);  // turn LED ON
      Blynk.virtualWrite(V0, 255);
      if(lastTrigger == 0 || millis() > lastTrigger + 15123L)
      {         
        if(emailsSentToday < 90) // Costas     // send emails whilst counter is from 0 to 89 (90 emails)
        {
          //Blynk.email(Mail, Subject, MsgBody); // Costas, line below is better but make sure your email address is in the widget
          Blynk.email(Subject, MsgBody);         // Costas, I can see your email address in the email widget so you are good to go
          lastTrigger = millis();
          emailsSentToday++;                     // Costas, add 1 to the counter
          Blynk.virtualWrite(V1, emailsSentToday);  // Costas, send email count to Blynk app
        }                                        // Costas, close if statement braces  
      }  
  } 
  else
  {
    digitalWrite(ledPin, LOW); // turn LED OFF
    Blynk.virtualWrite(V0, 0);
  }
}

BLYNK_WRITE(V1)                     // Costas, new function for value display widget on V1
{
  emailsSentToday = param.asInt();  // Costas, get last known email count from server in case Arduino reboots during the day
}

BLYNK_WRITE(V2)                     // Costas, new function for Blynk button to MANUALLY reset email count once a day
{
  emailsSentToday = 0;              // Costas, button in PUSH mode, not switch mode will clear the variable (twice) 
}

BLYNK_CONNECTED()                   // Costas new function, sync V1 widget each time Arduino connects to Blynk server
{
    Blynk.syncVirtual(V1);          // Costas, get emailsSentToday from Blynk server if Arduino reboots during the day.
}

void setup()
{
  pinMode(ledPin, OUTPUT);          // declare LED as output
  pinMode(inputPin, INPUT);         // declare sensor as input
  //pinMode(pinSpeaker, OUTPUT);    // Costas, no longer required 
  // Debug console
  //SwSerial.begin(9600);

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Serial.begin(9600);
  Blynk.begin(Serial, auth);

  // Setup a function to be called every 473ms
  timer.setInterval(473L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

I will flash the Arduino with the code now but what do you mean by search the sketch for each entry of Costas and ask yourself wha the code / comment if for?

So do i still keep the display on V2? i am still not getting the email count on it!

I forgot to add that bit, will edit the sketch and let you know when to reflash.

okā€¦

OK i have added the missing line in the last sketch. The line is:

Blynk.virtualWrite(V1, emailsSentToday); // Costas, send email count to Blynk app

If you look in the sketch you will see the word Costas all over the place.
Coding basics:

In the Arduino IDE you can search for things, normally variables but any word you like.
Use the IDE search facility to find each ā€œCostasā€ and learn about coding. I am trying to teach you to fish rather than your request for me to give you some fish. Fish is just a metaphor for software code.

i get it but i saw you put cost-as ever-where and i read everything.

1 Like

Where do i put this? What part of the sketch? NVM

If you mean the extra line of code itā€™s in the revised version of the full sketch.

I understood that, it still doesnt work i think you want the second display on v2 instead of v1?

Yes sorry V2 is the button, use V1 in the new line. Iā€™m a terrible coder :slight_smile: