Difference between revisions of "S17: Logan"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Hardware Design)
(Hardware Design)
 
(300 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=== Grading Criteria ===
+
== Abstract ==
<font color="green">
 
*  How well is Software & Hardware Design described?
 
*  How well can this report be used to reproduce this project?
 
*  Code Quality
 
*  Overall Report Quality:
 
**  Software Block Diagrams
 
**  Hardware Block Diagrams
 
**:  Schematic Quality
 
**  Quality of technical challenges and solutions adopted.
 
</font>
 
 
 
== Project Title ==
 
<span style="font-size:180%"> '''Logan The Smart Lock'''  </span>
 
  
== 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.
A staggering 1.4 billion smartphones were sold in 2015. An average consumer checks his or her smartphone 46 times a day, and in the US, people do this a collective 8 billion times every 24 hours. Most people at some point lose or forget to bring their key. Our Smart Home Lock system provides an alternate convenient way of access control on a user's smart phone. Smart Home Lock can simplify life and increase home security. Smart Home Lock provides a mechanism to lock and unlock your door with your Smart Phone, using Bluetooth communication with password protection. The door locks/unlocks automatically when the correct password is entered on the Mobile App and the motion sensor senses the motion when a person approaching from the inside towards the exit in order to lock the door to provide security. 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 users at every step.
 
  
 
== Objectives & Introduction ==
 
== Objectives & Introduction ==
Line 22: Line 8:
 
*  Design of Printed Circuit Board (PCB) to simplify the hardware system design  
 
*  Design of Printed Circuit Board (PCB) to simplify the hardware system design  
 
*  Combination of PIR Motion sensor and Mobile App to increase security
 
*  Combination of PIR Motion sensor and Mobile App to increase security
*  Accessing the doors using the Nordic Wireless
+
*  Accessing the other locks using the Nordic Wireless
 
*  Text-to-Speech to guide the User at every step
 
*  Text-to-Speech to guide the User at every step
  
=== Team Members ===
+
== Team Members & Responsibilities ==  
 +
[[File:CMPE244_S17_Logan_Team_Logan.PNG|right|300px|thumb|Team Logan]]
 +
 
 
* [http://linkedin.com/in/sreeharshagorantla Harsha Gorantla]<br>
 
* [http://linkedin.com/in/sreeharshagorantla Harsha Gorantla]<br>
 +
** Text-to-Speech Module, PCB Design and Complete System Algorithm
 +
 
* [https://linkedin.com/in/krishankmehta Krishank Mehta]<br>
 
* [https://linkedin.com/in/krishankmehta Krishank Mehta]<br>
 +
** Hardware Design and assembling, Software Flow, PCB design, PIR sensor and Door Strike
 +
 
* [https://linkedin.com/in/aithal-prashant Prashant Aithal]<br>
 
* [https://linkedin.com/in/aithal-prashant Prashant Aithal]<br>
 +
** Bluetooth, Mobile App, PCB Design and Nordic Wireless Communication
 +
 
* [https://linkedin.com/in/narayanshruthi Shruthi Narayan]<br>
 
* [https://linkedin.com/in/narayanshruthi Shruthi Narayan]<br>
 +
**PCB design, 3D Printing, Nordic Wireless Communication, Bluetooth and Testing
  
=== Roles & Responsibilities ===
 
* [http://linkedin.com/in/sreeharshagorantla Harsha Gorantla]<br>
 
** Text-to-Speech Module, PCB Design and Complete System Algorithm
 
* [https://linkedin.com/in/aithal-prashant Prashant Aithal]<br>
 
** Mobile App, Complete System Algorithm and Nordic Wireless Communication
 
* [https://linkedin.com/in/krishankmehta Krishank Mehta]<br>
 
** Hardware Design and assembling, PIR sensor and Door Strike
 
* [https://linkedin.com/in/narayanshruthi Shruthi Narayan]<br>
 
** LCD, Bluetooth and Testing
 
  
 
== Schedule ==
 
== Schedule ==
Show a simple table or figures that show your scheduled as planned before you started working on the project.  Then in another table column, write down the actual schedule so that readers can see the planned vs. actual goals.  The point of the schedule is for readers to assess how to pace themselves if they are doing a similar project.
+
 
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 81: Line 67:
 
|04/11/2017
 
|04/11/2017
 
|04/18/2017
 
|04/18/2017
|Integration and testing of Electric Door strike functionality <br> Design of PCB for bluetooth, PIR sensor, LCD, SJOne, door-strike related pins on the PCB
+
|Integration and testing of Electric Door strike functionality <br> Design of PCB for bluetooth, PIR sensor, SJOne, door-strike related pins on the PCB
 
|Completed
 
|Completed
 
|04/18/2017
 
|04/18/2017
Line 113: Line 99:
 
|05/07/2017
 
|05/07/2017
 
|05/14/2017
 
|05/14/2017
|Integration of the whole system<br>Debugging and testing of the whole system.
+
|Integration of the whole system<br>Debugging and testing of the whole system<br> Report preparation.
 
|Completed
 
|Completed
 
|05/14/2017
 
|05/14/2017
Line 122: Line 108:
 
|05/21/2017
 
|05/21/2017
 
|Final testing and fine tuning<br> Report preparation.
 
|Final testing and fine tuning<br> Report preparation.
|In Progress
+
|Completed
 
|05/21/2017
 
|05/21/2017
 
|}
 
|}
Line 149: Line 135:
 
|-
 
|-
 
! scope="row"| 3
 
! scope="row"| 3
| [https://www.amazon.com/gp/product/B003MXMJX8/ref=oh_aui_detailpage_o04_s01?ie=UTF8&psc=1 Battery Charger]
+
| [https://www.amazon.com/Tenergy-Smart-Universal-Charger-Battery/dp/B0061O9GYU/ref=sr_1_fkmr0_1?ie=UTF8&qid=1495719238&sr=8-1-fkmr0&keywords=Tenergy+Universal+Smart+6V+-+12V+Charger+for+NiMH%2FNiCd+Battery+Packs+%281025%29 Battery Charger]
 
| From Amazon
 
| From Amazon
 
| 1
 
| 1
Line 161: Line 147:
 
|-
 
|-
 
! scope="row"| 5
 
! scope="row"| 5
| [http://www.amazon.com/Qunqi-Controller-Module-Stepper-Arduino/dp/B014KMHSW6?ie=UTF8&psc=1&redirect=true&ref_=oh_aui_detailpage_o00_s00 Electric Door Strike]
+
| [https://www.amazon.com/gp/product/B00V45GWTI/ref=oh_aui_detailpage_o01_s01?ie=UTF8&psc=1 Electric Door Strike]
 
| From Amazon
 
| From Amazon
 
| 3
 
| 3
Line 167: Line 153:
 
|-
 
|-
 
! scope="row"| 6
 
! scope="row"| 6
| [https://www.digikey.com/en/product-highlight/4/4d-systems/ulcd-32ptu-display-module LCD]
+
| [https://www.pcbway.com PCB]
| From Digikey
+
| From PCBWay
| 1
 
| $80
 
|-
 
! scope="row"| 7
 
| [PCB]
 
| From ??
 
 
| 5
 
| 5
 
| $13
 
| $13
 
|-
 
|-
! scope="row"| 8
+
! scope="row"| 7
 
| [https://www.amazon.com/gp/product/B00JOZTAC6/ref=oh_aui_detailpage_o05_s00?ie=UTF8&psc=1 PIR Motion Sensor]
 
| [https://www.amazon.com/gp/product/B00JOZTAC6/ref=oh_aui_detailpage_o05_s00?ie=UTF8&psc=1 PIR Motion Sensor]
 
| From Amazon
 
| From Amazon
Line 184: Line 164:
 
| $9.95
 
| $9.95
 
|-
 
|-
! scope="row"| 9
+
! scope="row"| 8
| [https://www.amazon.com/gp/product/B00KTEN3TM/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1 Relays(4 Channel DC 5v relay)]
+
| [https://www.amazon.com/gp/product/B00KTEN3TM/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1 Relays(1 Channel DC 5v relay)]
 
| From Amazon
 
| From Amazon
| 3
+
| 5
| $21
+
| $16.50
 
|-
 
|-
! scope="row"| 10
+
! scope="row"| 9
 
| [https://www.amazon.com/gp/product/B01N6QB5VC/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1 Text-to-Speech]
 
| [https://www.amazon.com/gp/product/B01N6QB5VC/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1 Text-to-Speech]
 
| From Amazon
 
| From Amazon
 
| 1
 
| 1
 
| $69.45
 
| $69.45
|-
 
! scope="row"| 11
 
| [ Wires]
 
| From Amazon
 
| 1
 
| $3.95
 
 
|-
 
|-
 
|}
 
|}
Line 207: Line 181:
  
 
===System Block Diagram===
 
===System Block Diagram===
 +
 +
[[File:CMPE244_S17_Logan_Locker_Block_Diagram.png|center|750px|thumb|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.
 +
 +
 +
[[File:CMPE244 S17_Logan_PCB_Design.png|center|500px|thumb|PCB Design]]
 +
 +
==== 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.
 +
 +
 +
[[File:CMPE244 S17_Logan_PCB_Schematic.png|center|700px|thumb|PCB Schematic]]
 +
 +
 +
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.
 +
 +
 +
[[File:CMPE244 S17_Logan_PCB_Front.png|center|550px|thumb|PCB Front]]
 +
 +
 +
 +
==== Video Demonstration ====
 +
 +
 +
[https://youtu.be/aqmqXs8FgXM CMPE244 S17 Logan PCB Demo]
 +
 +
==== Connector List ====
 +
 +
 +
{| class="wikitable"
 +
|-
 +
! scope="col"| Purpose
 +
! scope="col"| Device
 +
! scope="col"| Library
 +
! scope="col"| Package
 +
! scope="col"| Port/Pin Connected
 +
|-
 +
|-
 +
! scope="row"| SJSUone Board
 +
| CONN_20X2
 +
| SparkFun-Connectors
 +
| 2X20
 +
|
 +
|-
 +
|-
 +
! scope="row"| Text To Speech
 +
| CONN_04
 +
| SparkFun-Connectors
 +
| 1X04
 +
| UART2
 +
|-
 +
|-
 +
! scope="row"| PIR Sensor
 +
| CONN_03
 +
| SparkFun-Connectors
 +
| 1X03
 +
| Port 2.0
 +
|-
 +
|-
 +
! scope="row"| Electric Door Strike
 +
| CONN_02
 +
| SparkFun-Connectors
 +
| 1X02
 +
| Port 2.1
 +
|-
 +
|-
 +
|}
  
 
=== PIR Motion Sensor ===  
 
=== 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 ====
 
==== Hardware Design ====
Discuss your hardware design here. Show detailed schematics, and the interface here.
+
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.
 +
 
 +
 
 +
[[File:CMPE244 S17_Logan_PIR_Motion_Sensor_Front.png|left|350px|thumb|PIR Motion Sensor Front]]
 +
[[File:CMPE244 S17_Logan_PIR_Motion_Sensor_Back.png|center|350px|thumb|PIR Motion Sensor Back]]
 +
 
 +
 
 +
{|
 +
[[File:CMPE244 S17_Logan_PIR_Motion_Sensor.gif|left|500px|thumb|PIR Motion Sensor]]
 +
[[File:CMPE244 S17_Logan_PIR_Motion_Sensor_schematic.PNG|center|500px|thumb|PIR Motion Sensor Schematic]]
 +
|}
  
 
==== Software Design ====
 
==== 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. <br>
 +
 +
Below is the code snippet for initializing the PIR motion sensor. <br>
 +
 +
<syntaxhighlight lang="C">
 +
 +
GPIO motion(P2_0);  /* Use P2.0 as General Purpose Input/Output (GPIO) */
 +
 +
motion.setAsInput();
 +
motion.enableDown();
 +
 +
</syntaxhighlight>
 +
 +
 +
The below code snippet is for reading the voltage at the GPIO pin.
 +
 +
<syntaxhighlight lang="C">
 +
 +
if (motion.read())
 +
    {
 +
      puts("Object detected");
 +
    }
 +
    else
 +
    {
 +
    puts("Object not detected");
 +
    }
 +
 +
</syntaxhighlight>
 +
 +
==== 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
 +
 +
 +
 +
[[File:CMPE244 S17_Logan_3D_Mount1.PNG|center|500px|thumb|3D Printing (A)]]
 +
 +
 +
[[File:CMPE244 S17_Logan_3D_Mount2.PNG|center|500px|thumb|3D Printing (B)]]
 +
 +
 +
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.
 +
 +
 +
[[File:CMPE244 S17_Logan PIR Motion 3D Mount.PNG|center|500px|thumb|PIR Sensor 3D Mount]]
  
 
=== Electric Door Strike ===  
 
=== 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
 +
 +
 +
 +
[[File:CMPE244 S17_Logan_One_Channel_Relay.png|left|600px|thumb|1-Channel Relay]]
 +
 +
[[File:CMPE244_S17_Logan_1_Channel_Relay.gif|center|600px|thumb|1-Channel Relay GIF]]
 +
 +
 +
 +
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 ====
 
==== Hardware Design ====
Discuss your hardware design here.  Show detailed schematics, and the interface here.
+
 
 +
 
 +
 
 +
[[File:CMPE244 S17_Logan_Electric_Door_Strike.png|center|600px|thumb|Electric Door Strike]]
  
 
==== Software Design ====
 
==== Software Design ====
  
=== LCD ===  
+
Code Snippet:
 +
 
 +
<syntaxhighlight lang="C">
 +
 
 +
GPIO doorStrike (P2_1); // Port 2 Pin 1
 +
 
 +
buzzer.setAsOutput(); //Enable the pin as output on GPIO
 +
doorStrike.setHigh(); // Locking the Door Strike
 +
 
 +
</syntaxhighlight>
 +
 
 +
=== 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:
 +
 
 +
 
 +
[[File:CMPE244_S17_Logan_Bluetooth.gif|center|500px|thumb|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:
 +
 
 +
[[File:CMPE244_S17_Logan_Bluetooth_Block_Diagram.PNG |center|500px|thumb|Bluetooth Schematic]]
 +
 
 +
 
 +
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:
 +
 
 +
 
 +
[[File:CMPE244_S17_Logan_Android_Block_Diagram.PNG |center|500px|thumb|Android Block Diagram]]
 +
 
 +
The following pictures are the sequential screens developed on our Android application:
 +
 
 +
 
  
==== Hardware Design ====
+
 
Discuss your hardware design here. Show detailed schematics, and the interface here.
+
{|
 +
|[[File:CMPE244 S17 Logan Screen1.PNG|left|220px|thumb|Android App Screen 1]]
 +
|[[File:CMPE244 S17_Logan_App2.png|left|220px|thumb|Android App Screen 2]]
 +
|[[File:CMPE244 S17_Logan_App3.png|left|220px|thumb|Android App Screen 3]]
 +
|[[File:CMPE244 S17_Logan_App7.png|center|220px|thumb|Android App Screen 4]]
 +
|[[File:CMPE244 S17_Logan_App1.png|left|220px|thumb|Android App Screen 5]]
 +
|[[File:CMPE244 S17_Logan_App8.png|right|220px|thumb|Android App Screen 6]]
 +
|[[File:CMPE244 S17_Logan_lastscreen.PNG|right|220px|thumb|Android App Screen 7]]
 +
|}
  
 
==== Software Design ====
 
==== Software Design ====
  
=== Mobile App ===
+
Code snippet on how to create a bluetooth service.
 +
 
 +
<syntaxhighlight lang="C">
 +
 
 +
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;
 +
  }
 +
}
  
==== Hardware Design ====
+
</syntaxhighlight>
Discuss your hardware design here.  Show detailed schematics, and the interface here.
+
 
 +
 
 +
==== Video Demonstration ====
  
==== Software Design ====
+
[https://youtu.be/_g4aXTIMUgQ CMPE244 S17 Logan Android App Demo]
  
 
=== Nordic Wireless===  
 
=== 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 ====
 
==== Hardware Design ====
Discuss your hardware design here.  Show detailed schematics, and the interface here.
+
 
 +
 
 +
[[File:CMPE244 S17_Logan_Nordic_Wireless.png|center|600px|thumb|Nordic Wireless]]
  
 
==== Software Design ====
 
==== Software Design ====
 +
 +
 +
[[File:CMPE244_S17_Logan_Nordic_Wireless_Flowchart.PNG|center|750px|thumb|Nordic Wireless Flow-Chart]]
 +
 +
 +
 +
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:
 +
 +
<syntaxhighlight lang="C">
 +
 +
        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");
 +
}
 +
 +
</syntaxhighlight>
 +
 +
Receive packet:
 +
 +
<syntaxhighlight lang="C">
 +
       
 +
      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);
 +
}
 +
 +
</syntaxhighlight>
 +
  
 
=== Text-to-Speech ===
 
=== Text-to-Speech ===
Line 256: Line 561:
 
==== Hardware Design ====
 
==== Hardware Design ====
  
[[File:CMPE244_S17_Logan_Text-to-Speech_front.png|left|200px|thumb|Text to speech Front]]
+
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.
[[File:CMPE244_S17_Logan_Text-to-Speech.png|right|200px|thumb|Text to speech Back]]
+
 
 +
 
 +
[[File:CMPE244_S17_Logan_Text-to-Speech_front.png|left|250px|thumb|Text to speech Front]]
 +
[[File:CMPE244 S17_Logan_Text-to-Speech_circuit.png|250px|thumb|Text to speech Circuit]]
 +
[[File:CMPE244_S17_Logan_Text-to-Speech.png|center|250px|thumb|Text to speech Back]]
 +
 
 +
 
 +
[[File:CMPE244_S17_Logan_Text-to-Speech_schematic.png|center|600px|thumb|Text to speech schematic]]
  
 
==== Software Design ====
 
==== Software Design ====
Show your software design.  For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level.  Do not show the details of the code.  For example, do not show exact code, but you may show psuedo-code and fragments of code.  Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
 
  
=== Implementation ===
+
[[File:CMPE244_S17_Logan_Text_to_Speech_Flowchart.PNG|center|350px|thumb|Text to Speech Flow-Chart]]
This section includes implementation, but again, not the details, just the high level.  For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.
+
 
 +
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:
 +
 
 +
<syntaxhighlight lang="C">
 +
 
 +
    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;
 +
}
 +
 
 +
 
 +
</syntaxhighlight>
 +
 
 +
 
 +
==== Video Demonstration ====
 +
 
 +
[https://www.youtube.com/watch?v=AsH4mrEF1nk CMPE244 S17 Logan Text to Speech Demo]
  
 
== Testing & Technical Challenges ==
 
== Testing & Technical Challenges ==
Describe the challenges of your project.  What advise would you give yourself or someone else if your project can be started from scratch again?
 
Make a smooth transition to testing section and described what it took to test your project.
 
  
Include sub-sections that list out a problem and solution, such as:
 
  
 
=== Issue #1 ===
 
=== Issue #1 ===
  
The current was not enough from the SJOne board to unlock the Electric Door Strike. We have used 12V battery and relays to give sufficient current in order to enable the circuit.
+
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 ===
 
=== Issue #2 ===
  
Bluetooth Issue
+
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.
 +
 
 +
[[File:CMPE244_S17_Logan_Nordic_Wireless_Antenna.PNG|center|300px|thumb|Nordic Wireless Antenna]]
 +
 
 +
=== 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.
 +
 
 +
[[File:CMPE244_S17_Logan_PIR_3D_Printing_Error.PNG|center|300px|thumb|PIR Sensor 3D Error]]
 +
 
 +
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 ==
 
== Conclusion ==
Line 284: Line 661:
  
 
=== Project Video ===
 
=== Project Video ===
Upload a video of your project and post the link here.
+
 
 +
[https://youtu.be/eqU0VwsANek CMPE244 S17 Logan Final Video]
 +
 
 +
[https://www.youtube.com/watch?v=gsNh0wSq_tU&t=3s CMPE244 S17_Logan]
 +
 
 +
 
 +
Module Specific Videos:
 +
 
 +
 
 +
[https://www.youtube.com/watch?v=AsH4mrEF1nk CMPE244 S17 Logan Text to Speech Demo]
 +
 
 +
[https://youtu.be/aqmqXs8FgXM CMPE244 S17 Logan PCB Demo]
 +
 
 +
[https://youtu.be/_g4aXTIMUgQ CMPE244 S17 Logan Android App Demo]
  
 
=== Project Source Code ===
 
=== Project Source Code ===
*  [https://sourceforge.net/projects/sjsu/files/CmpE_S2016/ Sourceforge Source Code Link]
+
*  [https://drive.google.com/open?id=0B_UQPGsOP0bgZFRWWkFXcGw3TWs CMPE244 S17 Logan Source Code]
  
 
== References ==
 
== References ==
Line 293: Line 683:
  
 
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 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.
  
 
=== References Used ===
 
=== References Used ===
Line 298: Line 690:
 
* [http://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/RN42XV.pdf Bluetooth]
 
* [http://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/RN42XV.pdf Bluetooth]
 
* [https://cdn-learn.adafruit.com/downloads/pdf/pir-passive-infrared-proximity-motion-sensor.pdf PIR Motion Sensor]
 
* [https://cdn-learn.adafruit.com/downloads/pdf/pir-passive-infrared-proximity-motion-sensor.pdf PIR Motion Sensor]
* [Text-to-Speech]
+
* [https://www.parallax.com/sites/default/files/downloads/30016-Emic-2-Text-To-Speech-Documentation-v1.2.pdf Text-to-Speech]
* [Relay]
+
* [http://www.geeetech.com/wiki/index.php/One-Channel_Relay_module Relay]
 
+
* [https://developer.android.com/studio/intro/index.html Android Studio]
=== Appendix ===
+
* [http://developer.android.com/guide/topics/connectivity/bluetooth.html Bluetooth Connectivity]
You can list the references you used.
+
* [http://developer.android.com/guide/topics/manifest/manifest-intro.html Android Manifest]
 +
* [https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/how-pirs-work PIR]
 +
* [https://learn.sparkfun.com/tutorials/pcb-basics PCB Basics]
 +
* [https://learn.sparkfun.com/tutorials/how-to-read-a-schematicI PCB Eagle Schematic]
 +
* [https://learn.sparkfun.com/tutorials/how-to-install-and-setup-eagle Eagle PCB]
 +
* [https://learn.sparkfun.com/tutorials/using-eagle-board-layout Eagle Layout]
 +
* [http://libguides.sjsu.edu/3d 3D Printing]
 +
* [https://learn.sparkfun.com/tutorials/how-to-install-and-setup-eagle Setup Eagle]
 +
* [http://www.circuitsgallery.com/2012/09/working-of-relay-and-connection.html Relay]
 +
* [https://ultimaker.com/en/products/cura-software CURA]
 +
* [http://www.socialledge.com/sjsu/index.php?title=Low_Powered_Mesh_Network_stack Low Powered Mesh Network]
 +
* [http://www.socialledge.com/sjsu/index.php?title=Realtime_OS_on_Embedded_Systems RTOS]

Latest revision as of 03:18, 23 May 2018

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 & Responsibilities

Team Logan
  • 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
    • Bluetooth, Mobile App, PCB Design and Nordic Wireless Communication
  • Shruthi Narayan
    • PCB design, 3D Printing, Nordic Wireless Communication, 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

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.


PCB Design

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.


PCB Schematic


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.


PCB Front


Video Demonstration

CMPE244 S17 Logan PCB Demo

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.


PIR Motion Sensor Front
PIR Motion Sensor Back


PIR Motion Sensor
PIR Motion Sensor Schematic

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


3D Printing (A)


3D Printing (B)


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.


PIR Sensor 3D Mount

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


1-Channel Relay
1-Channel Relay GIF


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

Electric Door Strike

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:


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:

Bluetooth Schematic


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:


Android Block Diagram

The following pictures are the sequential screens developed on our Android application:



Android App Screen 1
Android App Screen 2
Android App Screen 3
Android App Screen 4
Android App Screen 5
Android App Screen 6
Android App Screen 7

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

CMPE244 S17 Logan Android App Demo

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

Nordic Wireless

Software Design

Nordic Wireless Flow-Chart


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.


Text to speech Front
Text to speech Circuit
Text to speech Back


Text to speech schematic

Software Design

Text to Speech Flow-Chart

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

CMPE244 S17 Logan Text to Speech Demo

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.

Nordic Wireless Antenna

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.

PIR Sensor 3D Error

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

CMPE244 S17 Logan Final Video

CMPE244 S17_Logan


Module Specific Videos:


CMPE244 S17 Logan Text to Speech Demo

CMPE244 S17 Logan PCB Demo

CMPE244 S17 Logan Android App 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.

References Used