Detecting if the door is open with a reed switch

An example has been added as an option to implement a magnetic sensor in order to detect when a door or window is open or closed.

Detecting if the door is open with a reed switch

The sensor outputs a 0 when it detects the magnetic field and when the field is far away the output would be a 1; so you can determine when the door is open or closed.

The program in the Arduino is performed as follows:

We define the input signal of the sensor, and configure the serial communication:

void setup() { 
  pinMode(sensor, INPUT_PULLUP); 
  Serial.begin(9600); 
} 

We read the state of the sensor:

void loop() { 
state = digitalRead(sensor); 

It compares the digital input and displays the status of the door in the serial interface:

  if (state == LOW){ 
    Serial.println("Door Close"); 
  } 
  if (state == HIGH){ 
    Serial.println("Door Open"); 
  } 
} 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.209.121