Motion Sensor Alarm System – The Code


while (1) {
	if (ioport_get_pin_level(MOTION_SENSOR)) {
		pwm_start(&pwm_cfg, 50);
		while (1) {
			if (!ioport_get_pin_level(BUTTON)) {

This is the main loop running on the microcontroller. It continually checks if the level of the pin connected to the motion sensor is high. If it is high, then pulse width modulation on the pin connected to the buzzer starts.

Then we enter another while loop which polls for a button to be pressed. If the button is pressed, pulse width modulation stops (and therefore the buzzer stops buzzing) and we delay for 20 seconds. The motion sensor stays on for a few seconds after it has detected motion. If we didn’t delay here, then we would immediately break out of the inner while loop, pass the if statement, and start pulse modulation again. This would cause a strange effect while the motion sensor is still on. Therefore, we delay for some arbitrary amount of time before we poll for the motion sensor again.

Motion Sensor Alarm System – Schematics and Layout

Below is our original schematic for our Motion Sensor Alarm System.  The original project would integrate a Motion sensor, LED indicator, Micro Controller, RF Receiver, and RF Transmitter.

However, the RF Transmitter was not going to arrive in time of the projects deadline.  Therefore, we decided to remove the RF Receiver and RF Transmitter from our project entirely and built the interrupt of the buzzer into the Micro Controller.  This is reflected in the updated schematic and layout below.


The new Motion Sensor Alarm System works as follows.  The Motion Sensor will detect motion, sending a signal to the LED and Micro Controller.  The LED will alight, indicating that the motion sensor is working.  The Micro Controller receives the signal that the Motion Sensor is active and uses that signal to begin playing the Buzzer.  The Buzzer will continue to sound until the interrupt button SW1 is pushed, this means the Buzzer will continue to sound even if the Motion Sensor does not detect motion anymore.  The interrupt button SW1 will keep the Buzzer from sounding for a 20 second time frame.  During this time frame, the Motion Sensor can continue to turn on or off which will activate and deactivate the LED, but the Buzzer still will not sound until the time frame concludes.  This time frame can be edited in our code to be any amount of time.

Motion Sensor Alarm System – The Big Idea

Team Super Saver began work on laying out the hardware that would be required to build the Motion Sensor Alarm System. We experimented with the individual components to learn exactly how they worked. Our plan was to create a system that used a motion sensor to detect if a person was passing by, which then set off an alarm. If that person had the correct key fob, they could disable the alarm when they walked by.


Starting with the PIR Motion Sensor, we wired it up directly to an LED and resistor in order to test its timing and sensitivity settings. We learned that by keeping the timing dial and sensitivity dial at their minimum values, we could light up the LED most accurately with when we activated the motion sensor. Next, we test the buzzer.  We learned that the buzzer would not receive DC voltage, only taking AC.  This somewhat complicated our project, as now we must send a Pulse Width Modulation from the A3BU to the buzzer in order to trigger it, as opposed to just a DC signal, like the rest of our equipment runs on. Finally, we attempted to test our RF Receiver.  We were able to set it up but found that we never ordered a remote transmitter… So, we quickly placed an order and continued to set up the rest of our circuit. After that, we decided to break for lunch, and Gabe, who was in charge of coding the A3BU, had to leave. We the rest of us returned from lunch, we decided all that we could do for the day was clean up our board and draw schematics for the circuitry, in case something happened.

UPDATE: 12/9/17:

After realizing the RF Transmitter would not arrive in time for the projects deadline, we decided to remove the RF Receiver and RF Transmitter from our plans entirely.  Instead, we decided to build the interrupt to our buzzer directly into one of the A3BU’s Buttons.