RFIDuino Demo 2 - Solenoid Unlocker

If you haven't already, make sure to go through the RFIDuino Getting Started Guide to get your libraries and hardware setup.


Now we will extend upon Demo 1 to activate other devices. In this demo we are going to activate a small solenoid via a RobotGeek Relay board. This code will work for any digital output device (such as Relays, LEDs, buzzers and more.) Activating a solenoid or motor upon a read of the 'key' tag is the basic principal behind RFID enabled locks.

Hardware Required


  1. Connect your components as shown here. b_500_500_16777215_00__images_tutorials_rfiduino_rfiduino-lock-box_bb.png
  2. Open RFIDuino_demo2_lockbox onto your board. You can find this sketch under
  3. You will need to make sure the code is adjusted for your RFIduino hardware.
    v1.2 shields (2 pin antenna, 'REV 1.2' printed on the board) will need the following code
    RFIDuino myRFIDuino(1.2);     //initialize an RFIDuino object for hardware version 1.2
    v1.1 shields (4-pin antenna, no version number printed on the board) will need the following code
    RFIDuino myRFIDuino(1.1);     //initialize an RFIDuino object for hardware version 1.1
    Both lines of code are available in the RFIDuino_demo2_lockbox sketch, simply uncomment the one you don't need. If you are still unsure about what hardware you are using, see this page
  4. You will also need to modify the sketch to include the ID of a tag that we found in Hello World . Find line 57 - it looks like this.
    byte key_tag[5] ={0,0,0,0,0};			
    Now insert the ID numbers for your tag. For example, if our tags ID was '70 0 44 22 242' we would modify the code to look like this
    byte key_tag[5] ={77,0,44,22,242};
  5. Connect a micro USB cable from your computer to your Geekduino
  6. Load RFIDuino_demo2_lockbox onto your board using the upload button int the Arduino IDE.
  7. Once loaded, you disconnect the USB cable from your computer..
  8. Swipe the 'key' tag across the RFIDuino antenna. The green light will light up and your buzzer play three different notes. Additionally, the solenoid will fire.
  9. Swipe any tag that is not the 'key' tag across the RFIDuino antenna. The red light will light up and your buzzer play three monotone notes. The solenoid will not react.

Code Overview

This code is a modified version of RFIDuino_demo1. The code activates a new digital pin (9) so that it can control the relay board. By sending a HIGH signal to the relay board, the code activates the 'Normally Open(NO)' pin, connecting it to the common pin. When this connection is made, power can flow through the solenoid, activating it. This pin is held HIGH for a short period of time to 'unlock' the system, then the pin goes LOW to 'lock' the system

RFIDuino Functions used in this example

Power Options

The diagram shows connections using a single power supply and a wire nut for a connection. There are a couple of other options to wire everything up.

  • You can use the barrel jack to terminal converter found in the Power Converter Pack and wire up your devices as shown here.
  • You can cut off the barrel jack, then re-soldering it on, and also soldering two extra lines out, like this.
  • You can use two 12v power supplies, like this.

Next: Multiple Key Tags

Feedback Form