Five Guys – Security System – Schematic and Discussion

The first phase of testing for the project consisted only of the A3BU, the LED and the piezo-buzzer, and the IR distance sensor. There was no password interface or mechanism for disarming the alarm, except for removing the power to the A3BU. This first iteration of the project can be seen in Figure 1 below.

Figure 1

The infrared distance sensor works using two beams of infrared light with effective measurement ranges of 4 cm to 1 m. If either of the beams is interrupted by a solid object, the distance sensor will transmit a voltage signal back to the A3BU – 3.3 V for 4 cm distance and 0.4 V for the maximum measureable distance. Once this voltage signal is received by the A3BU, it uses an Analog to Digital Conversion (ADC) input to translate the signal into an 8-bit pattern (0 to 127 decimal) that can be translated using a linear regression into a physical distance interpretation.

Based on conditional logic in the programming (see “Source Code”), the LED and piezo-buzzer react differently at different bit patterns. For example, once the bit pattern reaches 70, the LED begins to flash at 50% duty cycle (1 kHz) as a warning that the system is armed. The LED and piezo-buzzer were powered from the A3BU and received a Pulse Width Modulated (PWM) signal at 1 kHz and varying duty cycles, based on the bit pattern received post-ADC from the IR distance sensor.

The second and final iteration of the prototype included password prompts from the A3BU, entered using SW1 and SW2 buttons native to the microcontroller. It also included an emergency switch to remove power from the piezo-buzzer in the instance of a false trip during our demo. This final product is depicted in Figure 2 below.

Figure 2

Once the bit pattern reached 100, the user would be prompted for a password on the LCD screen. If the password given was incorrect, the buzzer would sound in a “breathing” duty cycle pattern, similar to that used in Lab 4. If the correct password was given, then the logic was interrupted and the system went back to its pre-alert state. If the alarm was tripped, the user could press SW1 to deactivate the system, in the instance of a false trip. The emergency switch was also an option, but was only used to interrupt the piezo-buzzer. An example of the password prompt is shown in Figure 3.

Figure 3

The basic schematic form of the circuits are shown in the “Schematics (Hardware)” section of this report. The schematic was drawn using Microsoft Visio.

Basic Project Schematic

Five Guys – Security System – Code


#include <asf.h>

#include "keyboard.h"

#include "touch_api.h"

#include <stdio.h>

#include <conf_example.h>

#include <gfx_mono.h>

&nbsp;

//define our own codes for easier use with buttons

#define BOTTOM_RIGHT  40

#define TOP_RIGHT    38

#define TOP_LEFT  8

#define BOTTOM_LEFT 13

&nbsp;

//global

struct pwm_config mypwm[2]; //For your PWM configuration –CKH

struct keyboard_event input; // probes for button push

&nbsp;

//function declarations

bool CheckKey();

bool KeyToCheck(<em>uint8_t</em>);

&nbsp;

static void adc_handler(ADC_t *adc, <em>uint8_t</em> ch_mask, adc_result_t result)

{

#ifdef CONF_BOARD_OLED_UG_2832HSWEG04

gfx_mono_draw_filled_rect(0,0,128,32,GFX_PIXEL_CLR);

#endif

<em>int32_t</em> value;

char out_str[OUTPUT_STR_SIZE];

char *outputString = <em>NULL</em>;

bool valid;

bool goingUp = true;

int alarmSound = 10;

&nbsp;

value = (<em>int8_t</em>)(result);

&nbsp;

if(value > 70){//"low level" alert - LED flashes

pwm_start(&mypwm[0], 50);

}

if(value > 100){//"high level alert" - LED lit and buzzer armed

//alarm is going off and we need to check the password

gfx_mono_init();

gfx_mono_draw_string("Enter Password", 5, 5, &sysfont);

pwm_start(&mypwm[0], 100); // LED fully lit

valid = CheckKey();

if(!valid){

gfx_mono_init();

gfx_mono_draw_string("Calling Police",  5, 5, &sysfont);

while(true){

keyboard_get_key_state(&input);

if (input.type == KEYBOARD_RELEASE)

{

if(input.keycode == TOP_RIGHT){//end logic loop if password is correct

break;

}

}

delay_ms(250);

pwm_start(&mypwm[1], alarmSound);

if(alarmSound == 50){//restart "breathing" alarm loop

goingUp = false;

}

if(alarmSound == 10){ // "breathing" alarm loop

goingUp = true;

}

if(goingUp){

alarmSound += 10;

}

else{

alarmSound -= 10;

}

}

gfx_mono_init();

gfx_mono_draw_string("CORRECT!", 5, 5, &sysfont);

}

}

else{

pwm_start(&mypwm[0], 0); // restart LED if password is correct

pwm_start(&mypwm[1], 0);// restart buzzer if password is correct

}

//

//snprintf(out_str, OUTPUT_STR_SIZE, "%4d", value);

//gfx_mono_draw_string(out_str, 0, 0, &sysfont);

// Start next conversion.

adc_start_conversion(adc, ch_mask);

}

&nbsp;

int main(void)

{

struct adc_config         adc_conf;

struct adc_channel_config adcch_conf;

&nbsp;

board_init();

sysclk_init();

sleepmgr_init();

irq_initialize_vectors();

cpu_irq_enable();

gfx_mono_init();

&nbsp;

// Enable backlight if display type is not OLED

#ifndef CONF_BOARD_OLED_UG_2832HSWEG04

ioport_set_pin_high(LCD_BACKLIGHT_ENABLE_PIN);

#endif

&nbsp;

&nbsp;

&nbsp;

/* Set up a PWM channel with 500 Hz frequency. Here we will output 4 different pulse trains on 4 pins of the A3BU Xplained.*/

pwm_init(&mypwm[0], PWM_TCC0, PWM_CH_A, 1000);//this is SDA on J1 on the A3BU Xplained - LED

pwm_init(&mypwm[1], PWM_TCC0, PWM_CH_B, 1000);// this is SCL on J1 - buzzer

// both at 1 kHz PWM

pwm_start(&mypwm[0], 100);

pwm_start(&mypwm[1], 100);

// Initialize configuration structures.

adc_read_configuration(&ADCB, &adc_conf);

adcch_read_configuration(&ADCB, ADC_CH0, &adcch_conf);

&nbsp;

adc_set_conversion_parameters(&adc_conf, ADC_SIGN_ON, ADC_RES_8,

ADC_REF_VCC);

adc_set_clock_rate(&adc_conf, 200000UL);

adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);

adc_enable_internal_input(&adc_conf, ADC_INT_TEMPSENSE);

&nbsp;

adc_write_configuration(&ADCB, &adc_conf);

adc_set_callback(&ADCB, &adc_handler);

&nbsp;

/* Configure ADC channel 0:

* - single-ended measurement from temperature sensor

* - interrupt flag set on completed conversion

* - interrupts disabled

*/

adcch_set_input(&adcch_conf, ADCCH_POS_PIN1, ADCCH_NEG_NONE,

1);

adcch_set_interrupt_mode(&adcch_conf, ADCCH_MODE_COMPLETE);

adcch_enable_interrupt(&adcch_conf);

&nbsp;

adcch_write_configuration(&ADCB, ADC_CH0, &adcch_conf);

&nbsp;

// Enable the ADC and start the first conversion.

adc_enable(&ADCB);

adc_start_conversion(&ADCB, ADC_CH0);

&nbsp;

do {

// Sleep until ADC interrupt triggers.

sleepmgr_enter_sleep();

} while (1);

}

&nbsp;

bool CheckKey() //password check in high alert

{

bool isValid = false;

&nbsp;

isValid = KeyToCheck(TOP_RIGHT);

if(!isValid) return false;

isValid = KeyToCheck(BOTTOM_RIGHT);

if(!isValid) return false;

&nbsp;

return true;

}

&nbsp;

bool KeyToCheck(<em>uint8_t</em> nextCorrectKey)//receives button input and checks against pre-programmed password

{

// any key will exit the loop

while (true)

{

keyboard_get_key_state(&input);

if (input.type == KEYBOARD_RELEASE)

{

if(input.keycode == nextCorrectKey){

return true;

}

else{

return false;

}

}

}

}

Five Guys – Security System – Abstract

Our final project is the culmination of what we’ve been working on all semester. We set out to design a prototype “home security system” that would use an infrared (IR) distance sensor to detect the presence of an intruder, warn the intruder, prompt for a password, then set off an alarm if the proper password wasn’t given.

The IR sensor was set up in a logical loop with the LED and piezo-buzzer “alarm”, with the Atmel XmegaA3BU microcontroller being used as the power source and the “bridge” between the two control loops. This process will be discussed in greater detail in the “Body” section of this report.

Our equipment consisted of:

  • An Atmel XmegaA3BU Xplained microcontroller
  • An infrared (IR) distance sensor manufactured by SHARP
  • A green LED
  • A piezo-buzzer
  • Breadboarding
  • A constructed wooden platform for housing the components

All code was written in Atmel Studio 7.0 and debugged using a JTAGICE3.

The completed prototype was able to use the distance value returned from the sensor to set off different levels of alerts and prompt for a password that could be used to “disarm” the alerts.