Arduino + reed sensor

Reed sensor is a special device designed to increase the security level of individual objects. The main active components of this product are reed switch and magnet, so that the device and got an appropriate name. Sensor reacts to opening doors in private homes and far from their garages, utility rooms, metal containers. (figure 1).

Figure 1 – Reed sensor

Connecting reed sensor to Arduino via resistor 10 k.


Let’s write a program to Arduino, which will read the reed switch sensor and when you open the door, turn on the Arduino LED (pin 13).

int Door_Led_Pin = 13; // choose the pin for the LED
int Door_Sensor_Pin = 6; // choose the Door_Sensor_Pin
int val = 0; // variable for reading the Door_Sensor_Pin status

void setup() {
pinMode(Door_Led_Pin, OUTPUT); // declare Door_Led_Pin as output
pinMode(Door_Sensor_Pin, INPUT); // declare Door_Sensor_Pin as input

void loop(){
val = digitalRead(Door_Sensor_Pin); // read Door_Sensor_Pin
if (val == HIGH) { // If Door_Sensor N.C. (no with magnet) -> HIGH : Door is open / LOW : Door is closed
// If Door_Sensor N.0. (nc with magnet) -> HIGH : Door is closed / LOW : Door is open [This will be our case in AHA Project]
digitalWrite(Door_Led_Pin, LOW); //Set Door_Led low
} else {
digitalWrite(Door_Led_Pin, HIGH); //Set Door_Led high



Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.