Skip to content

Commit 25f6555

Browse files
committed
Adding files
0 parents  commit 25f6555

File tree

9 files changed

+193
-0
lines changed

9 files changed

+193
-0
lines changed

.idea/RP_Drivers_Python.iml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dictionaries/Mohammad.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MQ7.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import RPi.GPIO as GPIO
2+
import time
3+
import threading
4+
import sys
5+
6+
DO = 15
7+
LIGHT2 = 18
8+
9+
10+
def definition():
11+
GPIO.setmode(GPIO.BCM)
12+
GPIO.setup(DO, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
13+
GPIO.setup(LIGHT2, GPIO.OUT)
14+
15+
16+
def action(pin):
17+
print("Sensor detected action!")
18+
GPIO.output(LIGHT2, 1)
19+
time.sleep(1)
20+
GPIO.output(LIGHT2, 0)
21+
return
22+
23+
24+
def fun2():
25+
while True:
26+
print("waiting for smoke")
27+
GPIO.add_event_detect(DO, GPIO.RISING)
28+
GPIO.add_event_callback(DO, action)
29+
GPIO.remove_event_detect(DO)
30+
31+
32+
def main():
33+
try:
34+
definition()
35+
threads = []
36+
t2 = threading.Thread(target=fun2)
37+
threads.append(t2)
38+
t2.start()
39+
except KeyboardInterrupt:
40+
GPIO.cleanup()
41+
42+
43+
if __name__ == "__main__":
44+
main()

Moisture.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import RPi.GPIO as GPIO
2+
import time
3+
import threading
4+
import sys
5+
6+
HAM = 22
7+
LIGHT3 = 27
8+
9+
10+
def definition():
11+
GPIO.setmode(GPIO.BCM)
12+
GPIO.setup(HAM, GPIO.IN)
13+
GPIO.setup(LIGHT3, GPIO.OUT)
14+
15+
16+
def action2(pin):
17+
print("sensor detect action2!")
18+
GPIO.output(LIGHT3, 1)
19+
time.sleep(1)
20+
GPIO.output(LIGHT3, 0)
21+
return
22+
23+
24+
def fun3():
25+
# while(True):
26+
# print("waiting for moisture")
27+
# GPIO.add_event_detect(HAM, GPIO.RISING)
28+
# GPIO.add_event_callback(HAM, action2)
29+
# GPIO.remove_event_detect(HAM)
30+
while GPIO.input(HAM) == 0:
31+
print("0")
32+
33+
while GPIO.input(HAM) == 1:
34+
print("Water detected!!!")
35+
GPIO.output(LIGHT3, 1)
36+
time.sleep(1)
37+
GPIO.output(LIGHT3, 0)
38+
39+
40+
def main():
41+
try:
42+
definition()
43+
threads = []
44+
t3 = threading.Thread(target=fun3)
45+
threads.append(t3)
46+
t3.start()
47+
except KeyboardInterrupt:
48+
GPIO.cleanup()
49+
50+
51+
if __name__ == "__main__":
52+
main()

Ultrasonic.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import RPi.GPIO as GPIO
2+
import time
3+
import threading
4+
import sys
5+
6+
TRIG = 23
7+
ECHO = 24
8+
LIGHT1 = 17
9+
10+
11+
def definition():
12+
GPIO.setmode(GPIO.BCM)
13+
GPIO.setup(ECHO, GPIO.IN)
14+
GPIO.setup(TRIG, GPIO.OUT)
15+
GPIO.setup(LIGHT1, GPIO.OUT)
16+
17+
18+
def fun1():
19+
while True:
20+
GPIO.output(TRIG, False)
21+
print("Waiting For Sensor To Settle")
22+
time.sleep(2)
23+
GPIO.output(TRIG, True)
24+
time.sleep(0.00001)
25+
GPIO.output(TRIG, False)
26+
while GPIO.input(ECHO) == 0:
27+
pulse_start = time.time()
28+
while GPIO.input(ECHO) == 1:
29+
pulse_end = time.time()
30+
pulse_duration = pulse_end - pulse_start
31+
distance = pulse_duration * 17150
32+
distance = round(distance, 2)
33+
if 2 < distance < 50:
34+
print
35+
"Distance:", distance - 0.5, "cm"
36+
GPIO.output(LIGHT1, 1)
37+
time.sleep(1)
38+
GPIO.output(LIGHT1, 0)
39+
else:
40+
print("Out Of Range")
41+
42+
43+
def main():
44+
try:
45+
definition()
46+
threads = []
47+
t = threading.Thread(target=fun1)
48+
threads.append(t)
49+
t.start()
50+
except KeyboardInterrupt:
51+
GPIO.cleanup()
52+
53+
if __name__ == "__main__":
54+
main()

0 commit comments

Comments
 (0)