Group Tembo
Arturo Apú Chinchilla. B20386
Erick Eduarte Rojas. B22305
Luis Felipe Rincón Riveros. B25530
The main goal of the project is to create a device that controls an electric latchkey with a circuit (with a relay and a transistor), a RaspberryPi and a Bar Code reader.
The RaspberryPi will receive a serial number from the Bar Code reader from the user's card. This number will travel from the RaspberrryPi to a server with a database. The database will have the registers of the authorized users (authorized by an administrator) to enter the room. Only if the user is authorized, the server will return a positive answer to the RaspberryPi for it to activate the circuit that sends the signal to the latchkey and opens it.
The project's goal is to control the entrance to the ArcosLab or any other room at the Escuela de Ingeniería Eléctrica. The device to be created is a low cost one; the RaspberryPi and the electric components are cheap artecfacts. It will include a permisions' database which only allows athorized people into the room.The device will also be usefull to keep a register of the people that enters the room.
Raspbian is a Debian variant used for the Raspberry Pi hardware 1)
http://www.raspberrypi.org/downloads
Unzip the image and write it to a empty SD card (4GB or more)
unzip ~/Donwloads/2012-12-16-wheezy-raspbian.zip
Assuming that you put the zip file in ~/Donwloads/
df -h
See what devices are currently mounted. Then, insert the card. The device that was not there the last time is the SD card. The device will appear as “/dev/sdd1” or similar.
umount /dev/sdd1
sudo dd bs=4M if=~/Downloads/2012-12-16-wheezy-raspbian.img of=/dev/sdd
This may take 5 minutes or more. “dd” does not show its progress.
sudo sync
This ensures the write cache is flushed.
The RaspberryPi configuration (Raspi-config) is quite simple and known if you already intalled Debian.
startx
If any doubt remains, consult http://elinux.org/RPi_Beginners.
WiringPi is a library that allows to control the out signal in the RaspberryPI. It also can be used to read from the pins 2). WiringPI is maintained under GIT.
* sudo apt-get install git-core
git clone git://git.drogon.net/wiringPi
The script in the WiringPi directory compiles and intalls WiringPi
cd wiringPI ./build
This installation is useful if you want to control the pins using python
sudo apt-get install python-dev
git clone https://github.com/WiringPi/WiringPi-Python.git cd WiringPi-Python git submodule update --init python setup.py install
ZBar Bar Code Reader is software suite for reading bar codes 3).
sudo apt-get install zbar-tools
zbarcam
Camorama is a gnome utility to view and save images from a webcam that allows to take snapshots in different times.
sudo apt-get install camorama
Now we implemented Zbar and Camorama in python codes to simplify and zip the function of the Raspberry pi. These are the two codes implemented:
#!/usr/bin/env python import os #open zbarcam in a console p=os.popen('/usr/bin/zbarcam','r') #print the code if the zbarcam read something while True: code = p.readline() print 'Got barcode:', code
#!/usr/bin/env python import os import time #open camorama to take pictures each minute c=os.popen('/usr/bin/camorama','r') #analyzes the last picture taken wich is called Webcam.png while True: time.sleep(70) p=os.popen('/usr/bin/zbarimg'+' Webcam.png','r') code = p.readline() print 'Got barcode:', code
sshfs is a filesystem client based on the SSH File Transfer Protocol
sudo apt-get install sshfs
sudo ifconfig
Another way is to install the package nmap into your computer and run into a console:
nmap -O <range_of_IP_to_search>
ssh -X pi@<ip_Raspberry_pi>
It will ask you for the user password: 'raspberry'
Resistors, an optocoupler, a diode, a transistor and a relay where elements necesary to build the circuit.
The 3V source is the RaspberryPi's GPIO pin and the ground is the RaspberryPi's GND pin. Connected to the positive of that source is a 1KΩ resistor to reduce the tension and effectivly control the Darlington (NTE3044) optocupler. This device lights its internal led when the RaspberryPi sends a specific signal. At this point, the current travels to another resistor that protects a 2N2222 transistor. The transistor amplifies the current from the optocoupler. The transistor is connected to the 5V source-controlled relay and to a diode for protection. The relay's common terminal is connected to one of the latchkey's wire; the relay's normaly-open terminal goes to the 12V source that feeds the latchkey.
The optocoupler isolates one part of the circuit from the other. This protects the RaspberryPi components and the rest of the circuit's components.
The database to create is a relational database. It establishes inter-relations between the data following the relational model 4). SQlite will be the database management system. SQLite is in a relatively small library (275 kiB) but allows databases as big as 2TB 5).
In this database will be the authorized users to enter the room in a specific schedule.
The database will have 4 tables.
A table 'Usuario' with the user's information. A specific number ('Num_Usuario' the primary key) and the person's characteristics ('Name', 'Email', and 'Doc_Idenficacion').
Another table 'Tarjeta' with the information related to de card used by the user. This is 'Num_Serie', the number in the bar code (primary key); 'Esta_Activa' a boolean that tells if the card is active or not; and 'Num_Usuario' that tells which user is related to the specific card.
A third table 'Horario' with the period in which the users are authorized to enter the room. 'ID' a number related to a user (primary key); a time 'desde' and a time 'hasta'. The user can enter the room from time 'desde' until time 'hasta'.
A final table 'Tarjeta-Horario' references 'Tarjeta' and 'Horario'.
http://www.sqlite.org/download.html
Then, run in the terminal
sqlite3
You are know in the command line shell for SQLite.
sqlite> create table Usuario ( ...> Num_Usuario int NOT NULL primary key, ...> Nombre varchar(50) NOT NULL, ...> Email varchar(50) NOT NULL, ...> Doc_Idenficacion varchar(50) NULL ...> );
sqlite> create table Horario ( ...> ID int NOT NULL primary key, ...> Desde time(7) NOT NULL, ...> Hasta time(7) NULL, ...> Doc_Idenficacion varchar(50) NULL ...> );
sqlite> create table Tarjeta ( ...> Num_Serie varchar(100) NOT NULL primary key, ...> Activa bit NOT NULL, ...> Num_Usuario int NULL, ...> );
sqlite> create table Tarjeta ( ...> Num_Serie varchar(100) NOT NULL primary key, ...> ID int NOT NULL, ...> Es_Valida bit NOT NULL, ...> FOREIGN KEY Num_Serie REFERENCES Tarjeta ...> FOREIGN KEY ID REFERENCES Horario ...> );