Difference between revisions of "F16: Door Alarm System"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Schedule)
(References Used)
 
(75 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  
  
== Project Title ==
+
== Project Title: Door Alarm System ==
  
 +
== Abstract ==
 +
Our project would use a motion detector and light sensor on the SJOne board to control the output of a speaker. If the someone opens the door during daytime, the speaker would output a song as a welcome.  However, if the door opened at night where there’s no light, the speaker would output an alarm because there might be thieves coming in during midnight.
 +
 +
== Objectives & Introduction ==
 +
The objective of this project to create a realizable indoor anti-theft system. The system is able to detect the people's motion by using the motion sensor, and judge the current brightness by using the on-board light sensor.
 +
 +
In order to accomplish the objective, we need to the following things:
  
== Abstract ==
+
* Modified the Pulse-Width Modulation(PWM) source code to allow  the speaker to play a song.
Our project would use the acceleration sensor on the SJOne board to control the output of a speaker. If the someone opens the door during daytime the speaker would output “welcome”, if the door opened at night where there’s no light, the speaker would output an alarm because there might be thieves coming in during midnight.
 
  
 +
* Figure out how to amplify the sound signal.
  
== Objectives & Introduction ==
+
* Using the ADC code to receive the signal from motion sensor.   
Show list of your objectives.  This section includes the high level details of your projectYou can write about the various sensors or peripherals you used to get your project completed.
 
  
  
 
=== Team Members & Responsibilities ===
 
=== Team Members & Responsibilities ===
* Bowei Zhang
+
*<b>Bowei Zhang</b>
* Email: blueswebber@gmail.com
+
**  Program the speaker.
**  
+
** Design Hardware Schematic.
*  James Huang   
+
**  Programming.
Email: jameshuang415@yahoo.com
+
*Testing the hardware.
 +
 
 +
 
 +
*<b>James Huang</b> 
 +
**  Improve the playing song algorithm.
 +
**  Design the software schematic.
 +
** Programming.
 +
*Testing the software.
  
 
== 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.
+
The following table is our schedule for this project.
  
  
Line 30: Line 43:
 
! scope="col"| Date
 
! scope="col"| Date
 
! scope="col"| Task
 
! scope="col"| Task
! scope="col"| Actual
+
! scope="col"| Completion
 +
! scope="col"| Comment
 
|-
 
|-
 
! scope="row"| week1
 
! scope="row"| week1
| Oct31-Nov4
+
| Oct31 - Nov4
| Planning and ordering parts.
+
| Project Plan & ordering parts
| Incompleted. Haven't ordered the parts.
+
| Completed
 +
| Parts Ordered
 
|-
 
|-
 
! scope="row"| week2
 
! scope="row"| week2
| Nov7-Nov11
+
| Nov 7 - Nov11
| Design the Circuit. Ordered the parts.
+
| Circuit Design & Writing Software (part 1)
| Pending
+
| Completed
 +
| Finalizing the idea.
 
|-
 
|-
 
! scope="row"| week3
 
! scope="row"| week3
| Nov14-Nov18
+
| Nov14- Nov18
| Design the Circuit. Ordered the parts.
+
| Circuit Design & Writing Software (part 2)
| Code Development
+
| Incomplete
| Pending
+
| Speaker with low volume. Consider ordering Amplifier.
 
|-
 
|-
 
! scope="row"| week4
 
! scope="row"| week4
| Nov21-Nov25
+
| Nov21- Nov25
| Testing & complete report
+
| Finish Testing
| Pending
+
| In completed
 +
|  Motion Senor came with damage. Ordering new one.
 
|-
 
|-
 
! scope="row"| week5
 
! scope="row"| week5
| Nov27-Dec2
+
| Nov27- Dec2
| Contd Testing & complete report
+
| Project Report
| Pending
+
| Completed
 +
| Working on Report. Waiting for sensor.
 +
|-
 +
! scope="row"| week6
 +
| Dec 3 - Dec9
 +
| Cont. Testing & finish project report
 +
| Incomplete
 +
| Waiting for Motion sensor. Consider moving to plan B.
 +
|-
 +
! scope="row"| week7
 +
| Dec12- Dec16
 +
| Cont. Testing
 +
| Completed
 +
| Report finished. Testing sensor.
 +
|-
 +
! scope="row"| week8
 +
| Dec17- Dec19
 +
| Finish Report & Testing
 +
| Completed
 +
| Done
 
|}
 
|}
  
 
== Parts List & Cost ==
 
== Parts List & Cost ==
SJSUone Board
+
{| class="wikitable"
Speaker
+
|-
SD card
+
! scope="col"| Part Name
Couple LEDS
+
! scope="col"| Quantity
TBD
+
! scope="col"| Cost
 +
! scope="col"| Notes
 +
|-
 +
! scope="row"| SJone Board
 +
| 1
 +
| $80
 +
| SJone Board
 +
|-
 +
! scope="row"| Speaker module
 +
| 1
 +
| $2
 +
| Buzzer
 +
|-
 +
! scope="row"| LEDs
 +
| 4
 +
| <$1
 +
|
 +
|-
 +
! scope="row"| Motion Sensor
 +
|1
 +
|$15
 +
| Motion Detector
 +
|-
 +
! scope="row"| Signal Amplifier
 +
|1
 +
|$1
 +
| 2N3904
 +
|-
 +
|}
 +
 
 
== Design & Implementation ==
 
== Design & Implementation ==
The design section can go over your hardware and software design.  Organize this section using sub-sections that go over your design and implementation.
+
 
  
  
 
=== Hardware Design ===
 
=== Hardware Design ===
Discuss your hardware design here. Show detailed schematics, and the interface here.
+
 
 +
The following figure is the system level design of our project.  
 +
 
 +
[[File:System Level Design2.PNG|550px|thumb|left|Figure 1. System Level Design ]]
 +
 
 +
 
 +
 
  
  
 
=== Hardware Interface ===
 
=== Hardware Interface ===
In this section, you can describe how your hardware communicates, such as which BUSes used.  You can discuss your driver implementation here, such that the '''Software Design''' section is isolated to talk about high level workings rather than inner working of your project.
 
  
 +
<b>Pulse-Width Modulatio(PWM)</b>
 +
*As the Figure 1 showed,we connected the speaker with an 2N3904 Amplifier, and then connected it to the on- board PWM Pin (pin2.0)directly. When the speaker output condition is triggered, pin 2.0 will send a PWM signal to the amplifier and it will be amplified to allow the speaker output louder.
 +
 +
 +
<b>General Purpose Input/Output (GPIO)</b>
 +
*The General Purpose Input/Output(GPIO)Pin is used to control the LEDs. We also set the GPIO pin as an input pin to receive the signal come out from the motion sensor. The sensor will output logic "1" when it detects movement or output logic low if it doesn't. 
 +
 +
 +
<b>External Power Supply </b>
 +
*We power up the PIR Motion Sensor by using a 12V power supply which connected with a LM7805 Regulator to step down the voltage to 5V.
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
[[File:Speaker1.PNG|200px|thumb|right|Figure 3. Speaker Connection ]]
 +
[[File:sensor2.PNG|200px|thumb|left|Figure 2. Sensor Connection ]]
 +
 +
 +
 +
<b> Sensor Connection</b>
 +
 +
The left figure showed us the sensor circuit. The middle pin which is the trigger pin has been tied to the ADC, so the analog signal that send by the senor is able to transfer to the digital signal that the MCU is able to read.
 +
 +
 +
 +
<b> Speaker Connection</b>
 +
 +
The right figure showed us how to tie the Speaker. First, we use a 1k pull-up resister to prevent the current flows. Then we used the amplifier to amplify the PWM signal to make the song comes out of speaker is loud enough.
 +
 +
 +
[[File:SM.PNG|550px|thumb|right|Figure 4. State Machine ]]
  
 
=== 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 psuedocode and fragments of code.  Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
+
Figure 4 showed us the state machine of the project.  
  
 +
In our project, we used Real Time Operating System (RTOS) for this project. The software design consist of two tasks with different priority level. The low priority task would check for inputs of the motion sensors and if motion is detected from the sensor, the lower priority task would send data to the queue. The medium priority task would then receive the signals from the queue and generate sound for the speaker based on the value of the light sensor. If the brightness is pretty high, then it the micro-controller would output a song named "Jingle Bell", else micro-controller would output an alarm to the speaker because there maybe thieves inside the house.
  
 
=== Implementation ===
 
=== Implementation ===
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.
+
The first low priority task would check for the inputs of two motion sensors (This increases the accuracy of the detection). If both sensor sensed a motion in the first task, then it would send some data into the queue to indicate that motion is been detected. The medium priority task would wake up from sleep state because the queue is not empty anymore, this task would check the value on the light sensor to see how bright the room is. If the room is too dark (brightness <20), then there may be a thief inside the house, so an alarm frequency would be sent to the speaker pin. Else, if the value of brightness is pretty bright on the light sensor, just because it's christmas, the micro controller would generate a song called "Jingle Bell" just because it's christmas.
  
 +
== 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:
+
The biggest challenge we faced we deciding what to purchase for the project. In the first two week of the project, we purchased the speakers and thinking the onboard acceleration sensor would work like the way we want it to (sense motions), but it actually only works if the board is tilted. After the speaker came, we tested the speaker with our micro-controller, and yes there's sound coming out but the sound is very dim that we're barely able to hear. So we purchased some 2N3904 transistor and created a signal amplifying circuit and connected that to the speaker. Next, the first motion sensor that we bought online isn't turning off, we couldn't find out why so we bought 5 more motion sensor online just in case. If someone wants to start this project from scratch again, I would highly recommend doing enough research before making a purchase, because there's always not enough materials to work on the project if research are not well done.
  
  
=== My Issue #1 ===
+
=== My Issue #1: Speaker ===
Discuss the issue and resolution.
+
When we purchased the speaker, the sound wasn't loud enough so we need some device to amplify the signal. So, we spend some time to go to an electronic store to purchase some transistors 2N3904 to create an amplifying circuit and connect that to the speaker. Finally, the sound it generated was a lot louder than before. It would be a lot better to purchase the speaker and 2N3904 together, because a lot of time is being wasted in between because we thought the micro controller could create enough voltage to sound a speaker.
  
 +
=== My Issue #2: Motion Sensor ===
 +
The second part of our issue is the motion sensor, the first sensor that we bought is not turning off for some reason, in other words, it always senses motion even though nothing is moving in front of the sensor. Then, we were trying to think of a way to work around the box with other ideas, but none of them work. So we have to go online and buy 5 motion sensor because we don't want any defected parts to slow down our progress. The sensors that we bought finally worked, but sometimes it would give a false signal when there's no motion so I'm assuming it needs some time for the motion sensor to stabilize itself.
  
 
== Conclusion ==
 
== Conclusion ==
Conclude your project here. You can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this projectHow has this project increased your knowledge?
+
In conclusion, the project was successful completed. Through working on this project, we were able to understand the FreeRTos and Embedded Code deeper. During testing the project, we got many queue timing problem and priority issues. After we fixed those bugs by testing the program multiple times, we furthered our knowledge in the embedded system field. We also learned how to use the PIR motion, it took us a long time to make it work precisely. By doing this project, the lesson we have learned is to do enough research before you actually order the parts.We waste lots of money due to this reason.   
 +
 
  
  
 
=== Project Video ===
 
=== Project Video ===
 
Upload a video of your project and post the link here.
 
Upload a video of your project and post the link here.
 
+
*[https://www.youtube.com/watch?v=goAG0NiyZBs Indoor Alarm System Demonstration]
  
 
=== Project Source Code ===
 
=== Project Source Code ===
 
*  [https://sourceforge.net/projects/sjsu/files/CmpE_S2016/ Sourceforge Source Code Link]
 
*  [https://sourceforge.net/projects/sjsu/files/CmpE_S2016/ Sourceforge Source Code Link]
 
  
 
== References ==
 
== References ==
 
=== Acknowledgement ===
 
=== Acknowledgement ===
Any acknowledgement that you may wish to provide can be included here.
+
We would like to thank Mr. Preet and Professor Ozemek for teaching us all those knowledge about real-time embedded system design.
 
 
  
 
=== References Used ===
 
=== References Used ===
List any references used in project.
+
.
 
+
[http://www.socialledge.com/sjsu/index.php?title=Main_Page SocialEdge]
  
 
=== Appendix ===
 
=== Appendix ===
You can list the references you used.
+
*[http://www.nxp.com/documents/user_manual/UM10360.pdf LPC1758 Datasheet]

Latest revision as of 06:12, 21 December 2016



Project Title: Door Alarm System

Abstract

Our project would use a motion detector and light sensor on the SJOne board to control the output of a speaker. If the someone opens the door during daytime, the speaker would output a song as a welcome. However, if the door opened at night where there’s no light, the speaker would output an alarm because there might be thieves coming in during midnight.

Objectives & Introduction

The objective of this project to create a realizable indoor anti-theft system. The system is able to detect the people's motion by using the motion sensor, and judge the current brightness by using the on-board light sensor.

In order to accomplish the objective, we need to the following things:

  • Modified the Pulse-Width Modulation(PWM) source code to allow the speaker to play a song.
  • Figure out how to amplify the sound signal.
  • Using the ADC code to receive the signal from motion sensor.


Team Members & Responsibilities

  • Bowei Zhang
    • Program the speaker.
    • Design Hardware Schematic.
    • Programming.
    • Testing the hardware.


  • James Huang
    • Improve the playing song algorithm.
    • Design the software schematic.
    • Programming.
    • Testing the software.

Schedule

The following table is our schedule for this project.


Week# Date Task Completion Comment
week1 Oct31 - Nov4 Project Plan & ordering parts Completed Parts Ordered
week2 Nov 7 - Nov11 Circuit Design & Writing Software (part 1) Completed Finalizing the idea.
week3 Nov14- Nov18 Circuit Design & Writing Software (part 2) Incomplete Speaker with low volume. Consider ordering Amplifier.
week4 Nov21- Nov25 Finish Testing In completed Motion Senor came with damage. Ordering new one.
week5 Nov27- Dec2 Project Report Completed Working on Report. Waiting for sensor.
week6 Dec 3 - Dec9 Cont. Testing & finish project report Incomplete Waiting for Motion sensor. Consider moving to plan B.
week7 Dec12- Dec16 Cont. Testing Completed Report finished. Testing sensor.
week8 Dec17- Dec19 Finish Report & Testing Completed Done

Parts List & Cost

Part Name Quantity Cost Notes
SJone Board 1 $80 SJone Board
Speaker module 1 $2 Buzzer
LEDs 4 <$1
Motion Sensor 1 $15 Motion Detector
Signal Amplifier 1 $1 2N3904

Design & Implementation

Hardware Design

The following figure is the system level design of our project.

File:System Level Design2.PNG
Figure 1. System Level Design



Hardware Interface

Pulse-Width Modulatio(PWM)

  • As the Figure 1 showed,we connected the speaker with an 2N3904 Amplifier, and then connected it to the on- board PWM Pin (pin2.0)directly. When the speaker output condition is triggered, pin 2.0 will send a PWM signal to the amplifier and it will be amplified to allow the speaker output louder.


General Purpose Input/Output (GPIO)

  • The General Purpose Input/Output(GPIO)Pin is used to control the LEDs. We also set the GPIO pin as an input pin to receive the signal come out from the motion sensor. The sensor will output logic "1" when it detects movement or output logic low if it doesn't.


External Power Supply

  • We power up the PIR Motion Sensor by using a 12V power supply which connected with a LM7805 Regulator to step down the voltage to 5V.







File:Speaker1.PNG
Figure 3. Speaker Connection
File:Sensor2.PNG
Figure 2. Sensor Connection


Sensor Connection

The left figure showed us the sensor circuit. The middle pin which is the trigger pin has been tied to the ADC, so the analog signal that send by the senor is able to transfer to the digital signal that the MCU is able to read.


Speaker Connection

The right figure showed us how to tie the Speaker. First, we use a 1k pull-up resister to prevent the current flows. Then we used the amplifier to amplify the PWM signal to make the song comes out of speaker is loud enough.


File:SM.PNG
Figure 4. State Machine

Software Design

Figure 4 showed us the state machine of the project.

In our project, we used Real Time Operating System (RTOS) for this project. The software design consist of two tasks with different priority level. The low priority task would check for inputs of the motion sensors and if motion is detected from the sensor, the lower priority task would send data to the queue. The medium priority task would then receive the signals from the queue and generate sound for the speaker based on the value of the light sensor. If the brightness is pretty high, then it the micro-controller would output a song named "Jingle Bell", else micro-controller would output an alarm to the speaker because there maybe thieves inside the house.

Implementation

The first low priority task would check for the inputs of two motion sensors (This increases the accuracy of the detection). If both sensor sensed a motion in the first task, then it would send some data into the queue to indicate that motion is been detected. The medium priority task would wake up from sleep state because the queue is not empty anymore, this task would check the value on the light sensor to see how bright the room is. If the room is too dark (brightness <20), then there may be a thief inside the house, so an alarm frequency would be sent to the speaker pin. Else, if the value of brightness is pretty bright on the light sensor, just because it's christmas, the micro controller would generate a song called "Jingle Bell" just because it's christmas.

Testing & Technical Challenges

The biggest challenge we faced we deciding what to purchase for the project. In the first two week of the project, we purchased the speakers and thinking the onboard acceleration sensor would work like the way we want it to (sense motions), but it actually only works if the board is tilted. After the speaker came, we tested the speaker with our micro-controller, and yes there's sound coming out but the sound is very dim that we're barely able to hear. So we purchased some 2N3904 transistor and created a signal amplifying circuit and connected that to the speaker. Next, the first motion sensor that we bought online isn't turning off, we couldn't find out why so we bought 5 more motion sensor online just in case. If someone wants to start this project from scratch again, I would highly recommend doing enough research before making a purchase, because there's always not enough materials to work on the project if research are not well done.


My Issue #1: Speaker

When we purchased the speaker, the sound wasn't loud enough so we need some device to amplify the signal. So, we spend some time to go to an electronic store to purchase some transistors 2N3904 to create an amplifying circuit and connect that to the speaker. Finally, the sound it generated was a lot louder than before. It would be a lot better to purchase the speaker and 2N3904 together, because a lot of time is being wasted in between because we thought the micro controller could create enough voltage to sound a speaker.

My Issue #2: Motion Sensor

The second part of our issue is the motion sensor, the first sensor that we bought is not turning off for some reason, in other words, it always senses motion even though nothing is moving in front of the sensor. Then, we were trying to think of a way to work around the box with other ideas, but none of them work. So we have to go online and buy 5 motion sensor because we don't want any defected parts to slow down our progress. The sensors that we bought finally worked, but sometimes it would give a false signal when there's no motion so I'm assuming it needs some time for the motion sensor to stabilize itself.

Conclusion

In conclusion, the project was successful completed. Through working on this project, we were able to understand the FreeRTos and Embedded Code deeper. During testing the project, we got many queue timing problem and priority issues. After we fixed those bugs by testing the program multiple times, we furthered our knowledge in the embedded system field. We also learned how to use the PIR motion, it took us a long time to make it work precisely. By doing this project, the lesson we have learned is to do enough research before you actually order the parts.We waste lots of money due to this reason.


Project Video

Upload a video of your project and post the link here.

Project Source Code

References

Acknowledgement

We would like to thank Mr. Preet and Professor Ozemek for teaching us all those knowledge about real-time embedded system design.

References Used

. SocialEdge

Appendix