Ramin Sangesari
Published © GPL3+

LoRa Weather Station with BBC micro:bit

Send and receive temperature data over LoRa using a pair of BBC micro:bits

BeginnerFull instructions provided1 hour611
LoRa Weather Station with BBC micro:bit

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
×2
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
REYAX RYLR896 Lora Module
×2
IOBIT Expansion Board Breakout
×1
ElecFreaks Micro:bit Breakout Board (Octopus:bit)
×1

Software apps and online services

MakeCode
Microsoft MakeCode

Story

Read more

Schematics

RYLR896 DATASHEET

Code

LoRa Temp Data Sender

JavaScript
let DataT = ""
let HumiData = ""
let TempData = ""
let DelayTime = 5000
serial.redirect(
SerialPin.P8,
SerialPin.P12,
BaudRate.BaudRate115200
)
basic.forever(function () {
    basic.showIcon(IconNames.Sword)
    TempData = "" + Environment_IoT.temperature(DHT11Type.DHT11_temperature_C, DigitalPin.P5)
    basic.pause(DelayTime)
    HumiData = "" + Environment_IoT.temperature(DHT11Type.DHT11_humidity, DigitalPin.P5)
    basic.pause(DelayTime)
    DataT = "" + TempData + "#" + HumiData
    if (DataT.length >= 3) {
        serial.writeString("AT+SEND=0," + DataT.length + "," + DataT + "\r\n")
        basic.showIcon(IconNames.Yes)
        basic.pause(DelayTime)
    }
})

LoRa Temp Data Receiver

JavaScript
serial.onDataReceived(serial.delimiters(Delimiters.NewLine), function () {
    rcvData = serial.readUntil(serial.delimiters(Delimiters.NewLine))
    txtProcess(rcvData)
})
bluetooth.onBluetoothDisconnected(function () {
    basic.showIcon(IconNames.No)
    bleS = 0
})
input.onButtonPressed(Button.AB, function () {
    if (BuzzStatus == 0) {
        BuzzStatus = 1
        basic.showIcon(IconNames.Yes)
    } else {
        BuzzStatus = 0
        basic.showIcon(IconNames.No)
    }
})
bluetooth.onBluetoothConnected(function () {
    basic.showIcon(IconNames.Yes)
    bleS = 1
})

function txtProcess (text: string) {
    rcvTest = text.substr(1, 3)
    if (rcvTest == "RCV") {
        if (BuzzStatus == 1) {
            music.playTone(131, music.beat(BeatFraction.Whole))
        }
        let addr_start = text.indexOf(",")
rcvTest = text.substr(addr_start + 1, text.length - addr_start)
        let TwoStep = rcvTest.indexOf(",")
MessageSize = rcvTest.substr(0, TwoStep)
        // basic.showString(MessageSize)
        MessageTXT = rcvTest.substr(TwoStep + 1, parseFloat(MessageSize))
        let IndexData = MessageTXT.indexOf("#")
basic.showString(MessageTXT.substr(0, IndexData))
        basic.showString(MessageTXT.substr(IndexData + 1, MessageTXT.length - IndexData))
        if (bleS == 1) {
            bluetooth.uartWriteString(MessageTXT)
        }
    }
}
let MessageSize = ""
let bleS = 0
let rcvData = ""
let BuzzStatus = 0
bluetooth.startUartService()
let TempIndex = 0
let rcvTest = ""
let MessageTXT = ""
basic.showIcon(IconNames.Target)
BuzzStatus = 1
serial.redirect(
SerialPin.P8,
SerialPin.P12,
BaudRate.BaudRate115200
)

Credits

Ramin Sangesari

Ramin Sangesari

16 projects • 264 followers
Programmer and IoT Developer

Comments

Add projectSign up / LoginAbout BBC micro:bit