Introduction: Smart Mail Box

Use Case:

Although we live in a connected world where we expect instant notification when any significant event happens in our lives, there is no way to notify residents when a mail arrives in their mail box. This leads mailbox owners to check their mail every day, even if there is no mail for them. And on the other hand, residents may tend to miss/lose important mails when not checked regularly.

Smart mailbox is the solution for this real life problem, whenever a postal service representative delivers mail into resident’s mailbox. The user receives an SMS, notifying the delivery of a new mail. (Video link:

User Flow:

  • Installation of motion sensor, laser emitter and photo resistor inside mail box
  • Resident registers his phone number at the Twilio node
  • Resident starts receiving text message when mail or package is inserted in the box

Laser emitter is installed on one end of the box (inside the box) and photo resistor on the other end. A PIR motion sensor is installed at one corner of the mailbox pointing towards the door.

Ideally in an activated circuit a laser beam passes from one end of the mailbox to the other end with PIR motion sensors at status zero.

Whenever a mailman opens the door and inserts a mail, laser beam gets broken and PIR motion sensor senses motion to sets it status at one. Once the circuit identifies a set of activities, it triggers a message through twilio node in the node red flow to a pre-registered phone number.


Below team of people from Perficient Inc contributed to this IoT project.

  • Hemanth Volety
  • Harshavardhan Vishwanath
  • Paul Raj
  • Satyam Singh

Step 1: Gather Required Components

  • 1 X Raspberry Pi 3 Model B - $35
  • 1 X Bread board - $6
  • 1 X Laser emitter - $6
  • 1 X Photo resistor - $1.50
  • 1 X 10 Micro farad capacitor - $3
  • 1 X PIR motion sensor - $2
  • 10 X Jumper wires (combination of male and male to female) - $5
  • 1 X power bank - $7
  • 1 X cell phone

Step 2: Setup Your Rasperry Pi

Get the latest copy of Raspbian from:

Copy the image on to the SD card from your laptop: This can be done through third party app like Pi Filler or Pi Copier.

Place the SD card in the SD card slot of raspberry Pi and power up the Pi with the power bank. This would boot the Pi and loads Raspbian image up and running.

Latest version of the Pi comes with Wi-Fi and Bluetooth capabilities. Make sure that you have enabled SSH and VNC commands from Pi configuration section to remotely access the Pi through your laptop.

Step 3: Connect Your PIR Motion to Pi:

Connect VCC pin to PIN 1 or PIN 2 on the PI for power supply, GND pin to any of ground pin on the PI. Connect Signal of the PIR motion sensor to any of the GPIO pins of the PI.

This is a digital sensor and all the PINS of PI are digital pins hence whenever there is a motion detected the signal send 1 as input.

Step 4: Connect Laser Emitter to the PI:

Connect VCC PIN to power supply pin on Raspberry PI, SIG PIN to any of the GPIO pins on PI. If the laser is a 3 PIN emitter then connect the 3rd PIN to ground on the PI.

The laser emitter activates only when the state of the GPIO pin is changed, by default the input value is set 0. Whenever it is set to 1, the emitter gets activated.

Step 5: Connect Photo Resistor Circuit:

Connect one end of the photo resistor to the power supply and the other end to the signal (any GPIO pin on the PI). Place a 10-microfarad capacitor signal and GND; connect the negative pin of the capacitor to the signal and positive to ground.

A capacitor works on the similar bases of a rechargeable battery. Whenever there is an intense light focused on to the resistor the capacitor charges up, stores the electrons and sends low value as the signal. Once the intensity of light reduces then the capacitor starts discharging and providers higher values at GPIO pin as signal.

In this entire design the photo resistor and capacitor combination works as an analog sensor. As the PINs on PI are digital pins PI decides a threshold value or a cut off point to decide if the signal is high or low and then sets the status on the PIN.

Step 6: Assemble All:

Make sure you have separated out all the GPIO pins for these 3 circuits. If you are connecting multiple signal to the same GPIO Pin then one signal input can reset the other circuit.

Place the PIR motion sensor on one corner of the mailbox pointing towards the door. Place the photo resistor to one end of the box and laser emitter on the other end pointing towards the photo resistor.

Step 7: Node-Red Flow:

Node-red is used to maintain synchrony between these input signals and process that signal data to receive instructions to the end device. Node red comes pre-installed on the raspberry pi 3.

To initiate node red run the following commands from command prompt or terminal

  • SSH pi@<ip address>
  • Node-red-start

Get the ip address and port number on which the node red is started

By default port is set to 1880

Twilio is a cloud communication platform used to send programmable messages over the network to other connected devices.

Usually twilio doesn’t come in outbox node red for raspberry pi. Whenever you want to install twilio node, run the following commands on your raspberry pi terminal

  • sudo apt-get update
  • sudo apt-get install npm
  • npm install node-red-node-twillio

sign up with twilio:

This would provide you a phone number which can be used for programmable messaging.

While coming back to node flow, register a phone number to which you want to receive message notifications and deploy the flow on raspberry pi.

Check Beam status:

newMsg = {topic:'laserBeam'};

if (msg.payload === 0){

return {topic:'laserBeam', payload: true};

} else

return null;

Check Motion:

newMsg = {topic:'motionSensor'};

if (msg.payload === 0) {

return {topic:'motionSensor', payload: true};}


return null;

Final check:

context.beam = context.beam || false;

context.motion = context.motion || false;

if (msg.topic === 'laserBeam') {

context.beam = msg.payload;

} else if (msg.topic === 'motionSensor') {

context.motion = msg.payload; }

if (context.beam && context.motion) {

return {topic: 'mail', payload: 'Hey !!! You got a New mail :-)'};

} else {

return null;


if (context.motion && context.beam === false){

return {topic: 'mail', payload:'something fishy!!!'};



return null;

Step 8: Congratulations You Have Your Smart Mailbox Up and Running…!!!!

Green Electronics Contest 2016

Participated in the
Green Electronics Contest 2016

IoT Builders Contest

Participated in the
IoT Builders Contest

First Time Authors Contest 2016

Participated in the
First Time Authors Contest 2016