2024-10-17 19:11:52 +05:30
|
|
|
"""
|
|
|
|
THIS CODE HAS BEEN TESTED ON RASPBERRY PI 3B and 4B AND IS FULLY OPERATIONAL.
|
|
|
|
|
|
|
|
Problem Statement: IR Sensor
|
|
|
|
|
|
|
|
Code from InternetOfThingsAndEmbeddedSystems (SPPU - Third Year - Computer Engineering - Content) repository on KSKA Git: https://git.kska.io/sppu-te-comp-content/InternetOfThingsAndEmbeddedSystems
|
|
|
|
"""
|
|
|
|
|
|
|
|
# BEGINNING OF CODE
|
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
import time
|
|
|
|
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
|
|
GPIO.setwarnings(False)
|
2024-10-23 13:34:18 +05:30
|
|
|
GPIO.setup(16,GPIO.IN) # For IR sensor
|
|
|
|
GPIO.setup(26,GPIO.OUT) # For LED
|
2024-10-17 19:11:52 +05:30
|
|
|
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
if (GPIO.input(16)):
|
|
|
|
print("No object")
|
2024-10-23 13:34:18 +05:30
|
|
|
GPIO.output(26,GPIO.LOW) # LED OFF when no object detected
|
2024-10-17 19:11:52 +05:30
|
|
|
else:
|
|
|
|
print("Object Detected")
|
2024-10-23 13:34:18 +05:30
|
|
|
GPIO.output(26,GPIO.HIGH) # LED ON when object detected
|
2024-10-17 19:11:52 +05:30
|
|
|
except KeyboardInterrupt:
|
|
|
|
GPIO.cleanup()
|
|
|
|
# END OF CODE
|