tarun
Published © GPL3+

Raspberry Pi Node Red

Node-RED is a programming tool for wiring together hardware devices and used for Internet of Things.

IntermediateFull instructions provided2 hours1,578
Raspberry Pi Node Red

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

Node Red

Story

Read more

Schematics

node red connections

Node red flow chmdltgx6l

Code

ultrasonic sersor

Python
this code calculates the distance of an object which is in front of the sensor
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)

TRIG = 23
ECHO = 24

print "Distance Measurement In Progress"

GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)

GPIO.output(TRIG, False)
print "Waiting For Sensor To Settle"
time.sleep(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"

GPIO.cleanup()

Credits

tarun

tarun

0 projects • 5 followers
I coding micro controllers and connect them to the web and make some applications.I am an organizer of IoT User Group Hyderabad.
Contact

Comments