Introduction: Raspberry Pi IoT Doorbell

Picture of Raspberry Pi IoT Doorbell

This Raspberry Pi, IoT Doorbell is basically a simple smart Door Bell, which takes a photo of whoever rings it, and emails it to the specified email address, and keeps all the photos in a folder. (along with going Ding-Dong). This is my first Instructable so I hope you enjoy :)

How I have set out setting this up is: OLD:

the camera is looking at the door bell. I couldn't have the camera above the box because my lead is not long enough

If you wish to use the pi camera instead of a webcam:

nodes19chamb and MichaelM1252 have commented some code that should help! Thx guys.


I have Got a new setup where the Button Cable is routed through a small gap in a window next the frount door where the camera taped so it is looking out the window,

PS: The camera quality in my examples is bad because I have a bad camera.

Step 1: Parts/ Tools

Here is the list of parts with approximate prices and links, though you don't need to buy these exact parts

NOTE: :Project costs around $110, Though price can be made cheaper/ more expensive depending where you buy the parts, or using an RPi 1/2.


Raspberry pi $55, I've linked Raspberry pi 3, though any should work, though you will need a Wifi adapter if you wish this project to be wireless. You can also use the Raspberry pi 1 B and save $20

Wi-Fi Adapter $10You don't need this if you're using ethernet or RPi 3.

Pi Case $14You don't need this but i recommend it so your pi doesn't get damaged.

Mini Breadboard $1.29 to do wiring on

Button $1.29 (waterproof, Normally Open)

Lengthy wire, to from pi to doorbell

1K resistor, $2.48required for button circuit (only one needed)

Bread Board Jumper Cables $5.19 - you only need 3 :)

Webcam $4 - $100

Box to hold button in $2-10



Soldering Iron (Recommended)

Wire Stripers

Side Cutters/Sharp scissors



Step 2: Setting Up Hardware.

Picture of Setting Up Hardware.



I made some mistakes:

It is 5v not 3v

It is 10K Resistor not 1K


If you are using a non B+ Model

you will have to use GPIO 7 (or other) instead of 21!


Hardware is pretty simple. Plug your Webcam into the Rasp-pi, along with your selected network interface. Then, using the images as a guide (the wiring diagrams + this pinout for rasp pi 1B), connect your button and resistors to the pi. With the breadboard image, the orange and blue wires are the wires running the the door bell (Project Box with button).

Step 3: Making the Door Bell

Picture of Making the Door Bell

To Make the door Bell you will need to cut a 12mm (1/2") hole in the centre of the project box, and around a hole near the bottom for your wires. Im my case I have taped over the bottom hole(and wires) to stop water from coming in.

Step 4: Software & Programing

Now This is the harder part. First off SSH into your Pi (Raspbian Wheezy or Later).

--- Wondering how to SSH?

here you can find instructions by Antares72 for setting up SSH on Windows with the Pi

Or see here for instructions for Linux or Mac users.


For the "Advanced Users, I have put comments in the code explaining how it works

Follow these instructions (Once in the command line) (copy exactly

Remember to NOT copy the " $ " in these commands if you are copy and pasting.

First, make sure your in your home directory (or whatever directory you wish to install the program to ( PS: it is contained in one folder, so it won't go everywhere in your home directory)

$ cd ~

Then we want to download the dbell folder containing all the code:

$ git clone

Now we want to CD into the directory

$ cd dbell

$ mkdir photos

-------VERY IMPORTANT!!!!!! -------

# NOTE: If you do not use B+ Model, you will need to change the "Button" variable in from 21 to a # pin number that's available on your pi. TO do this do

# $ nano

# and change the Button = 21 line to something like Button = 7

# Pinouts are on the "Setting Up Hardware" Setting Up page

Now our setup is time to start editing the email code.

Step 5: Gmail Setup

Picture of Gmail Setup


To be able to send an email with a photo, the raspberry pi needs its own email account. For this we use GMAIL. So click here to sign up for a Gmail account. You can use one you have already created, but you will not be able to receive the notification, that someone is at your door, with it. Also, we will be disabling some security features, making your account more vulnerable to hackers. Step 1a: To Google, the raspberry pi is an "Insecure" Device, so we need to let Google let unsecured devices, (i believe this means devices not using https) login. To do this we:

1. Follow this link (opens in new tab), and log in with your "raspberry pi's" Gmail account you just created.

2. Scroll down to the bottom of the page and you'll see an "Allow login from less secure apps" card. Click the switch to change it to yes. (image of no state above)

Step 6: 3.5.6) Email Script Customisation

Ok Now we setup the Gmail account we can now set up the Email Script. I would like to give credit to Gagandeep Singh, for his code is used in the IoTNotify script, And Sentdex, for his tutorial on python email tutorial, which allowed me to understand the process.

For the more advanced users who want to know how this works, Check out Sentdex's tutorial as I have not explained at all how this script works.

Now do this:

$ nano

and change the following values:

Do this for all of the Fields

to the Gmail account email address E.g:

Yeah, Ass-Word, Wops, Spelling Mistake...

to the email you want to be notified at (eg: your personal email that on your phone, so your phone goes "Buzz" When someone's at the door)

After you have changed all the values, press Ctr X, then Y to save the document

Step 7: 4) Running the Code

Picture of 4) Running the Code


$ python3

And the script will repeat forever until you press Ctrl Z or Ctrl C


If there is any problems with the script, or i did something wrong, feel free to leave your feed back below (in comment form)


I hope you enjoyed this instructable :)


rajvish made it! (author)2017-11-12


I am getting this error: line 6: fswebcam: command not found

I am using Raspberry Pi 3 v2 and SainSmart Camera ModuleB for the project. I also changed the email ID. I have attached the photo of the same. Please help me out to debug this.

ÉdgarS57 made it! (author)2017-10-13

I have this error

Traceback (most recent call last):

File "", line 29, in <module>


File "/usr/lib/python3.5/", line 729, in login

raise last_exception

File "/usr/lib/python3.5/", line 720, in login


File "/usr/lib/python3.5/", line 641, in auth

raise SMTPAuthenticationError(code, resp)

smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 x135sm60609vke.32 - gsmtp')

Proceso terminado.

The username and password is correct. I have disabled apps no secures in Google. Please, help me

AngusC5 (author)ÉdgarS572017-10-13

Hi Edgar, Are you using 2 step verification? If you are that would most likely be the problem, try the troubleshooting steps under this link:

Also by the "bad credentials" Error, It seems to be a problem with your credentials, those troubleshooting steps should fix things. LetmeKnow if it works.

ÉdgarS57 (author)AngusC52017-10-13

Hi, thank you for your quick response. I already tried that steps, but the problem still :(

AngusC5 (author)ÉdgarS572017-10-22

Hi Edgar, sorry for the late response, but make sure you have "enabled" allow less secure devices! Not dissabled it. Thx

Darshanm15 (author)2017-05-08

i have this error please help to solve

what should i do


Traceback (most recent call last):

File "", line 29, in <module>


File "/usr/lib/python3.4/", line 652, in login

raise SMTPAuthenticationError(code, resp)

smtplib.SMTPAuthenticationError: (534, b'5.7.14 <\n5.7.14 I7caO_mMTlDCB5rUCEs-jGeqFe5ueUJTU75ApgdYJe-xePRmstwRm6bYLxKfnUC4NfAzAK\n5.7.14 TXC0QiaEdSNSsQQaQWR_cP43lU91PLFtnHaYHlz4Sr-9btEp8xdG-p_31EipeApWRTtXKu\n5.7.14 CxQiMALZSOj3VX80HsM332g4LCFnKyXulB-DMwhFZLy64XmiC9iQCpwNXFSBLfgjwQI7yO\n5.7.14 rNc2kyoDRxQxkYYTMMSqZt4kjVyUA> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 y6sm21630291pgc.40 - gsmtp')

Done Process

AngusC5 (author)Darshanm152017-10-06

Hi, I have since updated the email account process above, thank you for posting this error though, as you have made me aware of this issue, which I have now fixed, so more people can use this project :). Here is how to fix your issue:

Also, we will be disabling some security features, this may make your account more vulnerable to hackers, so I recommend making a new account. Step 1a: To Google, the raspberry pi is an "Insecure" Device, so we need to let Google let unsecured devices, (i believe this means devices not using https) login. To do this we:

1. Follow this link (opens in new tab), and log in with your "raspberry pi's" Gmail account you just created.

2. Scroll down to the bottom of the page and you'll see an "Allow login from less secure apps" card. Click the switch to change it to yes. (image of no state above)

MichaelM1252 (author)Darshanm152017-05-25

Darmish Did you get this working?

Looks like an authentication error on gmail

BTW did you change your password? You gave your password "Myoldjeans" away while cutting and pasting.

I would like to continue this project so I am interested in what others have done.

Thanks MM

AngusC5 (author)Darshanm152017-05-08

Hi Darmish, I will have a through look today. To help could paste in the contents of in here so I can see what changes you've made. (That the Instructables asked you to do). Before that make sure you've filled out all the fields

mulisamlivo (author)2017-10-06

does the end user have an interface where he/she can add/edit the email address considering that the end user has no python skills

AngusC5 (author)mulisamlivo2017-10-06

No, this tutorial I believes steps you through on how to do this. This is just meant to be a simple python project to get people's skills up.

mulisamlivo (author)2017-10-06

how do i remove the loop

so that it does not auto press itself

AngusC5 (author)mulisamlivo2017-10-06

you need the loop to look for the button press, if it is auto "pressing" then change the value on line 13:

if GPIO.input(Button) ==False: #when button pressed

change false to 1 or true, if this dosen't work,you have wired the button incorectly.

mulisamlivo (author)2017-10-06

is there a code that i can run to make the doorbell make a live video call to the end user

AngusC5 (author)mulisamlivo2017-10-06

you can use a program called motion, that makes the pi into a live stream camera, then you can have the doorbell just notify you with a link to the stream. please note though, without port forwarding, this will only work in the LAN of the pi, here is a link to a tutorial (note i have not teied this exact tutorial myself)

MichaelM1252 (author)2017-05-23

I love this made it on Pi3

changed the gpio setup to BOARD

AngusC5 (author)MichaelM12522017-07-09

Thanks for all your information you've put down here about using the pi camera instead.

JaimishA (author)2017-03-29

I'm getting the following error when I run the python file:

Traceback (most recent call last):

File "", line 6, in <module>


AttributeError: module 'RPi.GPIO' has no attribute 'setmode'

I've tried everything. Please help, urgent!

MichaelM1252 (author)JaimishA2017-05-25

Hi Jaimish. I made this on Pi3 but changed

the gpio setup to BOARD

AngusC5 (author)JaimishA2017-03-31

Hi JamishA, I think the problem is on your side. What version of the raspberry pi do you have, and what version of raspbian is it running? And have you done any other projects using the GPIO pins on the pi? Then, I will be able to have more information on how to solve your issue. Thx, Angus.

AngusC5 (author)JaimishA2017-03-29

Hi JaimishA, I am currently away from my PC, so in around a day or so I should get back 2 you with the answer to your problem

nodes19chamb (author)2017-05-24

To use the pi cam


added "from picamera import PiCamera"


changed the command to take the photo. Used raspistill without any switches.

I left the old USB there as a comment for my own purposes.


cd photos

echo "Taking the Photo"

now=$1 #Now is the filename time stamp

#take pic

# MM commented out to switch to PI Cam. fswebcam -d /dev/video0 -r "640x480" $now.jpg

raspistill -o $now.jpg

echo "Pic Taken"


#ring Bell

echo "Ringing Bell"

echo ""

echo ""

cd ..

omxplayer DBSE.mp3

Changed raspistill -o $now.jpg



to raspistill -w 800 -h 600 -o $now.jpg



1. The preview process would grab my screen and could only ssh to machine/ attached monitor went grey.

2. Image was too large for emailing.

MichaelM1252 (author)2017-05-23

Has anyone modified this to send SMS?

I am in Australia and our telcos do not support sending an email to your mobile service as per the US article

If i had a sms subscriprion I could send a second email to my sms gateway. EG

Revision... SMS working. Used

Added a new .py to the dbell folder to send another email to

My mobile is 0404xxxxx5

My account for email to sms is with burst


Correction. Burst uses transmitsms not burstsms

yours will be different if you use something other than burst

Create new file SMS.PY in the dbell folder

import smtplib

server = smtplib.SMTP('', 587)


server.login("", "yourpassword")

msg = "Message from the doorbell at home. Read email I have sent a photo!"

server.sendmail("", "", msg)

#Burstsms uses the address for communication to the "email to SMS" service.


Modify to call SMS.PY


cd photos

echo "Taking the Photo"

now=$1 #Now is the filename time stamp

#take pic

# MM commented out to switch to PI Cam. fswebcam -d /dev/video0 -r "640x480" $now.jpg

raspistill -o $now.jpg

echo "Pic Taken"


#ring Bell

echo "Ringing Bell"

echo ""

echo ""

cd ..

omxplayer DBSE.mp3


MichaelM1252 (author)2017-05-23

DOHH!!! Did not disconnect the usb camera.

Will have to get back on using picamera rather than USB


MichaelM1252 (author)2017-05-23



fswebcam -d /dev/video0 $now.jpg


fswebcam -d /dev/video0 -r "640X480" $now.jpg

Larger image in email

I am also using a pi camera. Started with usb webcam/ swapped out to picam no problem or need to change any software or script

Wrrr 10-G (author)2016-07-19

Nice IoT starter to get your feet wet. Thanks!

DylanD581 (author)2016-07-16

Awesome Raspberry Pi IoT Doorbell!

DIY Hacks and How Tos (author)2016-07-16

This is an awesome doorbell.

About This Instructable




More by AngusC5:Raspberry Pi IoT Doorbell
Add instructable to: