Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
IoT_lover
Published © GPL3+

PHPoC - Detect Someone Taking Your Stuff and send Gmail

When your stuff is being taken away by a thief, PHPoC makes an alert and sends a notification to you via Gmail.

BeginnerShowcase (no instructions)2 hours3,315

Things used in this project

Hardware components

PHPoC Blue
PHPoC Blue
×1
SparkFun Force Sensor
×1
Warning Lights & Electric Horns
×1
PHPoC 4-Port Relay Expansion Board (S-type or T-type)
PHPoC 4-Port Relay Expansion Board (S-type or T-type)
×1
Resistor
DIYables Resistor
×1
Jumper Wires
DIYables Jumper Wires
×1

Story

Read more

Schematics

Wiring

- Stack PHPoC Relay Board on PHPoC Blue
- Connect Force sensor to PHPoC Blue as below image.
- Connect Warning Lights & Electric Horns to port 0 of Relay Board

Real Wiring

Code

Main task (task0.php)

PHP
<?php

if(_SERVER("REQUEST_METHOD"))
	exit; // avoid php execution via http request

include_once "/lib/sd_340.php";
include_once "/lib/sn_dns.php";
include_once "/lib/sn_esmtp.php";
include_once "/lib/sd_spc.php";

define("THRESHOLD", 50); // in ADC value

function send_gmail()
{
	esmtp_account("ypur_account@gmail.com", "PHPoC");
	esmtp_auth("your_account", "your_password");
	esmtp_msa("smtp.gmail.com", 465);
	
	$time = date("Y-M-d H:i:s", time());

	$subject = "Alert: Your treasure is being taken away";
	$message  = "Location: Planet Earth\r\n";
	$message .= "Time: $time\r\n";
	$message .= "Your treasure is being taken away\r\n";

	$msg = esmtp_send("receiver_account@gmail.com", "Boss", $subject, $message);

	if($msg == "221")
		return true;
	else
		return false;
}

spc_reset();
spc_sync_baud(115200);
adc_setup(0, 0); // adc0, channel 0

$obj_present = false;

while(1)
{
	$adc_in = adc_in(0, 30);
	
	if($adc_in < THRESHOLD)
	{
		
		if($obj_present)
		{
			//Alert
			spc_request(14, 4, "set 0 output high");
			// send notification
			while(!send_gmail())
				;
			
			$obj_present = false;
		}
	}
	else
	{
		$obj_present = true;
		spc_request(14, 4, "set 0 output low");
	}
}

?>

Credits

IoT_lover
10 projects • 192 followers

Comments