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
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.
There are the usual 5V and GND pins located at each end of the pin header.
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.
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.
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.
For a manually-operated distance sensor you can ignore the Low/High reaction menu. Under 'Choose what happens' select Nothing, just display reading.
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.
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'.
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.
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.
In the next article we'll cover two of the newest features in AAIMI GPIO, conditional pins and software variables.