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

gregerwhut

  • Newbie
  • *
  • Posts: 13
HELP PIR sensor and oak
« on: April 11, 2016, 07:27:13 am »
hey Folks

Anyone that could help me making connection between a PIR sensor and the oak, which can send a message/notification 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.

Anders

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: HELP PIR sensor and oak
« Reply #1 on: April 11, 2016, 09:19:41 am »
I think you are going to have to break it down to it's component parts and do some research...

1. Don't know what PIR sensor you are using but most likely it is powered by 5V or more. The Oak is a 3.3v device so you'll need to look into how to drop the output voltage from the PIR output signal to 3.3v for whatever input pin you use on the Oak (Just to be safe). Search for circuits built around the PIR. Since you'll most likely want to pull-down the PIR output, I guess you could create a voltage divider by placing a resistor ahead of the Oak corresponding input pin. But note that there are Oak pins that should not be pulled down at boot.

2. You should be able to easily find a working example of code for the PIR in the Arduino Playground or elsewhere on the web. You'll need to adapt that to the available Oak pins. Also, Oak has no USB serial out through USB, but you can use the TX, RX pins with an appropriate 3.3v serial adapter to get serial output if needed for debug.

3. Notification to phone (not a strong point for me). Look at or for examples on how to get data to a cloud service from the Oak that can also notify to your phone. I'm not familiar with many of the them but they do exist. Thingspeak, I think can send Twitter messages.  The Blynk app has a virtual LCD screen.  Not sure what Particle offers in this realm. There may be others that I am even less familiar with. Microsoft Azure? IFTTT? Others apps?

Hope this at least gets you started in the right direction. Or have I given you just enough info to make it seem complicated? Just approach it step by step. You'll learn more in the end.
Get the basic circuit down with a simple example, then try to add the notification part.

There my be others here that can help with various parts of the puzzle.


gregerwhut

  • Newbie
  • *
  • Posts: 13
Re: HELP PIR sensor and oak
« Reply #2 on: April 11, 2016, 01:30:25 pm »
1. I use I 5 v PIR sensor yes. I have a Adruino nano and Uno, but dont know if they are to any help for the project? I dont know anything about how to setup a circuit like you described with yje resirsor ahead of the oak and so on.

2- I dont understand this part off your reply at all.

3. I would be glad to use IFTTT, if it is possible.

Yeah It seems kind of complicated, when I aint familiar with any of the stuff.

defragster

  • Sr. Member
  • ****
  • Posts: 467
Re: HELP PIR sensor and oak
« Reply #3 on: April 11, 2016, 03:24:42 pm »
I did a BING search "ESP8266 PIR" and this was the first link: http://www.esp8266-projects.com/2015/03/esp8266-pir-motion-sensor-detection.html

It should provide more helpful details.  It seems to be using LUA - but the PIR hardware and voltage technical details and process - and most coding - should be otherwise the same - if you have a similar PIR unit.

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: HELP PIR sensor and oak
« Reply #4 on: April 11, 2016, 08:34:43 pm »
Maybe this will help you get started...

Check to see if you PIR is 3.3v compatible. Some are. If so, you can use the simple fritzing example without the voltage divider.

NOTE: In the fritzing diagrams the PIR red wire is VCC, black wire is GND and yellow wire PIR OUT.

If your PIR is not 3.3v compatible, you can use the fritzing example with the voltage divider which uses 4.7K and 10K resistors to form that divider and drop the PIR output signal to about 3.4v assuming 5v at VIN. Check the band colors to see which resistor is which in the diagram. Do not exceed that 5V for VIN (i.e. Power to the Oak) as it will raise the voltage of the PIR output.
This all may not be necessary if the Oak pins can tolerate 5V but, I would rather be safe than sorry.

Finally, here is a very simple example. It will need a lot more code to handle the notifications and keeping motion states so that you are not flooded with continuous notifications when the PIR output remains HIGH because of motion. The example simple turns on the Oak onboard LED when motion is detected.
Code: [Select]
// Simple Oak PIR example
#define PIR_Out 5  // On Oak pin 5
#define Oak_LED 1  // Onboard LED pin

void setup()
{
  pinMode(PIR_Out, INPUT);
  pinMode(Oak_LED, OUTPUT);
  digitalWrite(Oak_LED, LOW); // Turn Off onboard LED
//  Serial.begin(9600);
//  Serial.println("Warming up...");
  delay(10000); // Ten seconds
}

void loop()
{
  if (digitalRead(PIR_Out) == HIGH) {
    digitalWrite(Oak_LED, HIGH);
  }
  else {
    digitalWrite(Oak_LED, LOW);
  }
  delay(200); // Adjust delay as needed
}

exeng OUT

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: HELP PIR sensor and oak
« Reply #5 on: April 11, 2016, 10:20:16 pm »
UPDATE: The fritzing diagrams do not apply to the HC-SR501 which is what comes with the Oak Ultimate Kit. I don't have one (but probably should as it appears to be a nicely featured PIR). From reading the spec's it operates at 5V to 20V for VCC but outputs 3.3V when motion is detected. So it looks like you can connect the PIR output directly to an Oak input pin. You only need to supply it's VCC with 5V and share a common ground with the Oak.
« Last Edit: April 11, 2016, 10:33:17 pm by exeng »


exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: HELP PIR sensor and oak
« Reply #7 on: April 12, 2016, 08:35:16 am »
gregerwhut,

The one you have looks suspiciously like the HC-SR501. Looking at the specs, it can be power by 5V and outputs 3.3V. So you should be able to use the fritzing diagram attached to this post and be able to get the example code to run.

gregerwhut

  • Newbie
  • *
  • Posts: 13
Re: HELP PIR sensor and oak
« Reply #8 on: April 12, 2016, 09:55:58 am »
Okay Super, I got that to work :). Now i need help to make a code that can be setup to send a notification, when the PIR detects movement ?? :)

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: HELP PIR sensor and oak
« Reply #9 on: April 12, 2016, 10:40:27 am »
Glad to hear that it works. I'm afraid you'll have to appeal to others or do some learning on your own. As I said in a previous post, I'm not that knowledgeable with respect to how to implement notifications to the phone. I'm only able to offer suggestions, as I did.

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: HELP PIR sensor and oak
« Reply #10 on: April 16, 2016, 10:16:13 am »
Adding DrJFM relpy here as most of the discussion has already occurred under "Oak Projects". http://digistump.com/board/index.php/topic,2187.msg10302.html#msg10302

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: HELP PIR sensor and oak
« Reply #11 on: April 18, 2016, 06:22:41 pm »
Desperately trying to keep this in 1 thread (here):

http://digistump.com/board/index.php/topic,2187.msg10320.html#msg10320

exeng

  • Sr. Member
  • ****
  • Posts: 454
Re: HELP PIR sensor and oak
« Reply #12 on: April 18, 2016, 06:39:10 pm »
gregerwhut,

In order for anyone to help you, you'll need to provide more info...

1. How are you getting the serial output from the Oak?
2. What is complaining about the python import?
3. It appears that you are trying to run an Adafruit example. Why did you change to this line in the example
Code: [Select]
ser = serial.Serial('COM4', 9600)to this?
Code: [Select]
ser = serial.Serial('/dev/cu.Bluetooth-Incoming-Port', 9600)

You realize that the Oak does not support serial out through USB and that you need to have some sort of adapter connected to TX and RX on the Oak to get serial output to display on your PC.

I'm not a Python expert, but from looking at the Adafruit example that you based this on, it somehow accesses serial output and looks for the "M" in movement to trigger the email.
So I'm guessing the way this is supposed to work is you motion detect code outputs to a serial port (on your PC) where python is installed and running and looking for serial input. Is this how you have it set up?
« Last Edit: April 18, 2016, 07:15:27 pm by exeng »

gregerwhut

  • Newbie
  • *
  • Posts: 13
Re: HELP PIR sensor and oak
« Reply #13 on: April 19, 2016, 07:31:47 am »
Hey again

1. I dont know how i get serial output from oak. but that is not what I actually a, trying to. I wrote that I was unsure where about what was meant with the Particle.publish()??

2. I am trying to make this work in Adruino software. I am unsure if i should do the code directly on the https://build.particle.io/build/. In the Adruino app it makes this error
Quote
ïmport¨dpes not name a type
and the same for the serial and smtplib.

3.
I changed it because it was stated here https://learn.adafruit.com/arduino-lesson-17-email-sending-movement-detector/python-code

.

4. I have Macbook, and are unfamiliar on how to setup Puthon, and I do not know anything off what i does?. I just need the most simple way for making this work together


PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: HELP PIR sensor and oak
« Reply #14 on: April 20, 2016, 03:26:28 am »
I posted a reply here before I realised that exeng was trying to stop this thread from fragmenting.
http://digistump.com/board/index.php/topic,2187.msg10337.html#msg10337

Now that I see you later posts, I can see where some of the confusion is comming from. The Adafruit code example you linked is the python code that is meant to run on your computer. However, their code is meant to be used when Arduino (not an Oak) sends a message via it's USB<->Serial connection, and lets the computer know motion has been detected. That python code then triggers an email to be sent.

If your project is to use an Oak to detect motion with a PIR sensor, and then send an email to your phone to alert you of that motion, you could use IFTTT as the final stage, instead of the python code on the computer (also removing the requirement to have a computer on all the time just for this purpose). You would create a recipe that waits for a particle event to be triggered (using the Particle.publish() command), and when that event triggers, sends an email. You can also choose other actions like sending an SMS, posting a message to twitter or facebook, etc.

Basically, using your code above as a example, you just need to add the Particle.publish() command as illustrated below, and then create a suitable IFTTT recipe to react to it.

Code: [Select]
  if (digitalRead(PIR_Out) == HIGH) {
    digitalWrite(Oak_LED, HIGH);
   //is the sensor output high when there is motion? if not, move the publish line to the 'else' block
   Particle.publish("motion-detected");
  }
  else {
    digitalWrite(Oak_LED, LOW);
  }