-
Notifications
You must be signed in to change notification settings - Fork 1
/
FIRE_ALARM.py
47 lines (42 loc) · 1.15 KB
/
FIRE_ALARM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#move to https://wokwi.com/projects/new/micropython-esp32
#Rebuild the ESP32 with the given connections looking at the Construction below in the pdf.
#Write the code and check it
#When temperatures crosses 57°C, then a Fire Alarm rings.
#FIRE ALARM
import dht
import time
import machine
from machine import Pin
led=Pin(15,Pin.OUT)
buz1=machine.PWM(Pin(2,Pin.OUT))
buz2=machine.PWM(Pin(4,Pin.OUT))
buz1.freq(1024)
buz2.freq(512)
d=dht.DHT22(Pin(13))
button=Pin(18,Pin.IN)
d.measure()
temp=d.temperature()
humid=d.humidity()
buz1.duty(0)
buz2.duty(0)
while True:
time.sleep(5)
print("Temperature in the room : ",str(temp)+"°C")
print("Humidity in the room : ",humid)
if(temp>57): #temperature in degree celsius at which fire accidents occurs mostly.
print("**FIRE ALERT**\n")
print("TO STOP ALARM : PRESS RED BUTTON")
while True:
led.on()
time.sleep(0.4)
led.off()
buz1.duty(50)
time.sleep(0.4)
buz1.duty(0)
buz2.duty(50)
time.sleep(0.5)
buz2.duty(0)
if(button.value()==True):
exit(0) #Stops the alarm
buz1.deinit()
buz2.deinit()