Read distance measurements from the sonic sensor within Node-Red
What You Will Learn:
- Basic Circuit Prototyping
- Basic Node-Red Programming
What You Need to Know:
What is a Sonic Sensor?
It is a sensor that works based on the principles of echo location. The sensor is able to emit ultrasonic pulses and read ultrasonic pulses, using this timing information along with the speed of sound and some math we can extrapolate distance to the surface the pulses have reflected against.
Thankfully the node we will be using will take care of the math for us.
Setting up the Hardware
I would suggest wiring it exactly as it is in the diagram, using 4 female to female jumper wires to allow you to point the sensor around freely.
Setting up Node-Red
Start Node-Red and navigate to 127.0.0.1:1880 using the web browser. Drag the “rpi srf” node and a “debug” node into the flow area.
Double click the “rpi srf” node to open its configuration settings. Set Pins to “16,18” (which corespond to GPIO 23,24). The programmer of this node decided that it was better to use the Raspberry Pi’s board pinout rather than the BCM standard, this web page shows both.
Next, open the “debug” nodes configuration settings. Check the debug window and node status options. This will display the last sent message beneath the debug node.
Link the nodes together and deploy the flow.
If everything has gone together properly, you should get numbers appearing below the “debug” node. These are distance measurements in centimeters, you can change the frequency of the measurements within the “rpi srf” node or see the entire measurement history in the debug tab.