Chat freely about anything...
User avatar
By liderbug
#74580 Success.

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.

Code: Select all#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
}

mailbox.jpg
Shown in quiescent state. S1 is mailbox door - opens(close sw) - powers 8266, D4 is pulled high, Q1 conducts taking "IN" on relay low. RY1 has +5 & Gnd. "IN" enables relay and it closes providing alt path for 5V to relay & 8266. Program sends text and set D4 to 0 volts. "IN" is pulled high, relay releases and we're back to quiescent. If the door hasn't closed by now the code hits deepSleep and the door closing kills the power.
User avatar
By liderbug
#74727 So today the mail came at 1:46
& 1:47, 1:47, 1:48:1:49 & 50 50 50 51 51 51 52 53 and...
Turns out the mailperson stuffed a Amazon box in the mailbox, left it sticking out about 3" so the door wouldn't close and reboot, reboot, reboot, re re re re re... until I got up, hiked to the road and @$$!%!#@!$!! - pulled everything out, closed the door and - ah.... silence.
User avatar
By schufti
#74736 so time to modify the design with momentary switch ...
try with magnet and reed contact
or microswitch that gets activated by notch in the door
or ...

as pure sw solution you could only power off the relay, check if you are still running and send esp to deep_sleep (simply set deep_sleep after some seconds delay past D4 set to low) ... for minimal battery drain; it should resume proper function with the next correct cycle.