Author Topic: HELP PIR sensor and oak  (Read 9463 times)


  • Newbie
  • *
  • Posts: 13
HELP PIR sensor and oak
« on: April 10, 2016, 02:36:44 pm »
hey Folks

Anyone that could help me making connection between a PIR sensor and the oak, which can send a message to the phone when it detects movement / light interfernce.

I am new to all kind off coding, and have been searching the web for my exact project, but cant find any help.



  • Newbie
  • *
  • Posts: 31
Re: HELP PIR sensor and oak
« Reply #1 on: April 16, 2016, 07:13:57 am »
Dear grererwhut,

You have two parts to your inquiry.  Using a PIR sensor to respond when you wish and (2) receiving that response on your phone.  Since the Oak is an arduino like device, it may be simpler for you as a newbie to work the first issue -- wiring and code for a PIR application-- out on an Arduino Uno using a PIR and code you can than migrate to the OAK.

Once you can detect your desired event locally, the Oak can send you your event notification over the Internet.  This can be done using the Blynk application on android or iPhone.  It can also be done using a browser or http: type notification using the Particle interface.

By the time you have the PIR and code working on a UNO using a simpler USB connection to your local computer, the second part should be more complete documented or have more examples here for you to follow.  You will need a data plan on your phone or be limited to receving messages when you have a wifi connection.  These routes do not use anything like a sms message, only internet access works.

Adafruit sells an appropriate sensor and they provide a wealth of links to arduino based use and application examples.  If you start on their web page for the sensor, you will see links that lead to details of the PIR wiring and use and further links to application examples.  There sensor is 3.3 V so no need for level shifting on moving to Oak.

They have an example on sending an email using an Uno and separate programing on you host computer to do the email.  This python programing for sending an email can be replaced by using Blynk and/or Particle communication from the Oak.  This example: has as its first step a simple sketch that uses your computer monitor and serial communication.  All you have to do is change the Serial.println() output to Particle.publish() output to get a web enabled notification working. You can build from there.

Getting the output as you want it on your phone once you are getting Particle log communications from you Oak is something you can tailor to your phone and needs.  It is also something you can ask for more specific help with once you are at that point.


PS  Looking further down this forum list, there is a note on using Oak or similar devices to send SMS by a couple methods, depending on the carrier you have etc.  you may want to look at this since SMS notification would remove the requirement for internet access.  See,1786.0.html lower on this page
« Last Edit: April 16, 2016, 07:18:58 am by DrJFM »


  • Sr. Member
  • ****
  • Posts: 454
Re: HELP PIR sensor and oak
« Reply #2 on: April 16, 2016, 10:19:32 am »
DrJFM, added a link to your relpy under "Oak Projects". Most of the discussion re: PIR sensor and oak has already occurred in that thread. grererwhut posted his question in two places. These should be merged to avoid confusion and duplication.


  • Newbie
  • *
  • Posts: 13
Re: HELP PIR sensor and oak
« Reply #3 on: April 18, 2016, 03:37:20 pm »

Why does this not work with the oak in Adruino software? I did set it up like Exeng did in the other thread

. I changed the Pin input from the adruino to the oak pin 5. I know the email and password is not set in the code you can see below.

int pirPin = 5;

int minSecsBetweenEmails = 60; // 1 min

long lastSend = -minSecsBetweenEmails * 1000l;

void setup()
  pinMode(pirPin, INPUT);

void loop()
  long now = millis();
  if (digitalRead(pirPin) == HIGH)
    if (now > (lastSend + minSecsBetweenEmails * 1000l))
      lastSend = now;
      Serial.println("Too soon");

import time
import serial
import smtplib

TO = 'email'
GMAIL_USER = 'email'
GMAIL_PASS = 'password'

SUBJECT = 'Intrusion!!'
TEXT = 'Your PIR sensor detected movement'
ser = serial.Serial('/dev/cu.Bluetooth-Incoming-Port', 9600)

def send_email():
    print("Sending Email")
    smtpserver = smtplib.SMTP("",587)
    smtpserver.login(GMAIL_USER, GMAIL_PASS)
    header = 'To:' + TO + '\n' + 'From: ' + GMAIL_USER
    header = header + '\n' + 'Subject:' + SUBJECT + '\n'
    print header
    msg = header + '\n' + TEXT + ' \n\n'
    smtpserver.sendmail(GMAIL_USER, TO, msg)
while True:
    message = ser.readline()
    if message[0] == 'M' :

I get an error with the Import
import time
import serial
import smtplib

And what about the Particle.publish() output??
« Last Edit: April 18, 2016, 03:38:54 pm by gregerwhut »


  • Hero Member
  • *****
  • Posts: 881
Re: HELP PIR sensor and oak
« Reply #4 on: April 20, 2016, 03:06:31 am »
You're getting error messages with the

Code: [Select]
import time
import serial
import smtplib

lines as they are not Arduino / C++ code... they look more like python code.

Most of the code from those lines on is all wrong... the TO / GMAIL_USER / etc variables are not defined properly, and nothing about the def send_email(): function will work.

You need to be looking for ESP8266 Arduino code if you want to find similar code you can re-use bits from, or find reference materials to help you get your project working.