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 Detection

Door/Window Detection with Arduino

Introduction: Door/Window detection is an essential component of home automation and security systems. By using Arduino, we can easily create a project that detects the status of doors or windows and triggers actions based on their open or closed state. This article will guide you through the process of creating a door/window detection project using Arduino, providing example codes and a list of components required for the project.

Project: The project aims to create a door/window detection system that can monitor the open or closed state of doors or windows. The system will use magnetic reed switches to detect the position of the door/window and provide real-time feedback.

Components Required:

  1. Arduino Uno
  2. Magnetic Reed Switches (quantity depends on the number of doors/windows to be monitored)
  3. Resistors (220 ohms)
  4. Jumper wires
  5. Breadboard
  6. LED (optional, for visual feedback)

Example Code: Below is an example code that demonstrates how to detect the open or closed state of a door/window using Arduino:

// Door/Window Detection with Arduino

const int reedSwitchPin = 2;  // Pin connected to the magnetic reed switch
const int ledPin = 13;        // Pin connected to the LED for visual feedback

void setup() {
  pinMode(reedSwitchPin, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

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

  if (doorState == HIGH) {
    digitalWrite(ledPin, HIGH);
    Serial.println("Door/Window is closed");
  } else {
    digitalWrite(ledPin, LOW);
    Serial.println("Door/Window is open");
  }

  delay(500); // Adjust the delay as per your requirement
}

Explanation:

  • The code starts by defining the pins for the reed switch and LED.
  • In the setup function, we set the reed switch pin as an input and the LED pin as an output. We also initialize the serial communication for debugging purposes.
  • In the loop function, we read the state of the reed switch using the digitalRead function. If the door/window is closed (reed switch is HIGH), we turn on the LED and print a message indicating the closed state. If the door/window is open (reed switch is LOW), we turn off the LED and print a message indicating the open state.
  • The delay function is used to add a small delay between each loop iteration to avoid rapid state changes.

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.