Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
The importance and usefulness of a door sensor
A door sensor is a crucial component in various applications, particularly in the field of home automation and security. It allows for the detection of the opening and closing of doors, providing valuable information for controlling access, monitoring activity, and enhancing safety. Door sensors are commonly used in alarm systems, smart locks, and automatic lighting systems, among others.
Project: Creating a door sensor using Arduino
For this example project, we will create a simple door sensor using Arduino. The objective is to detect the opening and closing of a door and provide visual feedback through an LED.
List of components:
Examples:
Arduino Uno Magnetic Reed Switch
-------------- --------------------
Digital Pin 2 ---------- Reed Switch (NO)
GND ------------ Reed Switch (GND)
5V ------------ Reed Switch (VCC)
Arduino Uno Resistor
-------------- --------------------
Digital Pin 13 ---------- Resistor (one leg)
GND ------------ Resistor (other leg)
Arduino Uno LED
-------------- --------------------
Digital Pin 12 ---------- LED (long leg)
GND ------------ LED (short leg)
const int reedSwitchPin = 2;
const int ledPin = 12;
void setup() {
pinMode(reedSwitchPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int doorState = digitalRead(reedSwitchPin);
if (doorState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
Explanation:
This code continuously checks the state of the door and controls the LED accordingly.