Temperature Sensor Code and Lesson Plans

 TS1 Show Tempature on Display Block Code  Copy and paste Text code
 TS1 Blockl Code

use Libraries.Robots.BirdBrain.Finch
Finch finch
output"Tempature as measured by the microbit chip"
repeat until finch:GetButton("A")
integer temp = finch:GetTemperature()
text temptxt = cast(text,temp)
output "Temperature: " + temptxt + " Degrees Celsius"
finch:PlayNote(temp*2,1)
say temp + " degrees Celsius"
finch:Pause(1)
end
say "Done"

finch:Disconnect() 

 

 Something new:  The finch gives us the tempautre as an integer. We want to have this spoken and speech needs text. Cast is the method we use to change and number or an integer in to text. (Line 6) in the last we have cast an integer in to a number. 

TS2 Tempetature Display

 TS2 Show Tempature on the Finch Display BlockCode  Text Code  
 TS2 display temp use Libraries.Robots.BirdBrain.Finch
Finch finch
integer temp = finch:GetTemperature()
integer startTemp= finch:GetTemperature()
integer highTemp = 0
repeat until finch:GetButton("A")
finch:SetTail("ALL",temp,0,0)
finch:SetTail("ALL",0,temp,0)
finch:SetTail("ALL",0,0,temp)
end
temp=finch:GetTemperature()
repeat until finch:GetButton("B")
temp=finch:GetTemperature()
if temp>highTemp
highTemp=temp
end
text temptxt = cast(text,temp)
finch:Output(temptxt)
finch:Pause(2)
end
text highTempTxt = cast(text,highTemp)
output "high Temperature = " + highTempTxt
output "Start Temperature = " + startTemp
output "End Temperature = " + temp
finch:StopAll()
finch:Disconnect() 
 The tempature sensor is on the processor chip on the back of the Micro-bit.   

 

TS3 Temperature Sensor with Centigrade and Fahrenheit 

TS3 Display Temperature in Fahrenheit.  BLOCK CODE CUT AND PASTE CODE
 Screenshot 2025 05 10 at 5.17.27 PM
 use Libraries.Robots.BirdBrain.Finch
//Converting C to F
Finch finch
integer temp = finch:GetTemperature()
integer startTemp= finch:GetTemperature()
integer highTemp = 0
number tempF =0
repeat until finch:GetButton("A")
finch:SetTail("ALL",temp,0,0)
finch:SetTail("ALL",0,temp,0)
finch:SetTail("ALL",0,0,temp)
end
temp=finch:GetTemperature()
tempF = temp * 1.8+32
output temp + "C " + tempF +"F "
repeat until finch:GetButton("B")
temp=finch:GetTemperature()
if temp>highTemp
highTemp=temp
end
text temptxt = cast(text,tempF)
finch:Output(temptxt)
finch:Pause(4)
finch:Output("F")
finch:SetMotors(20,2)
finch:Pause(2)
end
text highTempTxt = cast(text,highTemp)
finch:StopAll()
finch:Disconnect()
output "high Temperature = " + highTempTxt
output "Start Temperature = " + startTemp
output "End Tempature = " + temp
finch:StopAll()