The Door MC-38 is a magnetic reed switch commonly used as a sensor for detecting the opening and closing of doors and windows. It is a simple, yet effective component for security systems, home automation, and other applications where it is necessary to monitor the status of an entry point.
The Door MC-38 does not have traditional pins but has two parts: the reed switch and the magnet. The reed switch has two wires for connection.
Wire Color | Description |
---|---|
Red | Connect to power |
Black | Connect to ground |
// Define the pin connected to the Door MC-38
const int doorSensorPin = 2;
void setup() {
// Set the door sensor pin as an input with an internal pull-up resistor
pinMode(doorSensorPin, INPUT_PULLUP);
// Initialize serial communication at 9600 bits per second
Serial.begin(9600);
}
void loop() {
// Read the state of the door sensor
int doorState = digitalRead(doorSensorPin);
// Check if the door is open (the reed switch is open and the input is HIGH)
if (doorState == HIGH) {
Serial.println("Door is open");
} else {
Serial.println("Door is closed");
}
// Delay for a bit to avoid spamming the serial output
delay(500);
}
Q: Can the Door MC-38 be used outdoors? A: Yes, but it should be protected from the elements to prevent corrosion and damage.
Q: What is the maximum distance the magnet can be from the switch? A: The maximum operating gap is typically around 15-25mm, but it's best to keep it as close as possible for reliable operation.
Q: Can I connect multiple Door MC-38 switches to a single Arduino? A: Yes, you can connect multiple switches to different digital pins on the Arduino, just ensure each has its own pull-up resistor if not using the internal one.