Parts list:
1 - 5v solar 30,000 ma battery: https://smile.amazon.com/30000mAh-Porta ... ar+charger
1 - 5v relay: https://smile.amazon.com/gp/product/B00 ... UTF8&psc=1
1 - 2n2222, 1 333 ohm res. 1 1meg res
1 - MiniPro 8266 w ant: https://www.aliexpress.com/item/1PCS-WA ... 0.0.Rt8RZe
1 - mailbox with n/o contact
1 - microUSB female and a small proto board
-------------------------------
The solar battery is mounted on top of the mailbox post. When the mail arrives, door opened, contact closed supplying 5V to circuit. Relay closes supplying 5v to MiniPro and transistor which latches the relay. At this point the mailbox door can close or not the MiniPro will continue to be powered. The program runs until the text msg ("You have SMAIL") is sent to my cell phone. After the message is sent Pin2 (D4) is set "LOW" causing the relay to release and the whole circuit looses power. There is no current draw until the next time the door is opened.
Description of circuit: USB from battery to relay common, relay "VCC", and 1m resistor. 1m resistor to 2n2222 collector & relay "IN". Relay "N/O" to MiniPro 5V vcc. Ground to relay Gnd, transistor emitter, & MiniPro Gnd. MiniPro D4 to 333 resistor to 2n2222 base. The door switch is connected to the 5V battery pin and the relay VCC pin.
The LEDs on the relay come on for about 6 seconds before power is lost. I found I needed the relay (latching) because the delivery person is able to open the door, throw the junk mail in and close the door in under 3 seconds. This is for a remote location. The solar battery could be replace with a 110/220v plug. Also this is for my mailbox. Would wold work for a sump/flood, door/window alarm. I get the text within 9 seconds.
#include <ESP8266WiFi.h>
#include "Gsender.h"
IPAddress ip( 192, 168, 0, 30 );
IPAddress gateway( 192, 168, 0, 1 );
IPAddress subnet( 255, 255, 255, 0 );
IPAddress dns (8, 8, 8, 8);
const char* ssid = "mYSs1d";
const char* password = "myPa550wOrd";
void setup ()
{
pinMode(2, OUTPUT);
digitalWrite(2, HIGH); // set D4 to 0.0 volts (high is 0 and low is 3.3)
WiFi.config (ip, gateway, subnet, dns);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
}
delay (1000);
Gsender *gsender = Gsender::Instance();
gsender->Send("7194399662@vtext.com", "You have SMAIL");
delay (1000);
digitalWrite(2, LOW); // raise voltage on D4 which kills relay dropping all power
// if you watch really close you can see the led just blink ~~ 1/1000 sec
delay (1000); //should never get here
ESP.deepSleep(-1); // or here
}
void loop ()
{
ESP.deepSleep(-1); // or here
}