Panic Button using XinaBox, micro:bit and Ubidots

Panic Button using XinaBox, micro:bit and Ubidots

Learn how to create a Panic button, that will send text message directly to your mobile phone when pushed.

XinaBox produces a range of 70+ modular xChips, which includes cores/CPUs, sensors, power, communication, output, and storage, using a connectivity standard without wires, soldering, breadboards or hardware knowledge

The xChip CW01(ESP82666 Core) is a Wi-Fi module, that enables its users to send/receive data to/from cloud anywhere.

This xChip BM01 is designed to interface with the micro:bit single board computer. This provides an interface to support the XinaBox xChips ecosystem, adding support for many additional sensors etc.

The BBC micro:bit (MB) is a handheld, programmable micro-computer that can be used for all sorts ofcool creations, from robots to musical instruments – the possibilities are endless.

By the end of this guide you will be able to build a “Panic button” device. The device consists of a central gateway MB and multiple clientMBs. Client MBs has two buttons a Red and Green. Whenever, any button is pressed on client MB, it then sends message to gateway MB over Bluetooth. The gateway then sends text message to the specified mobile number using Ubidots.

The Red button is used to send text message, whenever a user feels Panic. The user is required to press the Green button within an hour to indicate OK situation, otherwise if not pressed, text message is sent to the mobile phone that something may be wrong.


    • 1x BM01 - micro:bit Bridge
    • 1x CW01 – Wi-Fi Core (ESP8266/ESP-12F)
    • 1x IP01 - USB Programming Interface (FT232R)
    • 1x XC10 - 10-Pack xBus Connectors
    • 2x micro:bit (at-least)
    • Ubidots
    • (Optional) Foam board
    • (Optional) Color paper
    • (Optional) Hot-glue gun


    1. Flashing Firmware
    2. Hardware Setup
    3. (Optional) Adding foam buttons to the original buttons
    4. Integrating Ubidots SMS/Email Event
    5. Result
    6. Summary

    1. Flashing Firmware

    1. Flash CW01.bin Firmware to CW01 using XinaBox Uploader
    2. Flash MBClient., py to Client micro:bit
    3. Flash to Gateway micro:bit

    2. Hardware Setup

    Connect micro:bit, CW01, BM01 and IP01 together using the XC10 xBus connectors. You may connect it as shown in the diagram below. Please see this guide on how to assemble xChips generally.

    Then connect IP01 to PC or Power bank to provide enough power to work.

    After the gateway is Powered On the gateway should display "Tick mark" 3 times consecutively, indicating that the gateway is connected to Ubidots, otherwise if crossed is diplay even for once, the gateway should be restarted to reconnect to Ubidots.

    3. (Optional) Adding foam buttons to the original buttons

    1. Cut the foam board into appropriate button size and shape

    2. Paste color paper of required color onto the cut foam pieces

    Attach each foam piece to the micro:bit client’s button:

    Attach battery pack of 2x AAA size to the MB. Click any of the button to create device on Ubidots.

    When you press the button the client MB displays button's alphabet and the gateway MB displays a Happy face.

    4. Integrating Ubidots SMS/Email Event

    1. Go to Ubidots Event. Select your Device 'PANIC', Variable 'help'. Select value form drop-down and set it to "1":

    IMPORTANT NOTE: Ubidots charges 20 credits per event, while Email is charged 1 credit per event.

    2. Enter your Phone number/Email address. Enter the message to be sent:

    5. Result

    Press the red button, the message is received within few seconds.

    6. Summary

    In this project we have built a “Panic button” device with XinaBox and micro:bit. The device sends text message to the mobile phone when a Red button is pressed, calling for help. The project is useful for patients, especially for those who are patient of mild Alzheimer's disease.

    Code Python
    micro:bit Gateway

    from microbit import *
    import radio
    radio.config(length=64, queue=8, channel=11, power=6)
    #   NOTE: radio settings are identical to those in the code
    uart.init(baudrate=9600, bits=8, parity=None, stop=1, tx=pin20, rx=pin19)
    # NOTE: gets the uart (serial / USB) port on the micro:bit ready to communicate with the CW01
    numberOfClassroomMicrobits = 10
    def sendMessageToCW01(parm):
        data = uart.readline()
        while(data is None):
            data = uart.readline()
        if(len(str(data)) >0):
            uartMessageID = getIntegerFromString(data[:1])
            if(uartMessageID == 1):     # NOTE: a tick is displayed when data is being transmitted correctly to the CW01
            else:                   # NOTE: this means that a cross is displayed when an attempt to send data fails
    def processRadioSignal(radioSignal, numberOfClassroomMicrobits):        #   NOTE: a 'valid' signal looks like this "0_a" or this "11_b"
        if(len(str(radioSignal)) < 3):   return False                       #   NOTE: valid radio signals are at least 3 or more characters long
        locationOfUnderscore = getLocationOfUnderscore(radioSignal)
        if(locationOfUnderscore == -1): return False                        #   NOTE: valid radio signals contain an underscore
        currentMicrobitID = getIntegerFromString(radioSignal[0:locationOfUnderscore])
        if(currentMicrobitID < 0):    return False                          #   NOTE: valid radio messages begin with an integer starting at 0.
        if(currentMicrobitID >= numberOfClassroomMicrobits): return False   #   NOTE: IDs should go from 0 to (numberOfClassroomMicrobits - 1)
        #   NOTE: If we've reached this point of the code the radioSignal has passed all our validation checks.  It is 'safe' to process it.
        return sendValidMessageToCW01(radioSignal, locationOfUnderscore, currentMicrobitID)
    def sendValidMessageToCW01(radioSignal, locationOfUnderscore, currentMicrobitID):
        messageType = str(radioSignal[locationOfUnderscore +1 : locationOfUnderscore +2])
        #   NOTE: you could experiment with sending new types of data from the classroom microbit - how about temperature ("0_c_25")
        if(messageType == "a"):
            return True
        if(messageType == "b"):
            return True
        return False
    def getLocationOfUnderscore(radioSignal):
        #   NOTE: The underscore can only be in 1 of 2 places in the string, so KISS:
        radioSignalStr = str(radioSignal)
        if(radioSignalStr[1:2] == "_"):    return 1
        if(radioSignalStr[2:3] == "_"):    return 2
        return -1
    def getIntegerFromString(uncheckedString):
        try: return int(uncheckedString)
        except ValueError: return -1
    #   INIT:          # NOTE: the square is shown on your micro:bit while it is connecting to Ubidots
    uart.write("$")                     # NOTE: Cleans out the serial buffer
    uart.write("+9@?$")                 # NOTE: Reboots the CW01
    sleep(5000)                         # NOTE: long delay is necessary - we need to give Wi-Fi time to sort itself out.
    uart.write("$")                     # NOTE: Clean out Serial buffer, again.
    # EDIT GUIDELINES: you MUST enter the name and password of the Wi-Fi network you are trying to connect to in the line above.
    # EDIT GUIDELINES: you MUST enter the DEFAULT TOKEN from Ubidots in the line above.
    # NOTE: above line tells the micro;bit where to send the data to - its a Ubidots URL.
    while True:
        if(processRadioSignal(radio.receive(), numberOfClassroomMicrobits)):
        sleep(100) Python
    mirco:bit Client

    from microbit import*
    import radio
    radio.config(length=64, queue=8, channel=11, power=6)
    #   NOTE - radio settings are identical to those in the code
    thisMicrobitID = 0
    # EDIT GUIDELINES: remember to name each classroom microbit with a unique integer.  Start from 0 and count upwards.
    while True:
            radio.send(str(thisMicrobitID) + "_a")
            radio.send(str(thisMicrobitID) + "_b")
    Previous article Riverdi and XinaBox - Hello World
    Next article Data Capturing with micro:bit, XinaBox and IoT