Difference between revisions of "F16: Door Alarm System"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Parts List & Cost)
(References Used)
 
(49 intermediate revisions by the same user not shown)
Line 13: Line 13:
 
In order to accomplish the objective, we need to the following things:
 
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.
+
* 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.   
+
* Figure out how to amplify the sound signal.
 +
 
 +
* Using the ADC code to receive the signal from motion sensor.   
  
  
Line 21: Line 23:
 
*<b>Bowei Zhang</b>
 
*<b>Bowei Zhang</b>
 
**  Program the speaker.
 
**  Program the speaker.
**  Programming the ADC code.
+
**  Design Hardware Schematic.
**  Testing the software.
+
**  Programming.
 +
**  Testing the hardware.
 +
 
  
 
*<b>James Huang</b>   
 
*<b>James Huang</b>   
 
**  Improve the playing song algorithm.
 
**  Improve the playing song algorithm.
**  Design the hardware connection between MCU and external parts.
+
**  Design the software schematic.
**  Programming the ADC code
+
**  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 44: Line 49:
 
| Oct31 - Nov4
 
| Oct31 - Nov4
 
| Project Plan & ordering parts
 
| Project Plan & ordering parts
| Incompleted.
+
| Completed
| Haven't ordered the parts.
+
| Parts Ordered
 
|-
 
|-
 
! scope="row"| week2
 
! scope="row"| week2
Line 107: Line 112:
 
| $2
 
| $2
 
| Buzzer
 
| Buzzer
|-
 
! scope="row"| SD card
 
| 1
 
| ~$10
 
|
 
 
|-
 
|-
 
! scope="row"| LEDs
 
! scope="row"| LEDs
Line 121: Line 121:
 
|1
 
|1
 
|$15
 
|$15
| Detector
+
| Motion Detector
 
|-
 
|-
 
! scope="row"| Signal Amplifier
 
! scope="row"| Signal Amplifier
Line 131: Line 131:
  
 
== 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