This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
oak:tutorials:pir [2016/08/13 12:47] brohan |
oak:tutorials:pir [2017/01/16 22:53] (current) weaslyd [Code] |
||
|---|---|---|---|
| Line 114: | Line 114: | ||
| //give the sensor some time to calibrate | //give the sensor some time to calibrate | ||
| - | for(int i = 0; i < calibrationTime; i++){ | + | for(int i = 0; i < calibrationTime; i++){ |
| - | delay(10000); | + | delay(10000); |
| - | } | + | |
| - | delay(50); | + | |
| } | } | ||
| + | delay(50); | ||
| + | |||
| + | } | ||
| void loop(){ | void loop(){ | ||
| - | if(digitalRead(pirPin) == HIGH){ | + | if(digitalRead(pirPin) == HIGH){ |
| - | digitalWrite(ledPin, HIGH); | + | digitalWrite(ledPin, HIGH); |
| - | Particle.publish("MOTION SENSOR", "Motion detected"); | + | Particle.publish("MOTION SENSOR", "Motion detected"); |
| - | if(lockLow){ | + | if(lockLow){ |
| - | lockLow = false; | + | lockLow = false; |
| - | delay(1000); | + | delay(1000); |
| - | } | + | } |
| - | takeLowTime = true; | + | takeLowTime = true; |
| - | } | + | } |
| - | if(digitalRead(pirPin) == LOW){ | + | if(digitalRead(pirPin) == LOW){ |
| - | digitalWrite(ledPin, LOW); | + | digitalWrite(ledPin, LOW); |
| - | if(takeLowTime){ | + | if(takeLowTime){ |
| - | lowIn = millis(); | + | lowIn = millis(); |
| - | takeLowTime = false; | + | takeLowTime = false; |
| - | } | + | } |
| - | if(!lockLow && millis() - lowIn > pause){ | + | if(!lockLow && millis() - lowIn > pause){ |
| - | //makes sure this block of code is only executed again after | + | //makes sure this block of code is only executed again after |
| - | //a new motion sequence has been detected | + | //a new motion sequence has been detected |
| - | lockLow = true; | + | lockLow = true; |
| - | delay(50); | + | delay(50); |
| - | } | + | } |
| - | } | + | |
| } | } | ||
| + | |||
| + | } | ||
| + | |||
| </code> | </code> | ||
| Line 154: | Line 158: | ||
| Remember the ifttt.com page with our recipe? Before you flash the program to your Oak, I highly recommend that you have this recipe page open in your browser, your Particle log page, as well as your Gmail page, so that you can see everything working together. | Remember the ifttt.com page with our recipe? Before you flash the program to your Oak, I highly recommend that you have this recipe page open in your browser, your Particle log page, as well as your Gmail page, so that you can see everything working together. | ||
| - | Flash your Oak, and you will shortly see your Particle logs showing the information that you've published, and if you're recipe is active, you will see an email (or a steady stream) arrive in your Gmail inbox. To halt the emails, simply turn off your recipe on ifttt. | + | Flash your Oak, and you will shortly see your Particle logs showing the information that you've published, and if your recipe is active, you will see an email (or a steady stream) arrive in your Gmail inbox. To halt the emails, simply turn off your recipe on ifttt. |
| == Note == | == Note == | ||