Tuesday, 27 January 2015

DOOR SENSORS WITH ARDUINO


Using door sensors are very basic prerequisites in electronics. Door sensors are just a Reed Switch where the Switch gets activated when subjected to electromagnetic waves.When in normal condition it gets deactivated.

 


Both single and dual contact reed switch is very simple . In single contact switch only one connection can be made while in dual contact is just an exact replica of a Relay which i have explained in your session on "HOW TO MAKE A AUTOMATIC EVENING LAMP".

Diagram


Working & Arduino Sketch


The above circuit is very simple in fact it is just a continuity check in an arduino.The ground of the Arduino is connected to a Reed switch and +5V of Arduino is connected to the other end of the Arduino with a LOAD.LOAD is connected in order to prevent the frying of Arduino.Arduino would be jammed if its Vcc and gnd are connected . Now to check whether the circuit is close the line is tapped and is given to any of the I/O pins in Arduino.

Program

//The following sketch blinks a LED when a magnet is brought near the sensor.

setup()
{
  pinMode(13,OUTPUT);
  pinMode(2,INPUT);  //change the pin number based on IO pin you connect
}
void loop()
{
  int sensorinput=digitalRead(2);
  if(sensorinput==HIGH)
  {
    digitalWrite(13,HIGH);
  }
  else
  {
    digitalWrite(13,LOW);
  }
}


Reed switch as a Door Sensor

Place the reed switch on one side of the door and a magnet on other side of the door. When the door is open the Circuit is broken and when the door is closed the circuit is inturn closed.


No comments:

Post a Comment