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

Door Detection

Door Detection with Arduino

Introduction: Door detection is a crucial aspect of various applications, including home automation, security systems, and robotics. By using Arduino, we can easily implement a door detection system that can monitor the status of a door and trigger actions accordingly. In this article, we will explore the importance and utility of door detection and provide examples of code and a list of components required for the project.

Project: The project aims to create a door detection system using Arduino. The objectives of the project include:

  1. Monitoring the status of a door (open or closed).
  2. Notifying the user or triggering actions based on the door status.
  3. Providing a versatile and customizable solution for different applications.

Components Required: To create the door detection system, the following components are needed:

  1. Arduino Uno - 1x
  2. Reed Switch - 1x
  3. Magnet - 1x
  4. Jumper wires - As required
  5. Breadboard - 1x

You can find these components at the following links:

  • Arduino Uno: [link]
  • Reed Switch: [link]
  • Magnet: [link]
  • Jumper wires: [link]
  • Breadboard: [link]

Examples: Here is an example code for implementing a door detection system using Arduino:

const int reedSwitchPin = 2; // Pin connected to the reed switch

void setup() {
  pinMode(reedSwitchPin, INPUT); // Set the reed switch pin as input
  Serial.begin(9600); // Initialize serial communication for debugging
}

void loop() {
  int doorStatus = digitalRead(reedSwitchPin); // Read the status of the reed switch

  if (doorStatus == HIGH) {
    Serial.println("Door is closed");
    // Perform actions when the door is closed
  } else {
    Serial.println("Door is open");
    // Perform actions when the door is open
  }

  delay(1000); // Delay for stability
}

Explanation:

  • We start by defining the pin connected to the reed switch (in this example, pin 2).
  • In the setup function, we set the reed switch pin as an input and initialize the serial communication for debugging purposes.
  • The loop function continuously reads the status of the reed switch using the digitalRead function.
  • If the door is closed (reed switch is activated), the code prints "Door is closed" and performs the corresponding actions.
  • If the door is open (reed switch is not activated), the code prints "Door is open" and performs the corresponding actions.
  • A delay of 1 second is added to ensure stability and prevent false readings.

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.