Difference between revisions of "S17: Logan"
Proj user3 (talk | contribs) |
Proj user3 (talk | contribs) (→Project Video) |
||
Line 673: | Line 673: | ||
− | [https://www.youtube.com/watch?v=AsH4mrEF1nk | + | [https://www.youtube.com/watch?v=AsH4mrEF1nk CMPE244 S17 LoganText to Speech Demo] |
− | [https://youtu.be/aqmqXs8FgXM PCB Demo] | + | [https://youtu.be/aqmqXs8FgXM CMPE244 S17 Logan PCB Demo] |
[https://youtu.be/_g4aXTIMUgQ CMPE244 S17 Android App Demo] | [https://youtu.be/_g4aXTIMUgQ CMPE244 S17 Android App Demo] | ||
− | |||
=== Project Source Code === | === Project Source Code === |
Revision as of 00:28, 26 May 2017
Contents
- 1 Logan The Smart Lock
- 2 Abstract
- 3 Objectives & Introduction
- 4 Schedule
- 5 Parts List & Cost
- 6 Design & Implementation
- 7 Testing & Technical Challenges
- 8 Conclusion
- 9 References
Logan The Smart Lock
Abstract
Have you ever locked yourself out? Have you ever waited outside the door for losing your keys? These are some of the scenarios every home owner goes through. Security has been and still remains a major concern in residential spaces, private firms and government offices. Over 5,400 burglaries happen every day in the United States. Keeping many keys for each and every door is troublesome and maintaining access to authorized personnel is an issue. The traditional method also has cost issues involved in the fabrication and duplication of the keys, which causes lot of security issues in case of lost keys. In this project, we developed an innovative lock system prototype which can be controlled by using a smart phone. The speciality of this prototype relies on integrating new technologies with the older one which result in a smart and more efficient system. We propose a smart lock system which can increase home security. Smart Lock provides a mechanism to lock/unlock your door with your Smart Phone by using Bluetooth communication with password protection. The door locks/unlocks automatically when the correct password is entered on the Mobile Application. We are using Nordic Wireless communication to access multiple locks in this project. Another additional feature in the project is interfacing the Text-to-Speech in order to inform/guide the user at every step.
Objectives & Introduction
- Locking/Unlocking of the Electric Door Strike using a Mobile App over Bluetooth
- Design of Printed Circuit Board (PCB) to simplify the hardware system design
- Combination of PIR Motion sensor and Mobile App to increase security
- Accessing the other locks using the Nordic Wireless
- Text-to-Speech to guide the User at every step
Team Members
Roles & Responsibilities
- Harsha Gorantla
- Text-to-Speech Module, PCB Design and Complete System Algorithm
- Krishank Mehta
- Hardware Design and assembling, Software Flow, PCB design, PIR sensor and Door Strike
- Prashant Aithal
- Mobile App, PCB Design and Nordic Wireless Communication
- Shruthi Narayan
- PCB design, 3D Printing, Bluetooth and Testing
Schedule
Sl. No | Start Date | End Date | Task | Status | Actual Completion Date |
---|---|---|---|---|---|
1 | 03/21/2017 | 03/28/2017 | Project proposal submitted | Completed | 03/21/2017 |
2 | 03/28/2017 | 04/04/2017 | Research on the whole system flow and deciding on components Assign individual task Order the components |
Completed | 04/04/2017 |
3 | 04/04/2017 | 04/11/2017 | Implementation of the PIR sensor with the SJ one board Initial circuit design of PCB |
Completed | 04/11/2017 |
4 | 04/11/2017 | 04/18/2017 | Integration and testing of Electric Door strike functionality Design of PCB for bluetooth, PIR sensor, SJOne, door-strike related pins on the PCB |
Completed | 04/18/2017 |
5 | 04/18/2017 | 04/25/2017 | Integration of door strike with PIR sensor Interface Bluetooth module with SJOne board Design of the Android Mobile app. |
Completed | 04/25/2017 |
6 | 04/25/2017 | 05/02/2017 | Verify communication between Bluetooth module and Android app Extending the functionality to multiple locks using Nordic Wireless. |
Completed | 05/02/2017 |
7 | 05/02/2017 | 05/07/2017 | Integration of Text-to-Speech module Individual system testing. |
Completed | 05/07/2017 |
8 | 05/07/2017 | 05/14/2017 | Integration of the whole system Debugging and testing of the whole system Report preparation. |
Completed | 05/14/2017 |
9 | 05/14/2017 | 05/21/2017 | Final testing and fine tuning Report preparation. |
Completed | 05/21/2017 |
Parts List & Cost
Item# | Part Description | Vendor | Qty | Cost |
---|---|---|---|---|
1 | SJ One Board (LPC 1758) | From Preet | 3 | $240 |
2 | Battery | From Amazon | 1 | $31.57 |
3 | Battery Charger | From Amazon | 1 | $17.50 |
4 | Bluetooth Module | From Sparkfun | 1 | $24.95 |
5 | Electric Door Strike | From Amazon | 3 | $72 |
6 | PCB | From PCBWay | 5 | $13 |
7 | PIR Motion Sensor | From Amazon | 1 | $9.95 |
8 | Relays(1 Channel DC 5v relay) | From Amazon | 5 | $16.50 |
9 | Text-to-Speech | From Amazon | 1 | $69.45 |
Design & Implementation
System Block Diagram
Printed Circuit Board
Design
We have designed a custom Printed Circuit Board (PCB) to reduce hardware complexity. The dimensions of the PCB is 3.56 X 3.16 Inch to interface our SJOne board with Text-to-Speech, PIR Sensor, 1-Channel Relay and Electric Door Strike. It is worth designing the PCB as it reduced the hardware complexity and saved lot of wires. The PCB was designed and printed to house the circuit. To design our custom PCB board, we used Autodesk EAGLE PCB software version 8.2.0 which is a free software available online. EAGLE stands for, Easily Applicable Graphical Layout Editor which contains a schematic editor, for designing circuit diagrams. Before starting the PCB design, we downloaded all additional libraries from outside sources such as Sparkfun and Adafruit, to order required components easily.
The tool provides various connectors and devices which are commonly used in PCB’s. The tool is very easy to use. It is just a drag and drop and make connections to join different ports. In our PCB design, we used a lot of connectors with different pin configuration for various peripherals ranging from 3-pin to 20-pin connectors.
Eagle PCB Design Tool
The PCB layout editor allows back annotation to the schematic and auto-routing to automatically connect traces based on the connections defined in the schematic. The layout of the devices and interconnections on the board showcases both the top and bottom layers. The blue lines indicate the connection made from the bottom and red lines from the top. We have used through holes to avoid shorting the pin connections.
We planned the design and positioned the components to ease the accessibility of the pins and ports. We designed a custom 3.56x3.16 inch PCB to integrate different modules together along with the SJOne board. In order to minimize noise, a power copper layer as well as a ground copper layer were added to the top and back of the board. This cleaned up the wiring a lot, since every component contained these wires.
After the schematic and board files were completed, we chose PCB fab company called PCB Way since they deliver the PCBs very fast and it is also cost effective. This company is known for reliability, and quick turn around time. In addition to this, their website is very user friendly and designed for hobbyist. We submitted gerber files along with .sch and .brd files. We chose FR-4 grade printed circuit boards (PCB) because they are flame-resistant. FR-4 is a composite material composed of woven fiberglass cloth with an epoxy resin binder. Our design went through the design checking process and when approved, they were manufactured. In total, the PCB took days from submission of payment to receiving the board. We also coordinated with other teams and ordered PCB together to share the shipping cost.
Video Demonstration
Connector List
Purpose | Device | Library | Package | Port/Pin Connected |
---|---|---|---|---|
SJSUone Board | CONN_20X2 | SparkFun-Connectors | 2X20 | |
Text To Speech | CONN_04 | SparkFun-Connectors | 1X04 | UART2 |
PIR Sensor | CONN_03 | SparkFun-Connectors | 1X03 | Port 2.0 |
Electric Door Strike | CONN_02 | SparkFun-Connectors | 1X02 | Port 2.1 |
PIR Motion Sensor
PIR (Passive Infrared )Motion sensor is an inexpensive, small sensor used to detect the human motion. The sensitivity or the range of the PIR sensor is 6 meters(or 20 feet) and works on a 3.3V input power supply. Once the device is powered, we have to wait 2-4 seconds to start using the device. The range of the sensor is 2 meters.
The sensor in a motion detector is actually split in two halves. The reason for that is that we are looking to detect motion (change) not average IR levels. The two halves are wired up so that they cancel each other out. If one half sees more or less IR radiation than the other, the output will swing high or low.
Hardware Design
A passive infrared sensor is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. PIR uses 3 pins for its operation, VCC, GND and the output pin. The output pin is connected to GPIO of one the PCB. When the PIR detects any motion within its range it gives logic high which is then fed to the microcontroler. When there is no movement in the range of PIR it will output as logic 0. There are two potentiometer on the PIR sensor board which controls the sensitivity and time duration. By adjusting the sensitivity knob we can increase or decrease the range of the PIR sensor. Timing knob is used to control the time duration for which the the potentiometer will output the pulse as high or low when detected.
Software Design
The decisions are based upon the voltage received by the output of the PIR sensor. Initially we set the GPIO pin as the input and we pull down the the GPIO pin in order to avoid any error on the start of the circuit. The GPIO pin then checks for the input voltage its receives from the sensor. If it receives a logic high on the pin it means that the motion is detected.
Below is the code snippet for initializing the PIR motion sensor.
GPIO motion(P2_0); /* Use P2.0 as General Purpose Input/Output (GPIO) */
motion.setAsInput();
motion.enableDown();
The below code snippet is for reading the voltage at the GPIO pin.
if (motion.read())
{
puts("Object detected");
}
else
{
puts("Object not detected");
}
3D Printing for PIR Mount
The PIR Motion Sensor is very sensitive and a small movement in the senor will create lot of noise. So, we decided to use 3D printed case to mount the PIR Motion sensor in order to:
- Avoid noise
- Provide a fixed position to the sensor
We have used a LulzBot® TAZ at SJSU 3D Printing, MLK Library. This is a versatile, high-performance desktop 3D printer for industrial users that respects our freedom to create. We have used ABS (Acrylonitrile Butadiene Styrene) filament, which is an oil-based plastic. This is a strong, sturdy material filament which is one of the most popular 3D printing materials and easy to print. It's a durable plastic that can be used for prototypes or functional end use for 3D printed parts. The filament material has a higher melting point and higher yield strength.
Software:
Cura creates a seamless integration between hardware, software and materials for the best 3D printing experience around.
- Novices can start printing right away
- Cura supports STL, 3MF and OBJ file formats
- It’s open source and completely free
We used Cura software to determine how long our file will take to print prior to requesting time.
The software estimated around 1 hour. We have to export a file in either a STL, 3MF or OBJ file format so Cura can understand it.
Printing size: Maximum printing size for the printer is 152 x 152 x 203 mm (6 x 6 x 8 in) and layers must be at least 0.1 mm thick (0.020 in). We built our object in millimeters prior to submitting our request. The dimensions of the model we designed is 56.17mm X 70.92mm X 16mm.
Image Format and multiple parts: We exported our model as a stereo lithography file, with an STL extension (.stl).
Colors: Black, Blue, Purple, Red, Silver, Yellow, Orange, Green, and White are available. We went ahead with Red.
Supports and Raft: Supporting structures are sometimes needed if the design includes a section that overhangs from the base. Raft is another means of support for the 3d print object; it is be added to the design to help it adhere to the printer bed. We added support structures to support the gap in the 3D model. We added brim as a base for the 3D model. These are light extra structures which have mesh structure which can be removed after printing.
Electric Door Strike
The electric door strike being used in this project is of the type "fail-secure". This means that when there is no power being supplied to the strike, it remains locked. When a DC power supply of 7V - 12V is given, the strike unlocks, which can be detected by the characteristic clicking sound it makes.
The 3.3V supplied by our SJOne board is not sufficient for operation of the strike, which needs 12V. We powered the door lock using Battery. In order to control electric strike operation using SJOne board, it is interfaced using GPIO. GPIO is input to an active low relay which acts like a switch.A Electric Door strike unlocks when GPIO pin outputs low otherwise it gets locked. We have used a 1-Channel relay to control the Electric Door Strike from GPIO.
One Channel Relay
The 1-Channel relay is active low circuit and the A and B are internally connected by default(NC). When a input of logic 1 is applied from GPIO to the relay, since the relay is active low, there will be no connection between B and C(NO). The circuit is not complete and so the Electric Door Strike will be locked. On the other hand, when a logic 0 is applied as Input to relay from GPIO, the B and C will be connected which completes the circuit. Hence the Electric Door Strike can be unlocked when the logic 0 is applied.
We need a battery, 1-Channel Relay and SJOne board to complete the Electric Door Strike circuit.
Hardware Design
Software Design
Code Snippet:
GPIO doorStrike (P2_1); // Port 2 Pin 1
buzzer.setAsOutput(); //Enable the pin as output on GPIO
doorStrike.setHigh(); // Locking the Door Strike
Mobile App with Bluetooth Interface
The mobile application is used to control the various locks in our project. The Android mobile application is communicated with SJOne board over bluetooth using the UART communication protocol. The range of the bluetooth is 20 meters and it delivers at a speed of 115200 bits per second.
Bluetooth:
RN42XV is built around Microchip's RN42 low power Bluetooth module. Some features of this module are as follows
- Based on the popular 2 x 10 (2mm) socket footprint.
- Voltage range: (3-3.6)Volts
- Current range: 26 μA sleep, 3 mA connected, 30 mA transmit.
- UART data connection interface.
- Sustained data rates: 240 Kbps (slave), 300 Kbps (master)
- Transmission range up to 60 feet (20 m) distance, +4 dBm output transmitter, -80 dBm typical receive sensitivity.
- FHSS/GFSK modulation, 79 channels at 1-MHz intervals.
The pins of this module are perfectly compatible with the pins of the SJOne board such that it can be directly fixed on the board. The bluetooth module is interfaced with SJOne using UART3. When a connection is established, it is possible to send and receive messages via bluetooth between the Android App and SJOne board.
The interface between Bluetooth module and controller is as shown in fig:
Android:
The android app was built using Android Studio using the Java programming language. Multiple activities corresponding to the different screens of the app were created. Bluetooth was implemented as a background service which allowed us to transmit the data across multiple screens of the app. The service also needs to be added in the Android Manifest xml.
The interface between Bluetooth controller and Android phone is as shown in fig:
The following pictures are the sequential screens developed on our Android application:
Software Design
Code snippet on how to create a bluetooth service.
public class BluetoothService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//TODO do something useful
return Service.START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
//TODO for communication return IBinder implementation
return null;
}
}
Video Demonstration
Nordic Wireless
We have used Nordic Wireless communication to unlock/lock the Door 1 and Door 2 from the Master Lock. Master lock communicate with the Slave locks using onboard Nordic wireless IC. The mesh network drivers were used to interface with the Nordic IC. The Nordic nRF24L01+ is a highly integrated, ultra low power 2Mbps RF transceiver IC for the 2.4GHz ISM (Industrial, Scientific and Medical) band. The Nordic nRF24L01+ integrates a complete 2.4GHz RF transceiver, RF synthesizer, and baseband logic. We had to attach a RP-SMA Connector antenna to communicate between the multiple nodes. Nordic wireless can be used in multiple applications such as smart homes, games, consumer electronics and PC peripherals. We made use of Preet’s Low Powered Mesh Network stack.
Each packet is sent via an existing route, and if route has changed, a new route is automatically discovered using a special retry packet. Each node's ACK contains some meta-data about the node itself. This data includes information about its routing table, and other statistic. Duplicate packets are absorbed but an ACK is still replied if it's a duplicate, but a retry packet. An ACK packet or a response to an ACK all use retries; even the repeating nodes participate to make sure the packet is delivered. The minimum payload is 9 bytes, of which, 8 bytes will be the mesh header overhead. The higher the payload, the higher the efficiency of the network. The eight bytes of payload header contains the network source and destination information, along with packet type and hop count information.
For example, if the payload size is 32 bytes, then 8 bytes are used by the network header and 24 bytes are free to be used for transmitting the data.
The mesh_packet_t is a structure that is used to transmit the data to understand the data of the wireless packet. It has 4 struct variables.
- nwk : Packet network address
- mac : packet physical address
- info:Packet header
- Data:uint8_t type of data that is sent..
In this example, a commander sends an "Application Ack" packet, meaning that the destination will have to manually send an acknowledge packet back. In other words, instead of auto-acknowledge, we send the ACK back with the requested data. Furthermore, we show you how data variables can be exchanged between two boards. A wireless Tx task was created which was used to handle the wireless Nordic transmissions.
Hardware Design
Software Design
Here are some of the Nordic wireless API we used for our project.
1. This function is responsible for forming the packet wherein the address of the packet, type of mesh protocol used, the number of hops, number of data which will be sent, the actual data and their respectives size if sent.
wireless_form_pkt(&pkt2,addr2,mesh_pkt_ack,hops2,1,&var12,sizeof(var12));
2. The function sends the data packet to the particular node which is identified by the addr[noOfNodes] parameter. Upon receiving the data packet the node sends the acknowledgement back to the sending node which is stored in mesh_pkt_ack_app. The parameter hops give the distance between the two nodes
wireless_send_formed_pkt(&pkt2);
3. This function returns true if the data is received.
wireless_get_rx_pkt(&pkt,100)
4. This function is responsible for decoding the packet wherein the address of the packet, the number of hops, number of data which will be sent, the actual data and their respective size will be received.
wireless_deform_pkt(&pkt,2,&var1,sizeof(var1),&var2,sizeof(var2));
This function is responsible for sending the formed packet to all three slave nodes.
Code samples:
Transmit packet:
wireless_form_pkt(&pkt,addr,mesh_pkt_ack,hops,2,&var1,sizeof(var1),&var2,sizeof(var2));
wireless_send_formed_pkt(&pkt);
if(wireless_get_ack_pkt(&pkt,1000))
{
u0_dbg_printf("Got ack\n");
}
Receive packet:
if(wireless_get_rx_pkt(&pkt,100))
{
wireless_deform_pkt(&pkt,2,&var1,sizeof(var1),&var2,sizeof(var2));
u0_dbg_printf("%c\n",var1);
u0_dbg_printf("%f\n",var2);
}
Text-to-Speech
Emic 2 Text-to-Speech module converts the digital text to natural sounding speech. It uses UART to communication with the SJOne board. The Text-to-Speech (TTS) module is connected to the UART2 on the SJOne board. We can pick any voice from the 9 different voices and the volume can also be changed using the various commands. The in-built 3.5mm jack is used to connect the TTS to any speaker/earphones.
The key features are mentioned below:
- High-quality speech synthesis for English and Spanish languages
- Nine pre-defined voice styles comprising male, female, and child
- Dynamic control of speech and voice characteristics, including pitch, speaking rate, and word emphasis
- Industry-standard DECtalk text-to-speech synthesizer engine (5.0.E1)
Hardware Design
The Text-to-Speech (TTS) module is interfaced on the SJOne board using UART 2. The power requirements for the TTS is 5 VDC and 46-220 mA active depending on speech parameters and output load. The communication is Asynchronous 9600 bps serial and the operating temperature is -20 to +70 °C (-4 to +158 °F). The commands are used to pick one from the available 9 tones and there are certain commands used to control the volume and speed of the Speech.
Software Design
Commands:
- Sx Convert text-to-speech: x = message (1023 characters maximum)
- Dx Play demonstration message: x = 0 (Speaking), 1 (Singing), 2 (Spanish)
- X Stop playback (while message is playing)
- Z Pause/un-pause playback (while message is playing)
- Nx Select voice: x = 0 to 8
- Vx Set audio volume (dB): x = -48 to 18
- Wx Set speaking rate (words/minute): x = 75 to 600
- Lx Select language: x = 0 (US English), 1 (Castilian Spanish), 2 (Latin Spanish)
- Px Select parser: x = 0 (DECtalk), 1 (Epson)
- R Revert to default text-to-speech settings
- C Print current text-to-speech settings
- I Print version information
- H Print list of available commands
Text-to-Speech code snippet:
Uart2 &u2=Uart2::getInstance();
ttsTask (uint8_t priority) : scheduler_task("ttsTask", 2048, priority)
{
}
bool init(void)
{
u2.init(9600,200,200);
u2.putline("V18", portMAX_DELAY); // volume control
return true;
}
bool run(void *p)
{
u2.putline("SHello", portMAX_DELAY);
//In the Sx command, S is to get the speech output and x refers to the data string, Text-to-Speech will say 'Hello' in this case
return true;
}
Video Demonstration
Testing & Technical Challenges
Issue #1
The current was not enough from the SJOne board to unlock the Electric Door Strike. We initially decided to use a N-MOSFET as a switch to control the Electric Door Strike from GPIO pin but the current is not enough to switch the N-MOSFET. So, We have used 1-Channel relay to supply proper current.
Issue #2
The first issue that we faced with Nordic Wireless was buying the RP-SMA connector which needs to be attached to the SJ One board. The RP stands for Reverse Polarity. The below diagram clears any doubts regarding the connectors. The RP-SMA Female Antenna were difficult to obtain.
Issue #3
In Nordic Wireless, the channel number needs to constant if you wish to communicate between the multiple nodes in the same network, meanwhile each node in the network needs to have a unique node address. These parameters can be changed in the sys_config.h file. This file provides the configurable parameters of the project.
Issue #4
The Android app requires us to create a RF Communication and a Bluetooth socket. We set up the bluetooth connection on the UI Main thread. While it does serve the purpose of transferring data in the current screen of the application, it is not feasible to transfer data across multiple screens of the mobile application. It is generally advisable to create any network related tasks on a separate thread. Hence we implemented the Bluetooth as a background service. This enabled us to transmit data via bluetooth across multiple screens of the mobile application.
Issue #5
Faced lot of issues while parsing the data between the activity and service of the app.Data needs to be transmitted from the activity and service with the help of intents along with the putExtra() method.
Issue #6
For some strange reason, when we first printed the 3D model, the model was printed without gap which is required to keep the sensor inside. We then worked with the Library 3D printing team and simulated the 3D printing process which showed some issues with the printing process.
We simulated the printing process with different axis by rotating the model in CURA software. We found through simulation that upside down axis is printed with a gap to house the sensor, so we went ahead with printing it. We succeeded the Third time!
Conclusion
This project was so much fun to work on. The project has increased our knowledge in both hardware and software know-how. We have interfaced PIR sensor, Text-to-Speech module and designed a mobile application to communicate over bluetooth. We got hands-on experience with the UART and Wireless communication. This project has provided an opportunity to delegate and work in a team. We defined our own objectives, overcame the challenges and successfully completed the project.
Project Video
Module Specific Videos:
CMPE244 S17 LoganText to Speech Demo
Project Source Code
References
Acknowledgement
We would like to thank Preet for the guidance and the support. The learnings in the class has helped us in the successful implementation of this project.
We are very fortunate that 3D printing facility is available for free for all SJSU students, faculty, and staff at MLK Library. We are grateful to the 3D printing team and Computer Services Center team for helping us and resolving issues in printing.