Micro:bits Radio Temperature Sensor Display Python Coding
The above image shows 5 degrees C being displayed after the Sensor micro:bit was placed in a freezer.
The following Python code was written in the Mu editor. You compile the coding to two separate micro:bits that have power. Place the sensor into a freezer or on an ice pack and watch the temperature change making use of radio waves for communication.
This coding needs to be compiled onto the sensor micro:bit:
=============================================
# Language: Python Transcribed by: Steve Madsen
# The microbit can make use of radio waves
# This coding needs to be compiled to one of
# two microbits. Both need their own power supply
from microbit import *
# import the radio module
import radio
# turn the radio on
radio.on()
while True:
# the temperature of the microbit
# is stored in a variable called temp
temp = temperature()
# send to the second microbit a
# string of the the variable temp where it
# will display
radio.send(str(temp))
# sleep for 3 seconds and repeat
# sends the temp reading every 3 seconds
sleep(3000)
# Place the sensor microbit close to heat or
# in a freezer to see the display change.
=============================================
This second coding needs to be compiled onto a second micro:bit to display:
# Language: Python Transcribed by: Steve Madsen
# The microbit can make use of radio waves
# This coding needs to be compiled to the second of
# two micobits. Both need their own power supply.
from microbit import *
# import the radio module
import radio
# turn the radio on
radio.on()
while True:
temp = radio.receive()
# if there is a temp reading transmitted
# it will scroll accross the display
if temp:
display.scroll(temp)
# Place the sensor microbit close to heat or
# in a freezer to see the display change.
Comments
Post a Comment