Tutorial 8: Scaling a Custom Sensor using the Expression Builder

Sensors are available to measure all sorts of physical quantities and many of these sensors provide DC signals in the 0 to 5 volt range or a pulse count that can be directly read by an ioBridge web gateway. Another very common output signal is a 4 to 20 mA current that can also be read by the analog input of a web gateway with the simple addition of a 250 ohm resistor connected between the analog input and ground pin.

The signals output by these sensors represent physical quantities like temperature and humidity similar to the signals shown in Sensors. More often than not a built-in lookup table will not be available to convert the RAW readings to a physical quantity.

This tutorial show how you can use the Expression Builder functionality to scale RAW values to physical quantities. The Maxbotix line of ultrasonic sensors is used as an example.

For example the LV-MaxSonar®-EZ1™ detects objects from 0-inches to 254-inches (6.45-meters) and provides sonar range information from 6-inches out to 254-inches with 1-inch resolution. Objects from 0-inches to 6-inches range as 6-inches. The interface output formats included are pulse width output, analog voltage output, and serial digital output. For this tutorial we are going to use the analog voltage output.

Step 1 – Connect the Ultrasonic Sensor

Refer to the Maxbotix datasheet and connect the sensor to Channel 1 as follows.

According to the datasheet for this sensor AN outputs analog voltage with a scaling factor of (Vcc/512) per inch. A supply of Vcc = 5V yields ~9.8mV/in. The output is buffered and corresponds to the most recent range data.

Step 2 – Scale the Sensor Signal to Depth in Inches

Let’s assume that we have mounted the sensor outside pointing down at the ground at a height of 72 inches above the ground. Let’s also assume that we are lucky enough to own a vacation home near the ski slopes and we want to measure snow depth in inches.

Log into your account at ioBridgePro.com and click on the menu item Widgets. Click Create Widget, select Expression Monitor and click Next to see a page like the one below.

We are going to use the Expression Builder to read the range value on the analog input of channel 1 and convert the value into depth.

From the datasheet

Range (in inches) = AN (in volts)/Vcc*512 = AN/5*512

Since AN is connected to AI which measured the input voltage from 0 to 5V as a 10-bit RAW value 0 to 1023

RAW = AN/5*1023


Range = RAW/1023*5/5*512 = RAW/1023*512 ~ RAW/2 (close enough)

Retrieving the live RAW analog value from Channel I using the input expression.

%%input:[Module Serial],[Input Type],[Channel / Location]%%

the expression to convert the sensor range to depth is as follows

 RAW = %%input:25000031,AI,1%% Range = RAW/2 Offset = 72 Depth = Offset - Range

Change the Expression Monitor page to look at as follows

You should now see snow depth on your dashboard.

Step 3 – Send an Email Alert (Optional)

The last step is to set up an email alert when the snow depth is 12 inches or greater.

Click on the menu Actions and follow the wizard to create an alert for the analog inout on channel 1. Create Action, select analog input messaging, select your web gateway, select Channel 1. Enter the following on the page that looks like this.

Note the RAW value of 120. With a little manipulation of the equations above,120 is the RAW value when the range is 60 inches or the depth is 12 inches (72-60).

An email alert is now sent whenever the snow depth is 12 inches or higher.