Gruppo E
Published © CC BY

Alarm System With Motion And Temperature Sensors

System constantly detects temperature and movement variations. If at least one change is detected, a notification will be sent.

IntermediateShowcase (no instructions)3 hours1,106
Alarm System With Motion And Temperature Sensors

Things used in this project

Hardware components

MikroE Flip and click
×1
MikroE Motion click
×1
MikroE WiFi 4 click
×1
MikroE Temp&Hum Click
×1

Software apps and online services

Zerynth Studio
Zerynth Studio

Story

Read more

Code

Python Code for Zerynth Studio

Python
Changes the following code lines with your values:
"YOUR APP UID"
"YOUR APP TOKEN"
"YOUR WI-FI SSID"
"YOUR WI-FI PASSWORD"
################################################################################
# CoverApp Alarm System 
################################################################################
from wireless import wifi
from stm.spwf01sa import spwf01sa as wifi_driver
import streams
import adc
streams.serial()
digitalWrite(D29,1)
# Import the Zerynth APP library
from zerynthapp import zerynthapp
# Import the HTS221 library
from stm.hts221 import hts221
temp_hum = hts221.HTS221(I2C0, D21) # slot A
sleep(1000)
print("STARTING...")
print()
try:
# Device UID and TOKEN can be created in the ADM panel
zapp = zerynthapp.ZerynthApp("YOUR APP UID", "YOUR APP TOKEN",ip =
"178.22.65.123", log=True)
# connect to the wifi network (Set your SSID and password below)
wifi_driver.init(SERIAL2,D24) # slot B
for i in range(0,5):
try:
wifi.link("YOUR WI-FI SSID",wifi.WIFI_WPA2,"YOUR WI-FI PASSWORD ")
break
except Exception as e:
print("Can't link",e)
else:
print("Impossible to link!")
while True:
sleep(1000)
# Start the Zerynth app instance!
zapp.run()
5
# Read the sensor and send values to the ADM
while True:
sleep(1000)
result=digitalRead(D31)
tmp, hum = temp_hum.get_temp_humidity() # Read tmp and hum for the first time
print("First iteration")
print("Temperature is:", tmp, "degrees, Humidity is:", hum, "%")
print()
try:
zapp.event({"temp":tmp, "humid":hum})
except Exception as e:
print(e)
temp1=tmp #Save the value of tmp into temp1 variable
sleep(1000) #the sleep is necessary to get temperature variation
tmp, hum = temp_hum.get_temp_humidity() # Read tmp and hum for the second
time
print("Second iteration")
print("Temperature is:", tmp, "degrees, Humidity is:", hum, "%")
print()
try:
zapp.event({"temp":tmp, "humid":hum})
except Exception as e:
print(e)
temp2=tmp #Save the value of tmp into temp2 variable
diffT=temp2-temp1#Calculate the temperature variation
print(temp1, ", ", temp2)
print (diffT)
print (result)
if diffT>0.001 or result==1:#if the variation is more than a threshold send a
comunication
# send mobile notification
# (there is a limit of one notification per minute per device on the ADM
sandbox)
try:
print (result)
zapp.notify("ALARM!","Someone is trying to steal your...!")
except Exception as e:
print(e)
except Exception as e:
print(e)

Java and html for your Zerynth App template

Java
Copy and paste this code in .html file of your Zerynt App template.
Later, change this code lines with your values:

<img src="YOUR LOGO URL" alt="YOUR LOGO TEXT"
height="125"
width="250">
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Zerynth</title>
<!-- LOAD JQUERY AND BOOTSTRAP -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
6
integrity="sha384-
BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstraptheme.
min.css"
integrity="sha384-
rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-
Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<!-- LOAD THE ZERYNTH ADM JS LIBRARY -->
<script src="https://api.zerynth.com/zadm/latest/z.js"></script>
<!-- LOAD Flot.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.js"></script>
</head>
<body>
<div align="center"> <img src="YOUR LOGO URL" alt="YOUR LOGO TEXT"
height="125"
width="250">
</div>
<div style="text-align:center">
<p id="status" style="background:#ddd;font-weight:bold"></p>
<h1>TEMPERATURA</h1>
<h4>Graphs show the temperature trend and humidity in real time </h4>
<div id="updating-chart1" style="height:300px"></div>
<div id="updating-chart2" style="height:300px"></div>
</div>
<script>
var temp = []
var humid = []
$(document).ready(function () {
var plot1 = $.plot("#updating-chart1", [ [] ], {
series: {
shadowSize: 0
},
yaxis: {
min: 00,
max: 60
},
xaxis: {
show: false
}
});
var plot2 = $.plot("#updating-chart2", [ [] ], {
series: {
shadowSize: 0
},
yaxis: {
min: 20,
max: 99
7
},
xaxis: {
show: false
}
});
Z.init({
on_connected: function(){$("#status").html("CONNECTED")},
on_error: function(){$("#status").html("ERROR")},
on_disconnected: function(){$("#status").html("DISCONNECTED"); return true},
on_online: function(evt){$("#status").html("ONLINE");},
on_offline: function(evt){$("#status").html("OFFLINE");},
on_event: function(evt){
console.log(evt)
temp.push([temp.length,evt.payload.temperature])
plot1.setData([temp]);
plot1.setupGrid()
plot1.draw();
humid.push([humid.length,evt.payload.humidity])
plot2.setData([humid]);
plot2.setupGrid()
plot2.draw();
}
})
})
</script>
</body>
</html>

Credits

Gruppo E

Gruppo E

0 projects • 0 followers
We are students of management engineering in Pisa.

Comments