Reed Switch with Raspberry Pi, interfacing and Python Programming

(Last Updated On: April 1, 2021)

Reed Switch with Raspberry Pi:

Reed Switch with Raspberry Pi– A very simple, but quite useful sensor is the reed switch or contact. The reed switch is also known as the magnetic reed switch. The reed switch has the contacts enclosed in a glass tube which can be controlled using a permanent magnet or electromagnet. When the magnet is near to the reed switch the contacts remain closed and when the magnet is away the contacts are open. This opening and closing of the contacts can be used as the signal, which can be used to perform some predefined functions. I have been using reed switches for quite a long time in different Arduino, ESP8266, ESP32, and Raspberry Pi based projects. I also have a very detailed tutorial now how to use a reed switch with the Arduino.  Conceivable application possibilities are:

  • Mounting on a door for open / closed detection
  • Proximity sensor
  • model maker
  • Rotation sensor
  • Detection of open windows or doors


Amazon Purchase Links:

Reed Switch

Raspberry Pi

raspberry pi 4 4gb kit

Wireless Keyboard and Mouse for raspberry pi:

Night vision Camera for Raspberry Pi:

Oled HDMI touch display for raspberry pi:

Other Tools and Components:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

The reed switch is available in different designs, however its functionality is always identical. Inside the switch there are two closely spaced metallic contact flags. If you approach the reed switch with a magnet or magnetic object closes the Contact inside and a conductive connection is created. You can say this is modified version of the mechanical switches or buttons, unlike the other buttons and switches, reed switches don’t need any physical contact as they work on the magnetic field.

Reed Switch with Raspberry pi



The reed contact basically works like a button. A reed switch can be easily used with Raspberry pi. Seriously if you know how to use a pushbutton with the Raspberry Pi then there is no need to be worried about. Reed switch is just like the pushbutton. The only difference is that, the pushbutton ned a physical contact while the reed switch is operated with the help of a magnet. You can use the same program that you have written for the pushbutton, with the reed switch as well. The reed switch just like the pushbutton does not give you measured values, but only a logical 1 or 0. The contact is connected as usual to a free GPIO pin, which is used as an input. Place the other side of the reed contact against ground or 3.3 V. It depends on whether the logical 1 or the logic 0  in the closed or open state is recognized. In the circuit diagram (see Figure 1) the contact is on GPIO pin 15 connected. R1 serves as a pull-up resistor and is optional when used in Python Pull-up is activated for this pin. R2 is used to limit the current when the contact is closed. The sensor is queried in Python as usual by reading back the GPIO status of pin 15:

Reed Switch with Raspberry pi
Figure 1: Reed switch on GPIO pin 15 as input


Reed Switch programming in Raspberry pi:

The little Python program indicates the status of the reed contact every second. If it is not actuated, 1 appears, in the actuated state a 0 is output. Here, too, you can use events or interrupts as with the PIR sensor.

 

Recommended For You

About the Author: Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

%d bloggers like this: