Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group project 2025
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Evan Jones
group project 2025
Commits
bd94e65c
Commit
bd94e65c
authored
4 months ago
by
Evan Jones
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
c1afbb01
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mainv2.py
+43
-0
43 additions, 0 deletions
mainv2.py
with
43 additions
and
0 deletions
mainv2.py
0 → 100644
+
43
−
0
View file @
bd94e65c
import
grovepi
import
time
# === GROVEPI PORT ASSIGNMENTS ===
pir_sensor
=
2
# D2
ultrasonic_ranger
=
4
# D4
light_sensor
=
0
# A0
button
=
3
# D3
led
=
5
# D5
# === SETUP ===
grovepi
.
pinMode
(
pir_sensor
,
"
INPUT
"
)
grovepi
.
pinMode
(
button
,
"
INPUT
"
)
grovepi
.
pinMode
(
led
,
"
OUTPUT
"
)
# === LOOP: SENSOR READS + LED CONTROL ===
print
(
"
Initializing GrovePi sensors for smart doorbell...
"
)
try
:
while
True
:
# PIR Motion Sensor
motion
=
grovepi
.
digitalRead
(
pir_sensor
)
print
(
"
Motion Detected!
"
if
motion
else
""
)
# Ultrasonic Distance
distance
=
grovepi
.
ultrasonicRead
(
ultrasonic_ranger
)
print
(
f
"
Distance:
{
distance
}
cm
"
)
# Light Sensor (0-1023)
light_level
=
grovepi
.
analogRead
(
light_sensor
)
print
(
f
"
Light Level:
{
light_level
}
"
)
# Button Read + LED Control
button_state
=
grovepi
.
digitalRead
(
button
)
if
button_state
==
0
:
print
(
"
Button Pressed!
"
)
time
.
sleep
(
1
)
except
KeyboardInterrupt
:
print
(
"
Exiting smart doorbell monitor.
"
)
except
IOError
as
e
:
print
(
f
"
IOError:
{
e
}
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment