Now you can build your own simple security alarm button using a tiny microcontroller chip PIC12F675 ! The circuit is nothing but an aural alert unit, which raises a warning tone when the trigger button is pushed by someone. The unit can be powered from four 1.5V AA/AAA cells wired in series (6VDC).
The circuit can be energized by turning the power switch S2 to “On” position. The Red LED (LED1) blinks 3 times when the power is turned on to indicate that the system has been powered up. Then IC1 (PIC12F675) waits for about 10 seconds before it starts monitoring the trigger switch status. After the initial delay, when the IC1 detects S1 is closed (door opened) , it drives the piezo –
speaker (PZ1) with a square wave signal, and the piezo – speaker remains on as long as the trigger switch is enabled. If the trigger switch is disabled (changes to open state) the piezo – speaker will not sleep immediately, but still be on for about 10 more seconds but with a slightly different frequency.
The firmware is written in C and compiled with MikroC Pro for PIC. Note that MCLR function is disabled, and WDT is OFF in this project. Demo version of MikroC Pro for PIC can be downloaded from http://www.mikroe.com
Source Code
/* Microcontroller = PIC12F675 Internal Clock @ 4.0 MHz T.K.Hareendran / 2018 https://www.codrey.com */ sbit Sensor_IP at GP5_bit; sbit LED at GP4_bit; // LED O/P unsigned short trigger, counter; void Get_Delay(){ Delay_ms(300); } void main() { CMCON0 = 7; TRISIO = 0b00101000; GPIO = 0; Sound_Init(&GPIO,2); LED = 1; Get_Delay(); LED = 0; Get_Delay(); LED = 1; Get_Delay(); LED = 0; Get_Delay(); LED = 1; Get_Delay(); LED = 0; Delay_ms(10000); counter = 0; trigger = 0; do { while (!Sensor_IP) { Sound_Play(3500, 600); Delay_ms(500); trigger = 1; counter = 0; } if (trigger) { Sound_Play(2900, 600); Delay_ms(500); counter = counter+1; if(counter == 10) trigger=0; } }while(1); } // End main()