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:
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 http://www.instructables.com/id/Touch-me-Edison-ba... for some help)
and from this directory run node.js with sonar_edison.js
root@edison:~# node ./sonar_edison.js
You now have a web server listening at
that displays your latest distance measurements! Have fun!