0% found this document useful (0 votes)
9 views

Raspberry Pi Programs

Python

Uploaded by

abinayasree2412
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Raspberry Pi Programs

Python

Uploaded by

abinayasree2412
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Blinking of LED using Raspberry Pi using Python Code.

Aim:
To interface LED on Raspberry Pi using Python Coding.
Connections:

Coding
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW)
while (True):
GPIO.output(8, GPIO.HIGH) # Turn on
sleep(1)
GPIO.output(8, GPIO.LOW)
sleep(1)
2. Interfacing Ultrasonic Sensor with Raspberry Pi Using Python
Coding
Aim: To Interface Ultrasonic Sensor with Raspberry Pi using
Python Coding.

Coding:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
TRIG=21
ECHO=20
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
While True:
Print(“Distance Measurement in Progress”)
GPIO.output(TRIG,False)
Print(“Waiting for sensor to settle”)
time.sleep(0.2)
GPIO.output(TRIG,True)
time.sleep(0.00001)
GPIO.output(TRIG,False)
While GPIO.input(ECHO)==0:
pulse_start=time.time()
While GPIO.input(ECHO)==1:
pulse_end=time.time()
pulse_duration=pulse_end-pulse_start
distance=pulse_duration*17150
distance=round(distance,2)
print(“distance:”,distance,”cm”)
time.sleep(0.5)

You might also like