Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » How to use Reed Switch with Raspberry Pi Pico
Raspberry Pi Raspberry Pi Pico Projects

How to use Reed Switch with Raspberry Pi Pico

Mamtaz AlamBy Mamtaz AlamUpdated:November 4, 20223 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Reed Switch use Raspberry Pi Pico
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this guide, we will interface the Reed Switch with Raspberry Pi Pico for Magnet Detection. We will program Raspberry Pi Pico using MicroPython Code to detect the magnetic signal. Whenever a small magnet is placed close to the reed switch, then the buzzer triggers to play a music tone.

A reed switch is an electromagnetic switch used to control the flow of electricity in a circuit. They are made from two or more ferrous reeds encased within a small glass tube-like envelope, which become magnetized and move together or separate when a magnetic field is moved towards the switch.


Components Required

In this guide, I used Elecrow Raspberry Pi Pico Starter Kit to test different Modules. You can buy the kit and perform some other operations as well. From this kit, you can use the following components.

1. Raspberry Pi Pico Board – 1
2. Reed Switch Module – 1
3. Buzzer – 1
4. Breadboard – 1
5. Jumper Wires – 4
6. Micro-USB Cable – 1




Reed Switch

A reed switch is a sensor that closes the circuit in the presence of a magnetic field. Reed sensors can be used in many applications requiring contactless on/off.

Reed Switch Sensor Module

The Reed Switch Sensor Module consists of a Reed Switch, resistors, capacitor, potentiometer, comparator LM393 IC, Power, and status LED in an integrated circuit.

reed switch module circuit diagram

Reed Switch Sensor Module consists of three pins i.e. VCC, GND, and DO. The digital out pin is connected to the output pin of the LM393 comparator IC. Then the output can be directly connected to the Microcontroller. When the Reed Switch sensor detects the magnetic field, it closes the circuit and the digital pin of the module connected to the LM393 IC goes high.


How to use Reed Switch with Raspberry Pi Pico

Now let us interface the Reed Switch Sensor Module with Raspberry Pi Pico & Buzzer. The connection diagram is very simple.

Reed Sensor Switch Raspberry Pi Pico

Connect the VCC, GND & Output of Reed Sensor Switch to VSYS, GND & GP0 of Raspberry Pi Pico respectively. Similarly, connect the positive terminal of Buzzer to GP14 of Raspberry Pi Pico & the negative terminal to GND.

Reed Switch with Raspberry Pi Pico



MicroPython Code/Program

Copy the following code and paste it into the Thonny Editor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from machine import Pin,PWM
import utime
from utime import sleep
 
Reed_switch = Pin(0, Pin.IN, Pin.PULL_UP)
buzzer = PWM(Pin(14))      
 
Tone_CL = [0, 131, 147, 165, 175, 196, 211, 248]        # low C note frequency
Tone_CM = [0, 262, 294, 330, 350, 393, 441, 495]        # middle C note frequency
Tone_CH = [0, 525, 589, 661, 700, 786, 882, 990]        # high C note frequency
 
# sheet music
song_1 = [ Tone_CM[3], Tone_CM[5], Tone_CM[6], Tone_CM[3], Tone_CM[2], Tone_CM[3], Tone_CM[5], Tone_CM[6],
           Tone_CH[1], Tone_CM[6], Tone_CM[5], Tone_CM[1], Tone_CM[3], Tone_CM[2], Tone_CM[2], Tone_CM[3],
           Tone_CM[5], Tone_CM[2], Tone_CM[3], Tone_CM[3], Tone_CL[6], Tone_CL[6], Tone_CL[6], Tone_CM[1],
           Tone_CM[2], Tone_CM[3], Tone_CM[2], Tone_CL[7], Tone_CL[6], Tone_CM[1], Tone_CL[5] ]
# The beat of the song
beat_1 = [ 1, 1, 3, 1, 1, 3, 1, 1,
           1, 1, 1, 1, 1, 1, 3, 1,
           1, 3, 1, 1, 1, 1, 1, 1,
           1, 2, 1, 1, 1, 1, 1, 1,
           1, 1, 3]
 
# Buzzer play function
def playtone(frequency):
    buzzer.duty_u16(1000)
    buzzer.freq(frequency)
    
# Stop play function
def bequiet():
    buzzer.duty_u16(0)
 
if __name__ == '__main__':
    while True:
        if Reed_switch.value() == 0:
            for i in range(1, len(song_1)):     # play song
                playtone(song_1[i])            # Set the frequency of the song notes
                sleep(beat_1[i] * 0.5)         # Delay a note by one beat * 0.5 seconds            
        sleep(1)
        bequiet()

Run the script and start testing the above-connected circuit.

Reed Switch Magnet Detection

Place the small magnet close to the reed switch, and then trigger the buzzer to play music by detecting the level signal change of the reed switch to achieve the effect of a music box.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleElectronic Hourglass with Raspberry Pi Pico & Rotary Encoder
Next Article Using RC522 RFID Reader Module with Raspberry Pi Pico

Related Posts

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

Updated:July 24, 2025
Interface BMI160 with Raspberry Pi Pico & MicroPython

Interface BMI160 with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Updated:February 2, 202513K
Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Modbus RTU with Raspberry Pi Pico & Micropython

Modbus RTU with Raspberry Pi Pico & MicroPython

Updated:February 2, 20258K
Fever Detector with MLX90640 & OpenCV Raspberry Pi

Thermal Fever Detector with MLX90640 & OpenCV Raspberry Pi

Updated:February 2, 20256K
Add A Comment

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • Half Wave Rectifier Basics, Circuit, Working & Applications
    Half Wave Rectifier Basics, Circuit, Working & Applications
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.