Posty:bitPost Box Sensor with micro:bit

Ferry Djaja
5 min readJun 2, 2017

--

Posty:bit is a post box monitoring system that is built with micro:bit. It has two smart modules that are interacting with each other: Transmitter & Receiver.

Posty:bit — Post Box Sensor with BBC:micro:bot

Material List

  • 2x micro:bits
  • 2x battery holders
  • 4x AAA batteries
  • 2x USB connectors
  • 1x PIR sensor: DYP-ME003

Transmitter

We need to put the Transmitter in your mail box to monitor any incoming mail from the postman. It has a PIR sensor to detect any movement in the box. You need to put the Transmitter on one of the side inside the box. See Installation section for more details.

Receiver
You need to carry a Receiver in order to check your mail box. Once you pressed the button A on the micro:bit, it will check if there is a mail in your box and it indicates the following LED status:

LED Status

Build The Transmitter

Because our PIR sensor runs at 5V, we need to do some hacking to work with micro:bit. Remember micro:bit input voltage is 3.3V.

PIR Sensor

Instead of using the normal VCC 5V pin, we will use the VCC 3.3V pin as highlighted in point A in the above picture. The final connectivity is shown in the below picture. Refer to this article for more details explanation.

GND, OUT and VCC connectivity on PIR sensor

Hook up the PIR sensor to the micro:bit as shown below:

Hook up the PIR sensor with micro:bit

Adjust the sensitivity of PIR sensor

We need to adjust the sensitivity and time delay on the PIR sensor. Turn both orange dials anti clockwise as far as they will go. This will set the motion sensitivity to its least sensitive setting and time delay between sensing the shortest possible interval.

Adjust the PIR sensor

Final product of Transmitter

Our Transmitter

Build The Receiver

As there is no external component attached to the Receiver, actually there is nothing to build, it is only the micro:bit itself that you need carry in order to check your mail !!. As an illustration, you can attach the receiver onto your bag (like the below picture), like this guy did. The bag will tell you if there is a mail !! :)

Smart bag with micro:bit :)

Final product of Receiver

Receiver

Upload the HEX file onto the JavaScript Block Editor

You can find the source code on my GitHub, so you can learn the logic and may modify to enhance the functionality:

Download the HEX codes from GitHub and upload it onto the PXT editor by clicking on the “Open Projects” tab and point the code editor to import the HEX file. You can find the PXT editor on https://pxt.microbit.org/

You will have two projects: Transmitter and Receiver

Two projects in PXT Editor: Transmitter & Receiver

Let’s Coding !!

Transmitter

The Transmitter has a PIR sensor attached to digital pin P01.

The program is keep monitoring in-cycle the value of digital pin P01, if the value is high (1) — assuming the mail is in the box, it will notify the Receiver on the incoming mail from the postman by sending a certain value via the radio frequency group 18.

Notice that variable mail = 1 indicates mail has arrived, mail = 0 indicates no mail. If the radio receives receivedNumber = 3, it acknowledges the user has checked the status (the button A on the receiver was pressed).

If the radio receives receivedNumber = 4, it will tell the Receiver that Transmitter is still alive. This is important to make sure the Transmitter is working as expected.

Transmitter Block Diagram

Receiver

The Receiver has a radio function on the group 1 that monitors the incoming values from the Transmitter.

  • If receivedNumber = 1, indicates the mail has arrived (mail = 1)
  • if receivedNumber = 2, indicates no mail (mail = 2)
  • if receivedNumber = 5, indicates Transmitter is still alive and within range (batt = 1)
Receiver Block Code

Within “On Button A Pressed” block:

  • Check if Transmitter battery has gone flat or out-of-range and check if the mail is in the box then indicate the LED status:
  • Check if there is no mail and indicate the LED status. Do a ‘ping’ to Transmitter to make sure it is alive and responding.

Let’s upload the program to micro:bit

You need to download each program for transmitter and receiver and upload to micro:bit. Click done once you see the below screen, it means the script has been successfully generated and downloaded to your default download folder.

Drag the downloaded script for transmitter and receiver and drop it onto your micro:bit drive. The downloaded script should end with a .HEX extension. We will have two HEX files, one is for transmitter and the other one is for receiver.

Install the Transmitter

Put your Transmitter in your mail box in such a way if the postman put the mail in your box, the PIR sensor can detect. I use double-sided tape on the back of the wood and stick the Transmitter as shown in the below image.

That’s all !!

Hope you can learn how easy to use micro:bit and PXT block editor with your projects. Happy coding and until next time!

Read my second post to enhance the functionality with bluetooth advertising on micro:bit and Android app.

--

--