
10. Reed Switch Sensor
Preparation
- Six different colored DuPont wires (male to female)
- Reed switch sensor module
- Bi-color LED module

(Note: For the list of Raspberry Pi and related accessories, please refer to previous articles on the public account.)
Experiment Content
Use the reed switch sensor module as an input device for the Raspberry Pi. When the module does not detect a magnetic field, the bi-color LED shows green; when the module detects a magnetic field, the bi-color LED shows red.
Experiment Principle
The reed switch sensor module is a sensor used to detect magnetic fields, commonly used in photocopiers, washing machines, refrigerators, cameras, door magnets, window magnets, etc.
Experiment Steps
Wiring Section
| Reed Switch Sensor | Raspberry Pi |
|---|---|
| DO | GPIO17 |
| VCC | 3.3V |
| GND (middle) | GND |
| Bi-color LED | Raspberry Pi |
|---|---|
| G (S) | GPIO27 |
| R (middle) | GPIO18 |
| GND (-) | GND |
1. Red wire, reed switch sensor DO <==> Raspberry Pi GPIO17

2. Orange wire, reed switch sensor VCC <==> Raspberry Pi 3.3V

3. Purple wire, reed switch sensor GND (middle) <==> Raspberry Pi GND

4. Yellow wire, bi-color LED G (S) <==> Raspberry Pi GPIO27

5. Green wire, bi-color LED R (middle) <==> Raspberry Pi GPIO18

6. Blue wire, bi-color LED GND (-) <==> Raspberry Pi GND

Code Section
Download Code
Download link: https://fliot.net.cn:8090/playsensor.html Go to the link and download 10. Reed Switch Sensor.py code file
Open the code file with Thonny tool.

Run Code

Stop Code
Click on the Shell window of the code tool, press Ctrl + C to stop execution and release resources.
Running Effect
When the reed switch sensor does not detect a magnetic field, the bi-color LED shows green; when it detects a magnetic field, the bi-color LED shows red.
