레이블이 GPIO project인 게시물을 표시합니다. 모든 게시물 표시
레이블이 GPIO project인 게시물을 표시합니다. 모든 게시물 표시

2015. 2. 15.

[Casual hacking] GPIO app project 2 : how to build Air Button using ultrasonic sensor

[Casual hacking] GPIO app project 2 : how to build Air Button using ultrasonic sensor 



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!)

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! :)

[Casual hacking] GPIO 앱 프로젝트 2 : 초음파 센서 에어 버튼(Air button) 만들기!

 [Casual hacking] GPIO app PROJECT 2 : 초음파 센서 Air button 만들기! 


GPIO 앱을 이용한 두 번째 프로젝트!
초음파 센서를 이용한 에어 버튼(Air button) 만들기 입니다.

우선 초음파 센서는 UART라는 시리얼 통신을 이용하죠.
우선 사용한 초음파 센서 사양은 아래의 링크를 통해 확인 가능합니다!
(구입하신 전자제품 쇼핑몰에 대부분 데이타 시트 및 상세 정보 등이 있으니 참고하세요)

초음파센서 제품 가이드 : HG-C40U

자 그럼 기본적인 초음파 센서를 숙지했다고 가정하고 설명을 시작해볼게요~


1. 브레드보드 셋팅하기



그림처럼 TxD, RxD, GND, 5V 만을 설정해주었습니다.
또한 제대로 셋팅했는지 알기 위해 LED를 설치해놨습니다.


2. GPIO 앱에서 UART 설정하기

제품 가이드에 나와있던 것처럼 GPIO 앱 UI에서도 똑같이 설정해주면 됩니다!


  • Baud rate : 38,400 bps
  • Data bit : 8 bit
  • Stop bit : 1 bit
  • Buffer size : 100
    • 버퍼 사이즈는 한 번에 받을 글자 사이즈를 의미해요.
  • 값들을 모두 입력해주고  Set !
  • 그러면 'Read data'에 초음파 센서로부터 데이터가 넘어오게 됩니다.
  • /x32/x37/x03/x02/x5e/x31/x37/x32/x38/x03/x02/x5e.... 같은 데이터가 반복되게 됩니다. 여기서 /x03/x02/ 가 반복되고 유용한 초음파 거리 값은 그 바로 뒤 2번째에 나옵니다.
    나중에 이 데이터를 이용해서 버튼을 만들 수 있어요!
  • (단, 저희가 가지고 있는 HG-C40U 사양에 해당하는 내용이니, 여러분의 초음파 센서와 데이터가 다를 수 있습니다!)



자 그리고 초음파 센서가 제대로 설정됐는지 확인하기 위해 LED 핀도 설정을 함께 해줄게요!


3. 초음파 센서 테스트하기

아래의 두 가지 룰로 초음파 센서가 제대로 셋팅됐는지 확인해 보겠습니다!

이 두 가지 자동화 규칙으로 아래의 영상처럼 테스트를 해볼 수 있습니다.



우선 첫 번째 Rule 설정과정부터 확인해볼게요!

"초음파 거리가 10cm 이하가 되면, LED 가 켜져라"

- 첫 번째 룰 설정 .gif 로 보기!


<센서(sensor) 앱 설정 스텝>
1. GPIO app 선택  
2. UART serial 선택  
3. UART Read  
4. (녹색박스 체크)
5. 필터 선택 및 입력 : '+ Advanced' 클릭
 Test True : {{{{{{data!split("\x03\x02^")}}[1]!to_int}}!le(100)}}
(필터에 입력하는 값이 어렵죠..
/x03/x02 를 파싱해서 리스트의 2번째(=[1]) 데이터를 사용하는 겁니다. 위에서 말했듯이 그 값이 초음파 센서가 감지한 거리이기 때문이죠!
그리고 그 데이터를 숫자로 바꾼 후 le(less and equal) 100mm 이하거나 같다는 의미입니다. 직접 숫자를 바꿔서 테스트 해보세요!)


필터 값에 입력하는 코드를 자세히 알고, 직접 만들어보고 싶다면 아래의 링크를 참고해주세요!
'AMBLANG(엠비언시 언어) 자세히 알기'

<액츄에이터(actuator) 앱 설정 스텝>
1. GPIO app 선택  
2. Write Digital 선택  
3. GPIO pin$ 선택  
4. (녹색박스 체크), Set '1'(LED를 켜라)


이제 두 번째 Rule 설정과정을 볼게요.

"초음파 거리가 10cm 이상이 되면, LED가 꺼져라"

- 두 번째 룰 설정 .gif로 보기!


<센서(sensor) 앱 설정 스텝>
1. GPIO app 선택  
2. UART serial 선택  
3. UART Read  
4. (녹색박스 체크)
5. 필터 선택 및 입력 : '+ Advanced' 클릭
  Test True : {{{{{{data!split("\x03\x02^")}}[1]!to_int}}!ge(100)}}
(ge(greater and equal) 100mm 라는 의미입니다. 100mm보다 크거나 같거나가 되겠네요...)

<액츄에이터(actuator) 앱 설정 스텝>
1. GPIO app 선택  
2. Write Digital 선택  
3. GPIO pin$ 선택  
4. (녹색박스 체크), Set '0'(LED를 꺼라)


4. Air button 만들기!


자 이제 위의 테스트를 응용해서 에어 버튼(air button)을 만들어볼까요?
버튼의 용도는 Volumio 앱을 이용해서 'Play music', 'Stop music', 'Volume up', 'Volume down' 만들어보겠습니다!

자 우선 자로 에어 버튼을 만들기 위해 버튼의 위치를 만들어 볼게요!
... 제 책상에서 테스트 해봤어요 :)

# 버튼 설치




에어 버튼(air button) 위치

         ~ 10cm : volume up
11cm ~ 20cm : volume down
21cm ~ 30cm : play music
31cm ~ 40cm : stop music

# 자동화 룰 설정


첫 번째 룰 설정 방법만 gif 를 참고해보세요!


자 이렇게 해서 초음파(Ultrasonic wave)를 이용한 에어 버튼(air button)을 만들어봤습니다.

여러분은 다른 버튼을 만들어보세요!

초음파 거리를 이용해서 리모콘이 있던 제품, 리모콘이 없던 제품 또한 제어가 가능합니다!
"침대 옆에 에어 버튼(air button)을 만들어 전등을 껐다 켰다 하고 싶다"
"출근하고 에어 버튼(air button)을 누르면 모니터와 노트북 쿨러가 켜져라!"
GPIO  앱 프로젝트를 이용한 사물인터넷 체험은 계속됩니다! :)