We had an installation of a Test your Strength machine and want to detect if the puk hit different high-levels. Normally you would use small light-sensors or already motion sensors. Both normally work with Infrared-LEDs and Infrared-Detectors. The problem is, that if you use those sensors in direct sunlight, which also is partly in infrared spectrum, the sensor does not work perfectly correct. As we had no chance to test the entire setup before and would mount the sensors onto the machine just hours before the official start, I had to minify the risk.

So I went with the Grove ultrasonic ranger. In my case the measurement of the distance was not important. I just wanted to know if there was a movement in a specific range in front of the sensor.

As I used the sensor together with Node-RED running on a Raspberry Pi, I wrote an Node-RED node to do all tasks I needed.

Connect Grove Ultrasonic Ranger

The Grove Ultrasonic Ranger has a connector on the board and you’ll have also an connector cable with four pins delivered with it. Black is the ground cable, connect this to a ground pin. Red is the 3.3V or 5V connector, connect this to the 5V pin of the Raspberry. Please connect the yellow Signal cable to a GPIO pin of the Raspberry Pi – in this example use the PIN 36. You need to know the PIN number ( = GPIO 16 ).

Node-RED ultrasonic node

To install the node on your raspberry please do the following steps on your Raspberry Pi:

Switch into the Node-RED modules directory:
cd /home/pi/.node-red/node-modules/

Download the node from Github:
git clone git://github.com/dinnerout/node-red-node-usonic.git

And finally restart Node-RED or the entire Raspberry Pi. After this you should be able to use the rpi-usonic node from the Raspberry section.

You have six different fields to edit (all units are measured in centimeters):

  • Signal Pin – Enter the PIN number (see above) where you connected the Signal connector
  • Hit Distance – The minimum distance which counts as a hit
  • Maximum Range – The minimum distance to detect collisions
  • Minimum Range – The maximum distance to detect collisions
  • Hit Sleep – Seconds to wait after a hit is detected before continous to detect motion
  • Name – A node name

Each time any object is within the detection range and closer to to sensor than given in Hit Distance the node will output the distance value in centimeters.

You also have the possibility to set a minimum and a maximum detection distance. This helps you to improve the performance of the detection script. The sensors sends a small signal out and waits until the signal is detected back. By the duration the signal needs to come back the distance is calculated.

Sometimes it is helpful to set a minimum distance. The sensor is measuring with a signal of 42kHz frequency. As this could also be output by audio speaker, there might be wrong detections as the speaker output might be detected as signal input. This will be filtered by a minimum range of 1cm.

I hope this is helpful for anyone.

Node RED Ultrasonic Node

cheers.
Sebastian

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.