Evan Rust
Published © GPL3+

Texting Christmas Santa Catcher

Catch the elusive Santa Claus in your living room (or just your parents) with a Raspberry Pi. It texts you a photo of him when he is caught.

IntermediateShowcase (no instructions)2 hours829
Texting Christmas Santa Catcher

Things used in this project

Hardware components

Relay (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
USB webcam
×1
Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1

Software apps and online services

Python 2.7
Gmail
IDLE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Schematics

Schematic

Code

Santa Catcher Code

Python
Just copy and paste, put in your gmail username and password
#Santa catcher for Raspberry Pi 2

#for internet communtication
import smtplib

#for capturing an image
import pygame.camera
import pygame.image

#import sleep for timing
from time import sleep

#import Raspberry Pi GPIO
import RPi.GPIO as GPIO

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage

GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.IN)
GPIO.setup(17,GPIO.OUT)
#turn off light attached to relay
GPIO.output(17,1)
def get_image():
	#turn on relay for the light
	GPIO.output(17,0)
	pygame.camera.init()
	cam = ptygame.camera.Camera(pygame.camera.list_cameras()[0])
	cam.start()
	img = cam.get_image()
	pygame.image.save(img,"recent.png")
	pygame.camera.quit()
	#turn off light again
	GPIO.output(17,1)
	
def send_email(image):
	#your gmail account address for emailing
	gmail_acct = "email address"
	#your password, you should use an app specific password.
	gmail_pass =  "password"
	
	TO=["email address of email recipient"]
	FROM = gmail_acct
	
	#make the messgae building section
	msg = MIMEMultipart('mixed')
	msg['Subject'] = 'Santa has been spotted!'
	msg['From'] = FROM
	msg['TO'] = ', '.join(TO)
	body = MIMEText('Santa has been detected by your Raspberry Pi.')
	msg.attach(body)
	
	#attach image file to the rest of the message
	img_data = open(image,'rb')
	image = MIMEImage(img_data.read())
	img_data.close()
	msg.attach(image)
	
	#send the email
	server = smtplib.SMTP('smtp.gmail.com',587)
	server.ehlo()
	server.starttls()
	server.ehlo
	server.login(gmail_acct,gmail_pass)
	server.sendmail(FROM,TO,smg.as_string())
	server.close()
	
def check_sensor():
	#see if Santa is here yet
	if GPIO.input(4)==1:
		#santa is here
		get_image()
		#wait half a sec for the image to be saved
		time.sleep(.5)
		#sending email
		send_email('recent.png')
		#wait 20 secs
		time.sleep(20)
	else:
		time.sleep(1)
		#just loop through schecking
while 1:
	#keep calling this function
	check_sensor()
	sleep(1)

Credits

Evan Rust

Evan Rust

120 projects • 1053 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments