Skip to content

Alexa Smart Mailbox

Build a smart mailbox that uses Arduino, Raspberry Pi, and Alexa to notify you when mail arrives.

  • Arduino
  • Advanced
  • 150 minutes
  • 6 steps

Shop this project

Cart

Prices from vilros.com. Tax and shipping at checkout.

Before you start, you'll need

  • Arduino Uno
  • Raspberry Pi 3 Model B
  • Proximity sensor (IR or ultrasonic)
  • USB microphone
  • External speaker (3.5mm)
  • Jumper wires

Program Arduino mail sensor

About 20 minutes

Detect mail with proximity sensor.

  1. Connect proximity sensor to Arduino Pin 5.
  2. Connect sensor VCC to 5V, GND to GND.
  3. Upload Arduino sketch to read sensor.
  4. Arduino sends '1' via serial when mail detected, '0' otherwise.
cpp
int sensor = 5;
int mail = 0;

void setup() {
  pinMode(sensor, INPUT);
  Serial.begin(9600);
}

void loop() {
  mail = digitalRead(sensor);
  
  if (mail == 1) {
    Serial.write(1);
  } else {
    Serial.write(0);
  }
  
  delay(1000);
}

Sensor detects mail presence in mailbox.

You should see

Arduino detects mail and sends serial signal.

Install Raspberry Pi software

About 30 minutes

Set up Flask and Alexa integration.

  1. On Raspberry Pi, update system: sudo apt-get update && sudo apt-get upgrade
  2. Install dependencies: sudo apt-get install python2.7-dev python-pip python-serial
  3. Install Flask: sudo pip install Flask flask-ask
  4. Connect Arduino to Pi via USB.

You should see

Required libraries are installed.

Write the Alexa skill backend

About 30 minutes

Create Python server to communicate with Alexa.

  1. Create a Python script on Raspberry Pi.
  2. The script reads Arduino serial data.
  3. Flask-ask creates endpoints for Alexa skill.
python
from flask import Flask
from flask_ask import Ask, statement
import serial

ser = serial.Serial("/dev/ttyACM0", 9600)

app = Flask(__name__)
ask = Ask(app, '/')

@ask.launch
@ask.intent("Check")
def check_mail():
    mail_present = ser.read()
    
    if mail_present == 1:
        return statement("New mail has arrived. Check it soon!")
    else:
        return statement("No mail yet.")

if __name__ == "__main__":
    app.run(debug=True)

Adjust serial port if not /dev/ttyACM0.

You should see

Flask app runs without errors.

Create HTTPS endpoint with ngrok

About 15 minutes

Expose Flask server to internet.

  1. Download ngrok from ngrok.com.
  2. Run: ./ngrok http 5000
  3. Copy the HTTPS URL (e.g., https://abc123.ngrok.io).
  4. This URL will be used for Alexa skill configuration.

You should see

Ngrok provides an HTTPS endpoint.

Configure Alexa skill

About 40 minutes

Set up Alexa Developer Console skill.

  1. Log in to developer.amazon.com/alexa.
  2. Create new skill: Name='MailBoxChecker', Invocation='mailbox checker'.
  3. Add intent: 'Check' with sample utterance 'check the mailbox'.
  4. Set endpoint to ngrok HTTPS URL.
  5. Choose SSL certificate type: 'wildcard subdomain'.
  6. Save and build the model.
  7. Enable skill for testing.

You should see

Alexa skill is created and enabled.

Test with Alexa

About 15 minutes

Ask Alexa about your mail.

  1. Make sure Flask app is running on Pi.
  2. Make sure ngrok tunnel is active.
  3. Say: 'Alexa, ask mailbox checker to check the mailbox'.
  4. Alexa should respond with mail status.
  5. Place mail in mailbox to trigger sensor.
  6. Ask Alexa again—she should confirm new mail.

You should see

Alexa accurately reports mail status.

It didn't work
  • Alexa can't connect to skill.

    Verify ngrok URL is correct in Alexa skill endpoint. Ensure Flask app is running. Check firewall settings on Pi.

What to do next

Stuck? Contact Vilros Support with your board model and what you see on screen.