E-mail notification of my snail mail box

I just got my first two Particle Photons. I have already created a little device that sits on the back of my mailbox and can tell me if the box is closed (photo resistor reads 0) or if the door is open (photo resistor reading is > 1)

I have the box installed outside and it’s being fed by a solar panel. I can see it from both the online site and the iOS app.

Normally I would write a program that would say:

void loop() {
int sensorRead = analogRead(A0);
If (sensorRead > 1) {

What libraries or commands(functions) do I use to “Send email to myemail@domain.com.”?


You can use something like IFTTT or webhooks that triggers to a email provider like Mailgun maybe


I was just thinking about doing this myself after checking to see if the mail had been delivered today about 5 times :smiley:

If you want to do it the easy way then checkout www.Ubidots.com since they make it really easy to setup triggers to send emails or SMS text messages. There are some examples on their site and on this site for how to setup the code.

Yeah, I agree with @kennethlimcp, I’d probably do this with a webhook, rather than trying to do SMTP directly from the Photon. I mean, SMTP is pretty simple (if you don’t need TLS or anything), but it’s still more work than is necessary. If I were personally doing this, I’d most likely have the webhook call an AWS Lambda function via the Amazon API Gateway, and have the Lambda function send the mail via my service of choice. But if you already have a webserver running somewhere, you could run it there too (I just like the Lambda solution because it’s totally independent of any of my servers).

Hi @axexgabe,
if the email is not a hard requirement, you could use Pushbullet to send you push notifications to your devices (phone, tablet, browser).
I wrote an article on how to achieve that here:

good luck!

Hey Gustavo,
Thank you for your suggestion. I followed your steps, but it is not working. Here is a copy of my JSON code/config.

  "eventName": "pushbulletHOME",
  "url": "https://api.pushbullet.com/v2/pushes",
  "requestType": "POST",
  "headers": {
    "Authorization": "Bearer o.cw8Wlh6SKGpp5HpxAxhzM35yNt83absG",
    "Content-Type": "application/json"
  "json": {
      "type": "note",
      "title": "{{SPARK_EVENT_VALUE}}",
      "body": "",
      "channel_tag": "antiquemail3456"
  "mydevices": true

I think it would help me if you could explain each element on this code/config.

It works!! Thank you @RWB.
Now, does anyone have any suggestions on how to make the device go to low-power mode at night and wake up in the morning, or at least turn off the WiFi at night? The device uses up the battery at night and when it comes back up in the morning it does not automatically connect to the WiFi network. :grimacing:

1 Like

An opamp to the wakeup pin or use a service that tracks sunrise/set and use regular deep sleep mode.

Hi, you can find all the info on those fields here:

@axexgabe You can use the Real Time Clock feature to set the Sleep and Wake up times.

Or I would just use the light sensor on the WKP pin set so a rising edge input will wake up the Photon from sleep and then run your code to send you notification and then go back to sleep until the Light sensor get’s hit with light again when the mail box is opened.

1 Like

Followed @MORA’s link and created a code that runs then places the device to sleep until input is detected on A0 as @RWB suggeted.

#include "Ubidots/Ubidots.h"
#define TOKEN "EyzIQwcR1wgtpXG9hdvgZ7uZzWCySL"

int photoResistor = A0;
int dotRead = 0;

Ubidots ubidots(TOKEN);

void setup() {

void loop() {
  dotRead = analogRead(photoResistor);
  ubidots.add("Status", dotRead);
  System.sleep(photoResistor, RISING);

It now runs once, then it goes to sleep but no input from the photo resistor on A0. Even a direct flash light on the photo resistor will not wake the system. Here are couple of pics from the device.

Any sugestions?

I can’t quite tell if the photo matches the schematic, but the schematic is definitely wrong. You show A0 connected to ground when it should be connected to the junction of the resistor and the photoresistor.

I’d drawn the schematic wrong. Now the schematic matches the actual configuration. Is my resistor’s value 47 ohm @ 1% to high? I would get a value of 0 when the mailbox was closed and a value 2 - 5 when the door was opened.

I’d rather think 47Ohm might be a bit low (quite a bit).
Have you measured the resistace of your photo resistor dark and lit?
Do the voltage division.

Your pull-down should be at least twice the resistance of your photo resistor when lit (not full brightness but your expected illumination when installed) to get a voltage up to at least 2/3 Vcc.

I eliminated the resistor (see schema) and now it is working as it should. What gives?

You resistor setup was keeping the output voltage below 2.5v I bet.

Glad it’s working now though.

This proves my point :wink:
You actually now have an “infinite” resistor to GND in series with the photo resistor.

But this only works due to the finite internal resistance of A0 to GND. Without it there would be no current flowing through the photo resistor resulting in zero voltage drop across it causing 3.3V on either side of it and A0 being stuck on HIGH.
The thing not obvious is, that System.sleep(pin, RISING) does in fact attach a pull-up resistor which is 40 ~ 50k and hence it does work for waking the device.


I guess I wasn’t clear with the resistance values. I thought the lower the number the lower the resistance. So it is the oposite then? The higher the number the lower the resistance?

Nope, the lower the number the lower the resistance, but the lowest resistance (0.0Ω) is a direct wire and no wire at all is “infinite” resistance (∞Ω).
The reciprocal value of resistance (unit Ohm) is conductance (unit Siemens), so 1/0.0Ω = ∞S (infinite conductance = ideal conductor) and 1/∞Ω = 0.0S no conductance what so ever (ideal insulator - like in your sample towards GND).