Contact Sensor (MC-38) Tutorial for ESP8266, ESP32, Raspberry Pi Pico W

In this section, we will show you how to create a contact sensor (also known as a door sensor, entry sensor, or window sensor) using an ESP32, ESP8266 or Raspberry Pi Pico W, and then view the open/close state in Alexa, Google Home, SmartThings, or the Sinric Pro app.

Sinric Pro contact sensor tutorial

Prerequisites :

  1. ESP32, ESP8266 or Raspberry Pi Pico W x 1.
  2. Contact Sensor (MC-38) x 1.
  3. Jumper Wires.

Quick introduction to Contact Sensor

A contact sensor is a device that detects whether a door, window, or other object is open or closed. A contact sensor comprises two components – a sensor and a magnet – used to determine the status of objects such as doors or windows, whether they are open or closed.

Sinric Pro Contact Sensor Reed Switch Open Close

The sensor is affixed to the frame of the sliding window, while the magnet is attached to the window itself. When the sliding window is shut, the magnet comes into proximity with the sensor, establishing a connection between the two components. Conversely, when the sliding window is opened, the magnet moves away from the sensor, breaking the connection between them.

Wiring Contact Sensor

Sinric Pro contact sensor wiring

Note: We are using INPUT_PULLUP instead of connecting a 10kΩ resistor between the reed switch and GND.

MCU GPIO Pin
ESP32 19
ESP8266 4 (D2)
Pico W GP5

Let’s verify that contact sensor is wired correctly and working.

Step 1 : Create a new Contact Sensor in Sinric Pro

Sinric Pro create device alexa

Sinric Pro temperature sensor device notifications

You can enable toggles for Open, Close here to receive a push notification via the Sinric Pro app when the contact sensor state change between Open or Close.

Sinric Pro copy device id

Step 2 : Connect to Sinric Pro

Step 2.1 Install Sinric Pro Library

Sinric Pro install SinricPro library

You can generate the code using Zero Code feature or write it by your self. If you do not have programming experice, we recommend to use Zero Code feature in the Portal to generate the code, download and flash.

2.2 Complete Code

Now you should be able to see the contact state via Alexa, Google Home, SmartThings and Sinric Pro App

Sinric Pro Alexa Contact Sensor

Troubleshooting

  1. Please refer to our Troubleshooting page for more details.

This document is open source. See a typo? Please create an issue