Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
36 views9 pages

Raspberry Pi GPIO Projects

Uploaded by

Anvitha Moilla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views9 pages

Raspberry Pi GPIO Projects

Uploaded by

Anvitha Moilla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Pi Programs

LED FLASH

import RPi.GPIO as GPIO


import time
led = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(led,GPIO.OUT)

while True:
GPIO.output(led,GPIO.HIGH)
time.sleep(6)
GPIO.output(led,GPIO.LOW)
time.sleep(4)
HUMIDITY AND TEMPARATURE SENSOR (DHT11)

import sys
import Adafruit_DHT
import time

while True:
h,t = Adafruit_DHT.read_retry(11,17)
print('Humidity is {} % and temparature is {} C'.format(h,t))
time.sleep(2)
SWITCH INTERFACE TO RASPBERRY Pi

import RPi.GPIO as GPIO


swt1 = 2
led1 = 4

GPIO.setmode(GPIO.BCM)
GPIO.setup(swt1,GPIO.IN)
GPIO.setup(led1,GPIO.OUT)
while True:
GPIO.output(led1,GPIO.input(swt1))
print(GPIO.input(swt1))
import RPi.GPIO as GPIO
swt1 = 2
led1 = 4

def dosetup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(swt1,GPIO.IN)
GPIO.setup(led1,GPIO.OUT)

def do_main():
while True:
GPIO.output(led1,not (GPIO.input(swt1)))
print(GPIO.input(swt1))

def do_end():
GPIO.output(led1,False)
GPIO.cleanup()
def main(): if __name__=="__main__":
dosetup() main()
try:
do_main()
except KeyboardInterrupt :
print("Key Board Interrupt Occured")
do_end()
def main():
dosetup()
try:
do_main()
except KeyboardInterrupt :
print("Key Board Interrupt Occured")
do_end()

if __name__=="__main__":
main()
LDR SENSOR MODULE

import RPi.GPIO as GPIO


ldrd0 = 21
ledp = 4
GPIO.setmode(GPIO.BCM)

GPIO.setup(ldrd0,GPIO.IN)
GPIO.setup(ledp,GPIO.OUT)

while True:
led = GPIO.input(ldrd0)
GPIO.output(ledp,led)
print("input read is",led)
PUSH BUTTON SWITCH AS TOGGLE
import RPi.GPIO as GPIO SWITCH
import time
swt1 = 2
led1 = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(swt1,GPIO.IN)
GPIO.setup(led1,GPIO.OUT)
status = False
flag = 0
while True:
while GPIO.input(swt1):
flag = 1
print(flag)

if flag == 1:
if status == True:
status = False
flag = 0
else :
status = True
flag = 0
GPIO.output(led1,status)
print('status',status,flag)

You might also like