F16: Door Alarm System
Contents
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.
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.
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.
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.