Anth's Computer Cave

AAIMI GPIO Tutorial Hub

AAIMI GPIO is a web-based control interface for the Raspberry Pi and Arduino. Check out the tutorials below.


AAIMI GPIO Distance Sensor

7th December 2017

In this article I'll show you how to configure and use a distance sensor with AAIMI GPIO on a Raspberry Pi.

Distance sensor basics

A distance sensor. Picture: Anthony Hartup

I've previously covered using distance sensors with an Arduino in another article in the Cave. They work by sending a short pulse outwards and waiting for the pulse to return. By calculating the elapsed time they can accurately measure the distance to an object.

The unit pictured above costs about $1.50 on Ebay. It has a maximum range of around 3.5 metres.

Let's hook it up and configure AAIMI GPIO to use it.

Connections

There are the usual 5V and GND pins located at each end of the pin header.

A distance sensor connected to a Raspberry Pi. Picture: Anthony Hartup

There are also two other pins, the echo and the trigger.

The trigger connects to an output on the Pi and as the name suggests, triggers the pulse for a measurement.

The echo pin connects to an input on the Pi and listens for the return signal. As with many other devices you need a 1K resistor on the echo wire to limit the current returned to the Pi.

Configure sensor

I'll configure a standard, manually-operated distance sensor first, then move on to an example of using the distance sensor as a proximity-cutoff switch for machinery.

Manual measurement

Power on the Pi and, in the AAIMI GPIO configuration window in your browser, click on the echo pin for your distance sensor. In my case I click GPIO_17, and name the pin 'Ruler'. Under pin-type I select Distance Sensor then click Next.

Selecting distance sensor in AAIMI GPIO. Picture: Anthony Hartup

For a manually-operated distance sensor you can ignore the Low/High reaction menu. Under 'Choose what happens' select Nothing, just display reading.

Setting the trigger pin for a distance sensor connected to a Raspberry Pi. Picture: Anthony Hartup

Enter the pin number for the trigger pin, leave 'Manual measure' selected and click next.

You can now go to the Run tab and you'll see your distance sensor.

Measuring with a distance sensor and AAIMI GPIO. Picture: Anthony Hartup

Click Measure and you'll see the distance in centimeters between the sensor and the nearest object.

Use as proximity cutoff switch

That's the basic version, now we'll re-configure the sensor as a proximity cut-out to switch machinery off if someone gets too close to the moving parts.

As before I select GPIO 17, name it Ruler and select Distance Sensor from the drop-down menu.

I want this sensor to switch an output off when the distance is too low, so I select Low in the High/Low drop-down menu. Under 'Choose what happens' I select 'Switch an output pin off'.

Using a distance sensor as a proximity-switch with AAIMI GPIO. Picture: Anthony Hartup

Ignore the optional conditional pin (I'll cover that in another article) and enter the number for your trigger pin.

Select Polling instead of Manual measure and enter your desired cutoff measurement. I've settled on 30 centimeters.

Using a distance sensor as a proximity-switch with AAIMI GPIO. Picture: Anthony Hartup

I'm going to switch a relay off attached to GPIO 10 so I enter 10 in the output pin field.

We obviously want a safety cut-off to work all the time so I select Always under When this applies. I select Indefinitely under Choose how long, meaning if the cut-out occurs, the relay will stay off until I manually switch it back on.

Click Next, head to the Run tab and switch on the output you wish to protect with the proximity-switch.

Place your hand within the trigger-distance of the sensor and the output should switch off.

Next

In the next article we'll cover two of the newest features in AAIMI GPIO, conditional pins and software variables.

Cheers

Anth


Previous: AAIMI GPIO Notifications

Next:

_____________________________________________


Comments

Leave a comment on this article