-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestcode.py
More file actions
66 lines (50 loc) · 1.26 KB
/
testcode.py
File metadata and controls
66 lines (50 loc) · 1.26 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
import time
import RPi.GPIO as GPIO
print("Car Parking System : Setup Started")
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
'''
Define pin for sensors
'''
slot1_Sensor = 29
slot2_Sensor = 31
GPIO.setup(slot1_Sensor, GPIO.IN)
GPIO.setup(slot2_Sensor, GPIO.IN)
print("Car Parking System : Setup Complete")
# Define delay between readings
delay = 5
print("Car Parking System : System Begins")
while 1:
slot1_status = GPIO.input(slot1_Sensor)
time.sleep(0.2)
slot2_status = GPIO.input(slot2_Sensor)
time.sleep(0.2)
if slot1_status == False:
# Do something when Slot 1 is occupied
print("Slot 1 is occupied")
time.sleep(0.2)
else:
# Do something when Slot 1 is free
print("Slot 1 is Free")
time.sleep(0.2)
if slot2_status == False:
# Do something when Slot 2 is occupied
print("Slot 2 is occupied")
time.sleep(0.2)
else:
# Do something when Slot 2 is free
print("Slot 2 is free")
time.sleep(0.2)
print("Car Parking System : System Ends")
'''
Pin connections of Ir Module & rpi
# ir sensor 1 :
- out = pin 29
- Vcc = pin 2 (5v Power)
- Gnd = pin 6 (GND)
# ir sensor 2 :
- out = pin 31
- Vcc = pin 4 (5v Power)
- Gnd = pin 9 (GND)
'''