Back to Parent

Outcome


Intention

I live in a 3 storied house with 2 other room mates. Our bedrooms are upstairs, while the living room is downstairs. We strive to create a communal environment in spite of our busy lifestyles. Every morning we're rushing through our routines to make it to class on time. Although we'd like to listen to music in the morning, we rarely pause to put on a song from our phones. Playing music also brings the entire home alive in the morning, inducing other to begin their day, instead of lounging in bed. The device detects motion in the living room during mornings, to trigger the music system.

Goal

I use a PIR motion sensor, to detect motion and publish an event to the Particle cloud. The device has some preconditions, to make sure it is only activated during morning hours. An IFTTT, recipe is used to link the event, to android play music action. IFTTT can also be used to trigger an action with other music services (Spotify, Bang & olfsen, etc).

Process

Stuff I used:

1. PIR Sensor - HC-SR501

2. 2 LED's - Red, Yellow & appropriate resistors

3. Two way switch

4. Jumper wires

I use a switch to disable the device. A red LED indicates the switch position (ON/OFF), the yellow LED will blink every-time motion is detected.

Initially I tried to write my own code from scratch, but due to the structure of the program and inexperience with setting up variables, I failed to get any output from the motion sensor. Eventually I switched to using Daragh's code at:

http://daraghbyrne.github.io/diotlabs/7-communicating-events/pir/

This got the LED blinking every time it detected motion, which was a little too often.

I modified this code using the built-in time function within particle. An additional trigOK() function, makes sure it is ok to publish the event. By setting up an additional variable trigT, to record the time of trigger using time.now(). I also added the IF condition to check that motion had not already been triggered in the past 60 mins. Another IF condition checks that the current time is between 7-11 AM, Time.hour() .


Playsong bb.thumb
Show Advanced Options
Img 20160128 225438973.thumb
Show Advanced Options
Ifttt.png.thumb
Show Advanced Options
Show Advanced Options
Show Advanced Options

Outcome

I was successfully able to trigger my phone to play Lithium (Nirvana), by walking near the motion sensor. The motion sensor can be placed horizontally or vertically, providing a lot of possibilities in it's placement and encasement design. While the Yellow LED would blink every time, motion was detected, I had trouble getting the Red LED to stay on, I assume this is because it doesn't have enough voltage.

 Ideally the device should trigger a radio channel on the Sonos system in our home. Due to the limitations in the IFTTT action portfolio, I could only play a specific song within my device.

A great deal of programming has to be customized depending on the final source of audio. The Sonos controller for example can only be played via an android device.

Reflection

Most home audio equipment don't support IFTTT. Ideally I would've loved to link up our Sonos system, or Chromecast Audio to IFTTT, but neither of them have any IFTTT integration at the moment. Also once motion is detected, it takes upto 15 sec, for the device to play the song.

It took me some effort to figure out the correct way to use the time function within particle. Figuring out the structure of the trigT, and trigOK took a while, I literally had to sleep on it.

I tried to write my own version of diagnostic tool to check if the motion sensor was working (LED + Serial monitor), I still don't know why my version did not work. One missing part from my code was the calibration time. Unfortunately I did not save my version, so I can't go back to compare, and learn from the errors.


Drop files here or click to select

You can upload files of up to 20MB using this form.