Open doors with a Raspberry Pi and RFID module

RFID Module

The centerpiece of this project is the RFID module [1], which in this case is based on the MFRC522 chip [2]. It can be controlled serially via I2C or with the SPI interface. This RFID module only has an SPI interface, which the Raspberry Pi also has.

The operating voltage for the module is 3.3V, and the power consumption is maximum 26mA, which the Rasp Pi can deliver easily. The module works at a frequency of 13.56MHz, which means it can read and write all of the standard cards. Table 1 shows how the module connects to the Raspberry Pi.

Table 1

RFID Module to GPIO

Module

Raspberry Pi

Header Pin No.

SDA

GPIO 8 (CE0)

24

SCK

GPIO 11 (SCLK)

23

MOSI

GPIO 10 (MOSI)

19

MISO

GPIO 9 (MISO)

21

IRQ

GND

GND

25

RST

GPIO 25

22

3.3V

3.3V

1

The Servomotor

The power supply for the servo used to open the door should not come directly from the GPIO. The motor can cause disruptions that could make the Rasp Pi crash. Moreover, you should not connect the control wire for the servo directly to the GPIO, because the Pi could be seriously damaged in the case of a fault.

The solution for this problem is to use a voltage converter that generates the operating voltage for the servomotor from any DC power source. A simple transistor stage decouples the control line, which also raises the signal level of the GPIO (3.3V) to the operating voltage of the servo (Figure 3). Almost any NPN transistor will do; here, I used a BC547B [3].

Figure 3: The circuit diagram to connect the RFID module and servomotors to the Raspberry Pi.

In this project, I used an OKL-T/1-W12N-C [4] voltage converter. However, this relatively low-priced module only has an effective grade of some 90 percent and delivers a maximum of 1A. Although the module is intended for surface mounting, soldering it to a header makes it possible to use the module on a breadboard.

The voltage regulator terminal is grounded with a variable resistor. The value of the resistor influences the size of the output voltage. The combination of a solid resistor and a 500-ohm, 10-gear potentiometer makes it easy to set the operating voltage for the servo. Typically this would be 6V.

ServoBlaster controls the servomotor. The commands used to install this tool are found in Listing 1. To load the userspace driver for a servomotor, you should start the server with the call in the last line. The --pcm ensures that ServoBlaster will not use the generator, which could interfere with the Rasp Pi sound output. The --invert switch inverts the signal to compensate for the inverted transistor level. You can close ServoBlaster with:

Listing 1

Installing ServoBlaster

$ sudo apt-get update
$ sudo apt-get upgrade
$ git clone git://github.com/richardghirst/PiBits.git
$ cd PiBits/ServoBlaster/user
$ make
$ sudo ./servod --p1pins=7 --pcm --invert
sudo killall servod

Servod creates an easy-to-use device driver. Using the instruction

echo 0=140 > /dev/servoblaster

you send the value 140 to servo 0, or about the middle position for the project presented here. The value for the open door is 60, whereas the value for the closed door is 170. You will need to figure these values out on your own through some trial and error because servomotor models almost always behave slightly differently.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content