Skip to content

Activiteit

Radio deuralarm

Gevorderd | MakeCode, Python | Kompas, LED scherm, Radio | Communicatie, Magnetisme, Radiogolven, Relationele operators, Selectie, Sensoren

Stap 1: Maak het

Wat is het?

Een draadloos alarm om je te waarschuwen wanneer iemand een deur opent of open laat.

Hoe je het maakt

  • You will need two micro:bits with different code on each. De ene micro:bit fungeert als een radiozender en de andere als radio-ontvanger.
  • 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.
  • Plaats de ontvanger ergens in de buurt.
  • Als het alarm niet werkt zoals je had verwacht, moet je het nummer van de sterkte van de magnetische kracht in de zender code wijzigen. 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.

Zo werkt het

  • 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.

Benodigdheden

  • Twee micro:bits en ten minste één batterijpakket
  • een magneet
  • 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

Step 2: Codeer het

Sensor / zender:

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

Alarm / ontvanger:

1from microbit import *
2import music
3import radio
4radio.config(group=17)
5radio.on()
6
7while True:
8    message = radio.receive()
9    if message:
10        if message == 'open':
11            display.show(Image.NO)
12            music.play(["C4:4"])
13        if message == 'closed':
14            display.show(Image.YES)
15

Stap 3: Verbeter het

  • Gebruik meerdere micro:bits om de status van verschillende deuren te volgen door verschillende radioberichten te verzenden, b.v. ‘achterdeur open’.
  • Gebruik een variabele om te meten hoe lang deuren open blijven - kan dit helpen om verwarming te besparen?