To know more about the circuitry of this program visit our blog by clicking here. This program continuously displays speed of sound, temperature, and distance from sensor to obstacle.
import time
import RPi.GPIO as GPIO
while True:
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False) # Disable warnings about alternate isage of GPIO pins
# Define GPIO to use on Pi
GPIO_TRIGGER = 23
GPIO_ECHO = 24
# Speed of sound in cm/s at temperature
temperature = 20
speedSound = 33100 + (0.6*temperature)
print("Ultrasonic Measurement")
print("Speed of sound is",speedSound/100,"m/s at ",temperature,"deg")
# Set pins as output and input
GPIO.setup(GPIO_TRIGGER,GPIO.OUT) # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN) # Echo
# Set trigger to False (Low)
GPIO.output(GPIO_TRIGGER, False)
# Allow module to settle
time.sleep(0.5)
# Send 10us pulse to trigger
GPIO.output(GPIO_TRIGGER, True)
# Wait 10us
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
start = time.time()
while GPIO.input(GPIO_ECHO)==0:
start = time.time()
while GPIO.input(GPIO_ECHO)==1:
stop = time.time()
# Calculate pulse length
elapsed = stop-start
# Distance pulse travelled in that time is time
# multiplied by the speed of sound (cm/s)
distance = elapsed * speedSound
# That was the distance there and back so halve the value
distance = distance / 2
print("Distance : {0:5.1f}".format(distance))
GPIO.cleanup()
Hai friends. My name is Arun K Soman. I am from India. Now I am pursuing M.Sc. Electronics science degree from Cochin University of Science and Technoloy(CUSAT). I completed B.Sc Electronics from BPC college, Piravom. I am not a webdesigner. But I intersted in webdesigning. I have also some enthusiam in Electronics. I know how to use CSS kits like Bootstrap, w3.css etc. and HTML as well as Jekyll. This is not my first Jekyll template. I also created some jekyll templates before, But this is a full fledged one. This theme made with doing some tweaks on w3.css. It is fully open source under MIT Licence.Pull requests are welcomed to improve this theme.