|Software apps and online services:|
Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click. It is build on Node.js. Node Red can be installed on Raspberry Pi and its server can be run on it. A sensor is connected to Raspberry Pi and this data is sent to mobile as a SMS. The whole thing is done using Node Red. The ultrasonic sensor is connected to Raspberry Pi and coding done using Python. Node Red has a inbuilt nodes installed in it. Using the exec node in Node Red it takes the data from ultrasonic sensor. This data is send to mobile using Twilio node in the Node Red. Let's do this in step by step.
- Raspberry Pi pin number ----- Ultrasonic sensor pins
- 2 ---- Vcc
- 6 ---- Ground
- 23 ---- trig
- 24 --- Echo
After connecting the ultrasonic sensor, the Raspberry Pi code, the code given below and check it using the command:
sudo python <path of the python file>
If the operating system of the Raspberry Pi is Raspbian Jessie, it comes with inbuilt installation. By starting the applications, it points to a URL to open the UI of Node Red.
After starting the Node Red UI connect the nodes as shown above. Select the exec node and name it as ultrasonic. In the exec node, it asks for the path of the directory, so paste the directory of the Python code which you have saved. Later for sending SMS to your mobile you need to sign up to Twilio https://www.twilio.com/. After creating the account fill the credentials in the Twilio node and deploy the application. Now everything is done.
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()
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!