1단계: 만들어 보세요.
프로젝트 소개
무선 문열림 경보기를 이용해서 문이 열렸는지, 문이 닫혔는지 알아내 보세요.
How to make it
- You will need two micro:bits with different code on each. One micro:bit acts as a radio transmitter and the other as a radio receiver.
- Attach the transmitter micro:bit and battery pack to the corner of a door frame and attach a magnet close to it on the corner of a door.
- Place the receiver micro:bit anywhere nearby.
- If the alarm doesn’t work as you expected, you may need to change the magnetic force strength number in the transmitter code. Pressing button A shows the current magnetic force reading. Use this to decide on the threshold number, taking readings with the door open and closed.
설명
- The transmitter program uses the micro:bit’s compass (magnetometer) input sensor and a loop to measure the strength of the magnetic field every two seconds.
- It uses selection so when the magnetic field strength falls below a certain level (the threshold), it sends a radio signal ‘open’. If the magnetism reading goes above the threshold, it sends the signal ‘closed'.
- When the receiver micro:bit receives the signal ‘open’, a cross appears on its LED display and an audible alarm sounds. When it receives the signal ‘closed’, a tick appears on its LED display and no sound plays.
준비물
- two micro:bits and at least one battery pack
- 자석 1개
- some adhesive putty to fix a magnet to a door and a micro:bit to a door frame
- if you have a V1 micro:bit and want to hear an audible alarm, optional headphones, buzzer or speaker and crocodile clip leads to attach them
2단계: 프로그래밍 해보세요.
센서 / 신호 전송기:
1from microbit import *
2import radio
3radio.config(group=17)
4radio.on()
5
6while True:
7 if button_a.was_pressed():
8 display.scroll(compass.get_field_strength())
9 if compass.get_field_strength() < 100000:
10 display.show(Image.DIAMOND_SMALL)
11 radio.send('open')
12 else:
13 display.clear()
14 radio.send('closed')
15 sleep(2000)
16
경보기 / 신호 수신기:
3단계: 더 좋게 만들어 보세요.
- 여러 대의 micro:bit 를 사용하고, 각각의 micro:bit 에서 서로 다른 무선 라디오 메시지를 전송하도록 하면, 각각의 문을 구분해서 문열림을 감지 할 수 있습니다. 예시. ‘back door open’
- 문이 열려 있었던 시간을 기록하는 변수를 사용해 보세요. - 냉난방 에너지를 절약하는데 도움이 되지 않을까요?
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.