From fa047dee959e4323392b6dd70e8bb61e34a61f5c Mon Sep 17 00:00:00 2001 From: Kshitij Date: Thu, 17 Oct 2024 19:24:36 +0530 Subject: [PATCH] Added water level indicator code. --- Practical/Water level code.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Practical/Water level code.py diff --git a/Practical/Water level code.py b/Practical/Water level code.py new file mode 100644 index 0000000..61b0072 --- /dev/null +++ b/Practical/Water level code.py @@ -0,0 +1,26 @@ +""" +THIS CODE HAS BEEN TESTED ON RASPBERRY PI 3B, 4B AND IS FULLY OPERATIONAL. + +Problem Statement: Water level + +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 library + +# Initalize GPIO +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) +GPIO.cleanup() +GPIO.setup(16, GPIO.IN) # Set GPIO 16 as input for water level sensor signal +GPIO.setup(6, GPIO.OUT) # Set GPIO 6 as output for LED + +while True: + if (GPIO.input(16)) + GPIO.output(6, True) # Turn ON LED if water detected + else + GPIO.output(6, False) # Keep LED OFF if no water detected + +GPIO.cleanup() +# END OF CODE