0% found this document useful (0 votes)
7 views4 pages

Raspberry Pi LED & Ultrasonic Sensor Guide

The document provides instructions for interfacing an LED and an ultrasonic sensor with a Raspberry Pi using Python. It includes sample code for blinking an LED and measuring distance with the ultrasonic sensor. The coding examples utilize the RPi.GPIO library for GPIO pin control.

Uploaded by

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

Raspberry Pi LED & Ultrasonic Sensor Guide

The document provides instructions for interfacing an LED and an ultrasonic sensor with a Raspberry Pi using Python. It includes sample code for blinking an LED and measuring distance with the ultrasonic sensor. The coding examples utilize the RPi.GPIO library for GPIO pin control.

Uploaded by

abinayasree2412
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

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

Coding
import [Link] as GPIO
from time import sleep
[Link](False)
[Link]([Link])
[Link](8, [Link], initial=[Link])
while (True):
[Link](8, [Link]) # Turn on
sleep(1)
[Link](8, [Link])
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 [Link] as GPIO
import time
[Link]([Link])
TRIG=21
ECHO=20
[Link](TRIG,[Link])
[Link](ECHO,[Link])
While True:
Print(“Distance Measurement in Progress”)
[Link](TRIG,False)
Print(“Waiting for sensor to settle”)
[Link](0.2)
[Link](TRIG,True)
[Link](0.00001)
[Link](TRIG,False)
While [Link](ECHO)==0:
pulse_start=[Link]()
While [Link](ECHO)==1:
pulse_end=[Link]()
pulse_duration=pulse_end-pulse_start
distance=pulse_duration*17150
distance=round(distance,2)
print(“distance:”,distance,”cm”)
[Link](0.5)

You might also like