 Hey everybody, this is Brian. I finished a very long project and I posted it on Facebook and I had some feedback asking for Hey, can you kind of explain this in depth? so Basically what this is is I wanted to do a like home security system But I wanted motion detectors. So I took these little cheap Adjustable PRI motion sensors. You can see like $2.62 and the graphics and not the best, but you can see it's very small Here's the actual whoops Here's the actual sensor Calling it a motion sensor is kind of not accurate. It actually detects variance in heat and that's how it detects motion They are dirt cheap and they are almost impossible to defeat I've tried several different ways to defeat these things from Aiming a laser at it to making sure that I was exactly like a room temperature, but now it picks up any little variance Along with being very cheap, they're very simple. You see little orange things allow you to just I think it's like the Horizontal and vertical scanning That might not actually be accurate, but and it's just got three little pens It's got a positive negative and then a little I don't remember what it's called It's like a voltage. It just tells you hey, there was motion. So whenever there's motion, it'll actually put out voltage on that pen And you can buy them in bulk. They're pretty pretty simple little devices with that I hooked it to what's called a particle photon and let me whoops Here's the actual Detector that I built that is the back side of the motion detector You see there's little orange knobbies that you can adjust and there's the wires the positive and negative and then here is the It's not a data line, but it's just like a voltage line. So in motion it sends Voltage down here and this will just pick it up Now it's a little silver guy in the center. That's actually a Wi-Fi chip set So really what I've done is I put a motion detector on my wireless network So when this thing detects motion, it'll go out to a Raspberry Pi Whoops, this is the actual front side of that detector that I built. See there's the motion Detector and I built like I think like six or nine of them something like that. They're scattered throughout the house And there it is plugged in. It's just a little micro USB plugs right into the wall And yeah, here it is. It goes to this Raspberry Pi Now why did I use a Raspberry Pi simple? I had it here. I had it laying around the house I've had it for a few years. I got it as like a Christmas preglet So I put it to 80802.1. I think B wireless USB adapter and it just you know fired right up now these sensors whoops Do an HTTP get so when this sees motion it does a web request over to the Raspberry Pi Which has a full lamp stack on here. It's running a Linux Apache What am I using yeah, yee 2.0 is the PHP framework that I actually used And then you know it stores everything in the database. So Basically gets motion it goes to here. This little guy says is Brian home? Yes or no And if the answer is no then it sends me a text message it contacts 9-1-1 and it does a few other snazzy things So to determine whether or not I was home. I also made an Android application Here's a screenshot off my actual phone, and it's very simple Off on awake sleep and ping pings kind of misleading Off obviously turns all the motion detectors off. It's not really true They constantly detect motion whether they're off or on it just flips a bit in the my sequel database and the raspberry Raspberry Pi checks that to see you know the status is it off is it on etc. Etc. So if it's off it just ignores all motion if it's on however it registers all motion and Says hey, there was motion and then it sends out through an email gateway I think AT&T and Verizon both have them, but it's like Texted ATT or something like that But basically just has my phone number or 9-1-1 and then a basic message and it just sends it out It'll AT&T automatically converts it into a text message and shoots it out for me And then I have awake and asleep. These are Take a little bit of explaining The Android application runs as a background service, and I'll actually show the code here in a minute But once a minute it'll do and HTTP get back to this Raspberry Pi this guy and say hey I'm home. So if there's motion just ignore it because it's me walking around my house Now a sleep turns that off. It's the same thing as on but there's special flags on some of the detectors And let me go in here Here's the actual web interface, and this is actually right off the Raspberry Pi So here's the detectors You can see how bedroom has enabled asleep as no while the others have it is yes Because when I'm laying in bed If I roll over in the middle of the night I don't want the motion that was just detected to register and sound the alarm because that Android application will actually Sound a very loud alarm to wake me up So my phone's laying right next to me at night. It detects motion and say the living room Well, guess what? I'm not in the living room. I'm in bed sleeping So it's gonna, you know make a very loud alarm sound contact 9-1-1 and do all this stuff so before I've even Before I've even rolled out of bed and wipe the sleep out of my eyes 9-1-1's already been contacted I'm not ultra paranoid. It just it was a project that I really wanted to do and You can enable or disable so if I have guests I can say you know guest room disable that so when there's motion in there It's not gonna wake me up to This was tricky for a few reasons Hey, I'm not a hardware guy at all. I mean I've built my own gaming computers and I've fixed laptops and you know Half a million dollar servers and networks and things like that But I've never actually just grabbed a bunch of hardware and started plugging it all together and wiring it up and writing the firmware for it So I had to get a bunch of these little sensors. I had to get a bunch of these little Little boxes and little things. I think all and all these are about 30 bucks each to build because these little Enclosures were a little expensive the particle phonons themselves are about 19 bucks each The PRI sensors like three bucks, but I got most of this for free because I had the Raspberry Pi as a Christmas present I had the particle phonons as Christmas presents on a different Christmas. So all this stuff was just You know laying around the house collecting dust and I wanted to do something with it Also I use particle photons because the documentation is just amazing on these and it comes with a cloud-based system When you set these up Yeah, let me scroll up here. Here's the actual photon right here When you set these bad boys up, it's very simple. You plug it into your computer or into an electrical outlet or whatever and You hook it to your Wi-Fi and you use an Android or an iPhone application to do that So it automatically just talks to it and it's literally just a screen comes up and says hey We found your device and then you just plug in your Wi-Fi credentials and it puts it on the Wi-Fi and then you can flash it So because this is cloud-based, I can be in a hotel room 3,000 miles away and I can update my security system from the hotel room using the hotel Wi-Fi and just flash these things remotely So if I'm you know gone and I start getting a lot of squirrely activity because these don't register motion. They register heat I had one of these under a Heating vent from the furnace and it kept registering whenever the furnace came on I can actually tweak that firmware remotely Also the documentation on these is just amazing It's just blew me away the amount of documentation they have on these And they walk you through a lot of things and they have a cellular version too So if you don't want to just do Wi-Fi, you can do it right off of cellular and there's a small monthly charge for the cellular I think it's like 2g and 3g speeds, but You can put the sucker out in the middle of nowhere and as long as you've got a cellular signal it works One of them did screw up for me And I had to go into the Linux command line and over serial give it the Wi-Fi credentials instead of through the android app And it was a known bug in these things But so far they've been not bad The other thing I like is they have an online IDE and here's the actual code for those Particle photons. There's really no point in screenshotting this. There's not a whole lot to the code They just simply they have a startup routine or setup Which is where you register all your pinouts and you know serial begin and things So i'm just changing some led colors and getting the mac address And setting the pin modes on these things. So I have like the board and the sensor So I have an led that blinks and then I have that sensor where I do an input to see when there's motion And then the only other real magic is i'm getting the mac address off of the Wi-Fi chipset on the board Which I use that for the HTTP get and then the get itself. I actually use one of their built-in libraries They come with just tons and tons and tons of libraries Pretty much anything you can imagine that somebody's already written the code for it So you can see right at the very top. I'm including their HTTP client The client's a little buggy I had to fight with it a couple times and I had to tweak the code on the back end But you can see here is the code right here where I'm just doing an HTTP get I'm going over to the raspberry pi Which I might network it's a 1.1 21 And then here's the actual query string If you remember e2 at all is your xml controller and the motion action and then I've got some parameters So I'm just saying version one and then the mac address. It's very simple. I'm just doing an HTTP get When that happens It does some magic in the background here and it says is brian home Is the system on or off or is it a wake or sleep? And then it just you know through the code determines what it needs to happen So when motion's detected if I'm gone or I'm asleep or whatever It'll text my phone through the at and t and verizon gateways Um, and then it'll text 911 and say hey motion was detected at and it'll give the address and then my cell phone number Um, so the cell phones, you know sitting next to me and motion is detected before I even roll over boom 911's already been contacted Um If I wanted to rebuild this thing, I'd probably do it with this little guy called chip Um, each one of these it's nine dollar board But each one of these is full embedded linux for nine bucks And the specs on these are just insane. It's built-in wi-fi. So this little board already has wi-fi Um, a one gigahertz processor four gigs of internal Storage 512 ram bluetooth 4 and works on any display So essentially you have you know this little guy With just a motion detector plopped right on top of it And then maybe a small enclosure and plug it straight into the wall So this thing's probably the size of a credit card Um, yeah, and you got a full-blown linux computer running specs that are better than what I had 15 years ago um We'll see what else uh, I did a full-blown android application and here's the application I did a couple different uh interfaces for the end user, but I basically settled on this Um, I can run it in the emulator, but it won't work in the emulator because the emulator doesn't do wi-fi But this had some some issues Uh, you can see how it's a service I had to run a background service because if you know anything about android if you go like that But your application is dead. It just died So it runs in a background service Of course on the emulator. It killed it, but uh Runs in the background service. So even if it's not in the foreground it's running and it's constantly pinging away at this thing um The big problem I had with that was just I'm not a java guy. I haven't really ever worked with java and Android's not really java java. It's like google's version of java So I had to learn, you know, basic android sdk and I had to learn how to do that And then I'm doing some advanced things like I'm starting a service And then bringing the service to the foreground and then, you know, registering it with the white list because android has this feature called Doze So if you're not using your phone it puts your phone into what's called dose or low power mode So it starts killing services that it thinks are not, you know, uh Not a priority So like if you have pandora on your phone and you set your phone down walk away for 20 minutes pandora It's probably not going to be running when you come back um So what was happening is I would set this thing up at night and then in the morning I'd walk around to test and I was getting no messages And that's because over the night android killed the service because it didn't see it as a priority service So I had to figure out how to how to do that. Um Here's the actual service itself And it plays some music and stuff like that. I shouldn't say music sounds And it'll detect when the wi-fi is connected and disconnected So when I walk out of my apartment and the wi-fi drops it stops the timer in the background So it's not chewing up my battery and then when I come home It sees the wi-fi is reconnected and it starts the timer again And then it says hey brian's home and sends that to the To the raspberry pi This guy So that knows i'm home So before my keys even entered in the lock for me to walk into the apartment It already knows that i'm home and it won't detect, you know motion because i'm home And 911 won't get called and all that Still a couple bugs in it, but for the most part it's working um The other main pickups that I really had was uh Just getting used to android itself and Originally I had everything in an activity until I learned about services and then when I moved to the service I had to do things a little differently Um, I am actually going to do If I can find my notes Full-blown android tutorial series because I've learned quite a bit about android So I've actually been spending the morning just typing up like a basic Lesson plan of what we're going to start doing here. Um, I do want to go get back to cute I love c++ and cute, but this is Kind of a neat project. I may like I said redo this whole thing on uh, What's it called chip this little guy? um The code would probably be in python instead of c++ though Unless I get really adventurous and want to do it all in c++ with cute that might actually be what I do So that's it