Skip to content

Instantly share code, notes, and snippets.

@suadanwar
Created March 5, 2020 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suadanwar/0709aae052062d510b6a886786c9ed9e to your computer and use it in GitHub Desktop.
Save suadanwar/0709aae052062d510b6a886786c9ed9e to your computer and use it in GitHub Desktop.
This sample code is for Mailbox Notification Using Blynk App tutorial.
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1
// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
int sensorPin = 7; // Input pin for the IR sensor
int count = 0; // Mail counter
String stringOne = "You got ";
String stringTwo;
String stringThree = " new mail.";
String message;
boolean prevState = false;
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
}
void loop()
{
Blynk.run();
int state = digitalRead(sensorPin);
if ( state == LOW && prevState == true) {
count++;
stringTwo = count;
message = stringOne + stringTwo + stringThree;
Blynk.notify(message);
}
prevState = state;
}
BLYNK_WRITE(V1)
{
count = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment