Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Door/Window Opening Detection

Importance and Utility of Door/Window Opening Detection

Door/Window opening detection is a crucial aspect in various applications, including security systems, home automation, and energy efficiency. By monitoring the state of doors and windows, we can enhance safety, automate tasks, and optimize energy consumption. This article will explore a practical project that demonstrates how to detect the opening and closing of doors/windows using Arduino and various electronic components.

Project: Door/Window Opening Detection System

The objective of this project is to create a simple yet effective door/window opening detection system using Arduino. The system will consist of a magnetic reed switch, Arduino board, and a buzzer. When a door/window is opened or closed, the reed switch will detect the change in magnetic field and trigger an alert through the buzzer.

List of Components:

Examples:

Example 1: Basic Door/Window Opening Detection

const int reedSwitchPin = 2; // Connect the reed switch to digital pin 2
const int buzzerPin = 3; // Connect the buzzer to digital pin 3

void setup() {
  pinMode(reedSwitchPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  int doorStatus = digitalRead(reedSwitchPin);

  if (doorStatus == HIGH) {
    digitalWrite(buzzerPin, HIGH);
    delay(1000);
    digitalWrite(buzzerPin, LOW);
    delay(1000);
  }
}

Explanation:

  • We define the reed switch pin and buzzer pin as constants.
  • In the setup() function, we set the reed switch pin as an input and the buzzer pin as an output.
  • In the loop() function, we read the status of the reed switch using digitalRead().
  • If the door/window is open (reed switch is HIGH), the buzzer is turned on for 1 second and then turned off for 1 second.

Example 2: Advanced Door/Window Opening Detection with LED Indicator

const int reedSwitchPin = 2; // Connect the reed switch to digital pin 2
const int buzzerPin = 3; // Connect the buzzer to digital pin 3
const int ledPin = 4; // Connect an LED to digital pin 4

void setup() {
  pinMode(reedSwitchPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int doorStatus = digitalRead(reedSwitchPin);

  if (doorStatus == HIGH) {
    digitalWrite(buzzerPin, HIGH);
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(buzzerPin, LOW);
    digitalWrite(ledPin, LOW);
    delay(1000);
  }
}

Explanation:

  • This example extends the basic door/window opening detection by adding an LED indicator.
  • We define the LED pin as a constant and set it as an output in the setup() function.
  • In the loop() function, we turn on the LED along with the buzzer when the door/window is open.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.