Name: Switch-Controlled Alarm System
Description: This project uses a K1 switch to activate an alarm. The system is programmed to control the P1.0 pin to generate two different frequencies, simulating a highly realistic alarm sound.
/* This program is designed for an 8051 microcontroller */
#include
#define uchar unsigned char
#define uint unsigned int
sbit SPK = P1^0;
sbit K1 = P1^7;
// Function to generate alarm sound
void Alarm(uchar t)
{
uchar i, j;
for(i = 0; i < 200; i++)
{
SPK = ~SPK;
for(j = 0; j < t; j++); // Adjust frequency based on parameter t
}
}
// Main function
void main()
{
SPK = 0;
while(1)
{
if(K1 == 1)
{
Alarm(90);
Alarm(120);
}
}
}
This simple yet effective alarm system demonstrates how a basic microcontroller can be used to create interactive and real-world applications. The K1 switch acts as a trigger, and when pressed, it activates the alarm by sending signals through the P1.0 pin. The sound is generated using a square wave, which is toggled rapidly to produce different frequencies. By varying the value of 't' in the Alarm function, the frequency of the sound changes, allowing for distinct tones that mimic a real alarm. This project is ideal for learning about microcontroller programming, digital signal generation, and hardware interfacing. It also highlights the importance of timing and loop control in embedded systems.
Cordline Switches,Electrical Switch, Rocker Switch, Foot Switch, Hand Switch, On-Off Rocker Switches
Jiangmen Krealux Electrical Appliances Co.,Ltd. , https://www.krealux-online.com