Keybox, email, and RFID

Keybox, email, and RFID

Our blog articles are generally used to give ideas on how to solve issues with Yoctopuce modules.Today, we offer you not an idea but a complete realization, which can be used by any user without computing knowledge...


The user has a key which must be returned to him in a key-box. He wants to receive an email when the key is back in the box. There is an Internet connection close to the box, but nothing else. The user has no specific computer skills. We must therefore offer a solution which doesn't require him to perform anything more complex than to view a web page.


How can we detect a key in a box? We had the idea to attach an RFID chip to the key and to place an RFID sensor in the box. Yoctopuce doesn't have an RFID reader in its module range. But Parallax offers one with a serial output for less than 50 dollars. We only need to connect a Yocto-Serial to it and to configure the module for it to behave like a sensor of which the value is the ID of the detected RFID chip.

To avoid having a computer permanently on close to the key-box, we propose to connect the Yocto-Serial to a YoctoHub-Ethernet. Thus, we can configure it to be driven in callback mode from a PHP script running on a remote server. Other advantage: the YoctoHub-Ethernet can be powered by PoE, we can therefore bring a single wire to the box.

The distinct electronic components needed to build the box
The distinct electronic components needed to build the box

This solution present numerous advantages: the customer only needs to connect the modules to one another, and the modules can be pre-configured. The programming part is limited to a PHP script which needs to be copied on a server, a task that can be easily performed remotely by someone else.


The Parallax RFID reader is a simple reader with a serial interface. It needs a 5V power supply which means that we can even power it from the Yocto-Serial. Its behavior is very basic: when it detects an RFID chip nearby, it sends once per second the chip ID on the serial line. When there is no chip, it doesn't do anything. The Yocto-Serial is simply connected to the YoctoHub-Ethernet which is connected to the network.

Connections between the modules
Connections between the modules

The RFID reader has rather limited capacities: it detects an RFID chip only if it is quite close, 2-3 centimeters at most. We must therefore make sure that when we put the key in the box it automatically finds itself close to the sensor. We used a simple mailbox and we built a small structure inside, a sort of funnel, at the bottom of which we put the sensor.

We put everything in a simple letter-box
We put everything in a simple letter-box


For the software part, we decided to put everything in a single PHP file which must:

  • Communicate with the YoctoHub-Ethernet of the box.
  • Send an email when the key is detected in the box
  • Offer a configuration interface to define how and to whom to send the email.

Rather than store the system state in a database, we decided to do it in a simple small .ini file. It's neither very elegant nor very efficient, but this avoids having to configure a database. The software installation is therefore limited to the copy of some files.

The complete PHP script is not very interesting. It is mostly code implementing a basic user interface. You can download it here. There are, however, some particularities:

  • The Parallax reader sends data only when an RFID chip is nearby, it doesn't do anything when the chip disappears. The Yocto-Serial has therefore no means of signaling that the key has been removed. However, the chip ID being mapped on one of the genericSensor of the Yocto-Serial, we can solve the issue by initializing again the value of this genericSensor right after reading it.
  • The Parallax reader is not very reliable: from time to time, without us knowing why, it sends an empty line, or even an incorrect ID. We suppose that this is due to transmission errors between the reader and the RFID chip. To circumvent this issue, we save the latest 3 states and decide to send an email only if those 3 states are identical.


For everything to work, the Yocto-Serial, the YoctoHub-Ethernet, and the script must be configured appropriately. You can configure the Yoctopuce modules with the VirtualHub, the PHP script offers its own configuration interface.

  1. Setting the Yocto-Serial power supply to 5V, the protocol to Line-based ASCII protocol, 2400, 8N1, none, and the levels to TTL 5V.
  2. Defining a new job containing a reactive task reading a hexadecimal numerical value mapped on the genericSensor1 function, and running this job.
  3. Making sure that the job previously defined starts automatically at the Yocto-Serial module startup, thanks to the Startup job parameter.
  4. Giving the "RFID" logical name to the "genericSensor1" function.
  5. Defining an "Outgoing callback" of the Yocto-API callback type in the YoctoHub-Ethernet, the callback URL must be that of the PHP script.
  6. Running the PHP script from a web browser, the default password is in the file source, and configuring the parameters necessary to send an email. Do not forget to configure the ID of the key to be detected.

When everything is configured, put the key and its RFID chip near the reader to receive a few seconds later an email signaling its presence. Here is a short video illustrating how the system works.



With two Yoctopuce modules, a cheap RFID reader, and a relatively short PHP script, we managed to build a system that sends an email each time it detects a key or any other object equipped with an RFID chip. Significant advantage: The system doesn't need a local computer to work, a simple connection to the Internet is enough... In short, a solution mirroring the Yoctopuce technology: simple and effective.

Add a comment No comment yet Back to blog

Yoctopuce, get your stuff connected.