[tutorial] How to use a Magnetic Door Switch / Sensor With Arduino

Introduction

In this tutorial we will use one magnetic – contact door sw / sensor and a buzzer for making a “noise” when a door is opened. Normally the reed is ‘open’ (no connection between the two wires). The other half is a magnet. When the magnet is less than 13mm (0.5″) away, the reed switch closes.

What you will need

For this project you will need:

  • Arduino uno
  • Magnetic Contact Switch – Door Sensor
  • Buzzer
  • Breadboard and some cables

The circuit

The connections are pretty easy, see the above image with the breadboard circuit schematic.

The Code

Here’s the code, embedded using Codebender!

Try downloading the Codebender plugin and clicking on the “Run on Arduino” button to program your Arduino board with this sketch. And that’s it, you’ve programmed your Arduino with this sketch!

Well done!

You have successfully completed one more “How to” tutorial and you learned how to use a magnetic contact switch with Arduino.

I hope you liked this, let me know in the comments.

2 Comments

  1. Sharath

    23 Mar 2018 13:56:30

    A very creative post. Can help a lot to the students for any DIY wonderful project. So many options to get into the result. If we get the right accessories, we can prepare our own alam system for the home security. Thank you for sharing.

  2. Martin Salazar

    11 Oct 2018 00:09:48

    Buenas Tardes
    Abria problema con el Amperaje que trabaja el sensor magnetico de puerta 500mA
    ya que la conexion es P

    Producto: MC38
    Corriente máx: 0.5A (lo que es lo mismo a 500mA)Lo que me Preocupa esta caracteristica
    Voltaje máx: 100V
    Distancia de activación: 15-25mm
    Longitud de cable: 25cm
    Material: Plastico Blanco ABS
    Dimensiones: 34 × 41 × 6.5 mm
    PIn 4 (Pinmode pull-up) conecta con el GND a través del Sensor magnético de puerta el cual trabaja como maximo a 500mA
    quiero saber si esto me da problemas por la cantidad de corriente que necesita el magnetico y termine con problemas en la placa dado que su consumo maximo es 500mA (ojo conexion por pin digital) no el de 5 voltios

Comments are closed.

Stay tuned:

* we promise that we won´t spam you, never.