I have been chatting lately with a civil engineer friend of mine and I was telling him about my new laser rangefinder, when he hinted that a rangefinder with logging capabilities would be far more interesting to him. Since my new toy is an Intel® Edison Arduino Board complete with a Grove Starter Kit Plus V2.0, kindly provided by Intel and Instructables (I was one of the 250 lucky ones!), I decided to make a rangefinder that not only measures distances, but also stores them with the press of a button and displays them through a web interface:)
As you may already know, laser rangefinders are still expensive for the tinkering crowds, so I used a very cheap HC-SR04 sonar I had lying around. It turns out that the Grove platform with its standardized breakout makes it easy to connect also non-Grove circuits, as the HC-SR04 sonar. I just had to change the pinouts (by connecting a second 4-pin cable) from GND-VCC-D8-D9 of the Grove Board to GND-ECHO-TRIGGER-VCC of the sonar, so that I could control TRIGGER from Arduino Edison's Pin 7 and ECHO from Pin 8
From what I've come to understand, HC-SR04 has a usable range of 4 meters, although in this example code, it is restricted to 2m.
Step 1: Setup
To build your own Intel IoT Edison sonar rangefinder distance meter, you'll need the following:
- Intel® Edison Arduino Board
- Grove Starter Kit Plus V2.0
- Ultrasonic ranging module HC-SR04
- Having successfully installed the Arduino IDE on your computer, updated to the latest Yocto Image and a working terminal connection to the board. For a detailed how-to, you can check my other instructable https://www.instructables.com/id/Touch-me-Edison-b...
- The Grove RGB LCD should be connected to one of the I2C ports of the Grove shield. The sonar should be connected as I described above to the D7 port of the Grove shield. For saving measurements, you need a Grove button or a Grove touch sensor - connect this to the D6 port.
Step 2: The Arduino Part
Create a folder named sonar_edison in your Arduino sketchbook and copy the following sonar_edison.ino and dtostrf.c in it.
Now open sonar_edison.ino from the Arduino Edison IDE, check that it compiles and upload it to your Intel® Edison.
If everything goes OK (and it should), the Grove RGB LCD screen will start showing the distance (in cm) your sonar rangefinder measures. In this normal operation, the screen appears green. If the distance exceeds 2m (ie, the sonar signal doesn't echo in time), the display turns red and displays "out of range".
By pressing the button, your Edison stores the value to /tmp/arduino.log in its linux filesystem (where your arduino sketch runs as a process). The screen turns blue and the stored value is displayed.
Step 3: Accessing Measurements From the Network
You can check the last stored measurements from your terminal with the following command:
root@edison:~# tail /tmp/arduino.log
We want however to be able to check our rangefinder measurements from our web browser (Isn't after all the Internet of Things what it's all about?)
So, create, type or copy and paste sonar_edison.js to a folder in your root home directory
(check https://www.instructables.com/id/Touch-me-Edison-ba... for some help)
and from this directory run node.js withsonar_edison.js
root@edison:~# node ./sonar_edison.js
You now have a web server listening at
that displays your latest distance measurements! Have fun!