xanexxxx
Posts: 8
Joined: Tue Aug 08, 2017 6:38 am

PIR Sensor with phone notification (what method to use)?

Tue Aug 08, 2017 6:48 am

I recently got myself a Raspberry Pi A+ with a PIR sensor, I have everything setup except for which method to use, I'm trying to make a portable motion detector. I know a bit about setting up the pi/electronics/GPIO pins etc, but when it comes to python I'm still a beginner. What i have done now is that i made a python script that emails me everytime motion is triggered (this was my first python script ever) and it works as it's supposed to.

So i have my smart phone (Android ofc). Everytime a motion is triggered i want it to show up on my phone, But I'm not sure what method to use. Since i want a PORTABLE motion detector i can't use wifi, i also don't have a GSM module so text message is out of the question, next thing is Bluetooth but the range isn't far enough.. So what/how do you guys recommend that i use this in the best way?

If you need anymore info do tell and I'll answer asap. Regards!!

xanexxxx
Posts: 8
Joined: Tue Aug 08, 2017 6:38 am

Re: PIR Sensor with phone notification (what method to use)?

Wed Aug 09, 2017 1:44 am

I thought that i should share the python script i wrote to send myself the email on motion. Since this is my first script there is prolly a much better way to this. But at least it works hehe.

Code: Select all

#!/usr/bin/python
import RPi.GPIO as GPIO
import os
import sys
from time import sleep
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
GPIO.setmode(GPIO.BCM)
GPIO.setup(13, GPIO.IN)
GPIO.setup(6, GPIO.OUT)
try:
  while True:
    if ( GPIO.input(13) == True ):
      os.system('clear')
      print("Motion Seen")
      GPIO.output(6,GPIO.HIGH)
      fromaddr = "myemail"
      toaddr = "toemail"
      msg = MIMEMultipart()
      msg['From'] = fromaddr
      msg['To'] = toaddr
      msg['Subject'] = "Test Alert"
      body = 'Motion Detected'
      msg.attach(MIMEText(body, 'plain'))
      server = smtplib.SMTP('smtp.gmail.com', 587)
      server.ehlo
      server.starttls()
      server.login("myemail", "mypassword")
      text = msg.as_string()
      server.sendmail(fromaddr, toaddr, text)
      server.quit()
      sleep(3)
      sys.exit()
    else:
      os.system('clear') # clear the screens text
      print ("No Motion Detected!")
      GPIO.output(6,GPIO.LOW)
      sleep(0.5)
except: KeyboardInterrupt
GPIO.cleanup()
os.system('clear')
print('Aborted!')

xanexxxx
Posts: 8
Joined: Tue Aug 08, 2017 6:38 am

Re: PIR Sensor with phone notification (what method to use)?

Thu Aug 10, 2017 3:51 am

Bump.. no one have a clue? Or did i maybe post in the wrong forum? If so can an admin please move the thread :)

pcmanbob
Posts: 2221
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: PIR Sensor with phone notification (what method to use)?

Thu Aug 10, 2017 1:18 pm

As you say you don't have wifi available or a GSM modem for the pi and Bluetooth range is to short, It does not really leave you with much does it as you cant add any other devices to your phone were as you could add them to your pi.

you only answer may be to set your pi up as a wifi access point and then pair your phone with pi wifi. which would allow you to at least communicate between them, but I don't think sending emails with a connection like this would work.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

xanexxxx
Posts: 8
Joined: Tue Aug 08, 2017 6:38 am

Re: PIR Sensor with phone notification (what method to use)?

Fri Aug 11, 2017 11:00 am

pcmanbob wrote:
Thu Aug 10, 2017 1:18 pm
As you say you don't have wifi available or a GSM modem for the pi and Bluetooth range is to short, It does not really leave you with much does it as you cant add any other devices to your phone were as you could add them to your pi.

you only answer may be to set your pi up as a wifi access point and then pair your phone with pi wifi. which would allow you to at least communicate between them, but I don't think sending emails with a connection like this would work.
Thanks for your answer! Actually that's not a bad idea.. to set it up as an access point.. Maybe i can create a local website which i then enter on my phone, and then somehow it shows on the website if motion is detected..

xanexxxx
Posts: 8
Joined: Tue Aug 08, 2017 6:38 am

Re: PIR Sensor with phone notification (what method to use)?

Sun Aug 13, 2017 1:17 pm

Just wanted to update! I have decided what to do, I'm going to use Bluetooth for the communication. I had an old bluetooth USB dongle which i "hacked" and added a new antenna so that the range is over 100 meters atm :D

Return to “Other projects”

Who is online

Users browsing this forum: No registered users and 12 guests