This is the second project using the GPIO app.
Please note the following to build an Air Button using an ultrasonic sensor.
First of all, ultrasonic sensor adopts serial communication called UART.
If you would like to check out the specification of the sensor, you can do so by clicking the link below.
(Please note the data sheet or details from the product page of your purchased goods)
Product information from ultrasonic sensor: HG-C40U
From here on, please follow the instructions below.
1. Get your breadboard ready
Like in the picture, only TxD, RxD, GND, and 5V are connected.
An LED has also been pinned to be notified whether the settings are working properly.
2. Configure UART from the GPIO app
Please configure your settings as shown in the guideline of UI of GPIO app.
- Baud rate : 38,400 bps
- Data bit : 8 bit
- Stop bit : 1 bit
- Buffer size : 100
- The buffer size means the number of letters that can be delivered at one transfer.
- Register all values & Set !
- As a result, 'Read data’ of ultrasonic sensor is retrieved.
- /x32/x37/x03/x02/x5e/x31/x37/x32/x38/x03/x02/x5e.. so on. Data like /x03/x02 repeats and meaningful data follows from the third.
- (note that this is limited to HG-C40U specification and data may differ depends on your ultrasonic models.)
I will also pin a LED to provide me a feedback of whether the ultrasonic sensor has been properly placed.
3. Test the ultrasonic sensor
To test whether the ultrasonic sensor has been placed properly, I will use the rules below.
Like in the clip below, tests can be made with the two automation rules.
Lets go over with how to configure the first Rule.
“If the distance reading on ultrasonic is less than 10cm, turn on the LED."
- Check out the configuring process of the first Rule in .gif!
<How to configure a sensor app>
1. select GPIO app
2. select UART serial
3. UART Read
4. (check the green checkbox)
5. select and register filter : click '+ Advanced'
Test True : {{{{{{data!split("\x03\x02^")}}[1]!to_int}}!le(100)}}
This works by parsing /x03/x02 and making use of the second data in list(=[1]). This is the value retrieved from ultrasonic sensor.
(This may be a bit difficult step to some of us.. in short, le(less than and equal to) 100mm. Try testing by changing the numbers yourself!)
(This may be a bit difficult step to some of us.. in short, le(less than and equal to) 100mm. Try testing by changing the numbers yourself!)
If you’d like to understand more about how to register code in filter values and build the rule for yourself, please try out the link(blog) below.
<How to configure an actuator app>
1. select GPIO app
2. select Write Digital
3. select GPIO pin$
4. (check the green checkbox), Set '1’(turn on the LED)
Lets check out how to setup the second Rule.
“If the distance reading on ultrasonic is more than 10cm, turn off the LED."
- Check out the configuring process of the second Rule in .gif!
<How to configure a sensor app>
1. select GPIO app
2. select UART serial
3. UART Read
4. (check the green checkbox)
5. select and register filter : click '+ Advanced'
Test True : {{{{{{data!split("\x03\x02^")}}[1]!to_int}}!ge(100)}}
(ge(greater than and equal to) 100mm.)
<How to configure an actuator app>
1. select GPIO app
2. select Write Digital
3. select GPIO pin$
4. (check the green checkbox), Set '0’(turn off the LED)
4. Build an Air button!
Lets make use of the rules we created above for testing and create an air button.
Using the button and the Volumio app, I can 'Play music', 'Stop music', 'Volume up', 'Volume down.'
I’ve marked the heights for the buttons using a ruler and some Post-it.
… and this’s what my desk looks like :)
# Marking buttons
Heights for Air Button
~ 10cm : volume up
11cm ~ 20cm : volume down
21cm ~ 30cm : play music
31cm ~ 40cm : stop music
# Create automation rules
Please note the gif above for creating the first rule.
This’s been the guideline of creating an Air Button using ultrasonic wave.
Try building a button of different purpose.
Control digital devices and appliances using an Air Button next to yo ur bed.
“I wish I could turn on and off the bedside lights with Air Button."
“Turn on the monitors and notebook cooler with Air Button on my desk!"
More IoT experience to come using the GPIO app! :)



















