Hello friends, I hope you all are doing great. Today, I am going to share the new MC-38 Door Sensor Library for Proteus Simulation. The MC-38 is the little pair of white plastic blocks on almost every alarmed door and window: one block with a reed switch and two wires on the frame, one block with a magnet on the door. Shut the door and the magnet closes the switch; open it and the switch opens. It is the simplest, cheapest and most reliable security sensor there is. With this library you can run a full Proteus simulation of the contact, bounce and all, so that your door alarm logic is right before you drill a single hole.
MC-38 Door Sensor Library for Proteus
Latest version: V1.0 (November 2026, this tutorial)
Other security sensors: PIR Sensor · Magnetic Reed Switch · A3144 Hall Sensor · SW-420 Vibration Sensor
Helping Tools
- Serial Monitor Advance: a serial terminal window for the UART of your board
- Serial Monitor Expert: the serial monitor with extra debugging tools
- LCD Library for Proteus V3.0: 16x2, 20x4 and I2C LCDs to show your readings
The contact comes alive at run time: through a window in its body you see the two reeds touch or spring apart, and its LED shows green with the door shut and red when it opens. The demo is a door monitor: an Arduino watches a door being opened, left open, closed, and quickly opened and closed again; it counts and times the openings, warns when the door is left open, and shows it all on an OLED with a SHUT and an OPEN LED.
NOTICE: Our team has put a lot of effort into these small parts: the bodies, the animation and the pop-ups are all our own design, and you get them free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below or in the PIR sensor board of our forum. And if our free libraries help you, you can buy us a coffee. So, let's get started with the MC-38 Door Sensor Library for Proteus Simulation:
How Does a Magnetic Door Contact Work?
Inside the switch body sits a reed switch: two thin, springy strips of nickel-iron sealed in a small glass tube, their tips overlapping with a tiny gap. On their own they stay apart. Bring a magnet close and its field magnetises the two reeds with opposite poles at their tips; they attract and snap together, closing the circuit. Take the magnet away and they spring apart. Mount the switch on the door frame and the magnet on the door, side by side when the door is shut, and you have a door sensor: closed when the door is shut, open when it opens.
| MC-38 magnetic door / window contact | |
|---|---|
| Parts | a switch body (27 x 14 mm) with two wires, a magnet body (27 x 10 mm) |
| Contact | a reed switch: closed with the magnet near, open when it moves away |
| Gap | switches at roughly 15 - 25 mm, with a little hysteresis |
| Supply | none - a dry contact (up to about 100 V, 0.5 A) |
| Wiring | one wire to an input with a pull-up, one to GND: LOW = shut, HIGH = open |
| Uses | burglar alarms, door-open alerts, windows, garages, cabinets, fridges |
Closed Means Safe
The MC-38 is wired so that a shut door is a closed circuit. That is deliberate: if a burglar cuts the wire, or it simply breaks, the alarm sees an open circuit - exactly what an open door looks like - and raises the alarm. A sensor that only spoke up when something happened could be silenced with a pair of cutters; this one fails safe.
Bounce
A reed switch is a mechanical contact, and when the reeds snap together they bounce: they touch, spring apart for a moment and touch again. A sketch that reacts to every change would count one door closing as two or three. The cure is a debounce - only trust a change once the input has held its new level for a few tens of milliseconds. Our model gives every closing one 1 ms bounce, so the demo has something to cure.
Features of the MC-38 Door Sensor Library for Proteus Simulation
- A real-looking contact: the white switch body at its real size with its screw holes and two wires, and the magnet body beside it, as on a shut door.
- Animated: a window onto the glass reed where the reeds touch or spring apart, and a status LED - green shut, red open (both our additions).
- A real reed: closed under a 15 mm gap, open over 20 mm, holding its state between, with a bounce on every closing.
- A dry contact: pins 1 and 2 are a switch, 0.1 ohm closed and 100 Mohm open, needing a pull-up like the real one.
- A scene: the door opened, left open, closed, and a quick open-close, plus chips for shut, ajar at 10 or 18 mm, open and wide open.
- A pop-up: the door seen from above swinging on its hinge, the gap with the closing and opening gaps and the reed over the run, eight live tiles, graphs, an event log and a check page.
- A complete package: about 2.3 MB with the library, our OLED, 5 mm LED and resistor libraries, our Arduino UNO V4.0 and the demo, without the source code of the model.
The MC-38 in Proteus
The device is DOORMC38TEP in TEPMC38.LIB, under Sensors > Magnetic, with the prefix U and the model TEPMC38.DLL. Search MC38 or door in Pick Devices. Two pins along the bottom: 1 and 2, the two ends of the reed switch - either way round. Its properties: PROFILE (DEMO or STEADY) and GAP (mm, for STEADY).
Download MC-38 Door Sensor Library for Proteus Simulation
Click the button below to download MC-38-Door-Sensor-Library-for-Proteus-v1.0.zip (about 2.3 MB, without the source code of the models):
MC-38 Door Sensor Library for Proteus V1.0- README.txt: installation, the demo, the wiring, troubleshooting and the limits of the simulation.
- Proteus Library Files:
TEPMC38.LIB,TEPOLED12864.LIB,TEPLED5MM.LIB,TEPRESISTOR.LIBandArduinoV4TEP.LIB. - Proteus Model Files:
TEPMC38.DLL,TEPOLED.DLL,TEPLED5MM.DLL,TEPRESISTOR.DLLandTEPARDUINO.DLL. - Arduino Code: the demo sketch (no extra library).
- Proteus Simulation: the demo project, its HEX file and copies of the DLLs.
No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.
How to Install MC-38 Door Sensor Library for Proteus Simulation
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy the files from Proteus Model Files into the MODELS folder.
- Delete
TEPMC38.IDXfrom the LIBRARY folder if it is there. - Start Proteus, press P and search for MC38.
Proteus Simulation of a Door Monitor
Our demo watches a door. U1 is the MC-38 with PROFILE DEMO: the door shut, opened at 2 seconds until the magnet is 120 mm away, left open, closed at 7 seconds, and opened and closed quickly at 10 seconds. Pin 2 goes to D2 of our Arduino UNO Library for Proteus V4.0 and pin 1 to ground; R1, 10 k, pulls D2 up to 5 V (the sketch also turns on the UNO's own pull-up). Our OLED SSD1306 Library for Proteus shows the door's state, and two LEDs from our 5mm LED Library for Proteus sit beside it: SHUT (green, D5) and OPEN (red, D6), each through 220 ohm. The Arduino's built-in monitor is the same window as our TEP Serial Monitor Advance for Proteus. Open MC38-Door-ArduinoUnoV4.pdsprj.
The Sketch
The sketch needs no library. The contact goes between D2 and ground, with the pull-up turned on, so a shut door reads LOW and an open door HIGH:
pinMode(PIN_DOOR, INPUT_PULLUP); // the reed to GND: LOW = shut, HIGH = open
Every change of the raw input restarts a timer - and every fall back to LOW while the door is closing is a bounce the sketch counts:
if (r != raw) { raw = r; rawSince = now; if (!r) bounces++; }
Only when the input has held its new level for 30 ms does the door's state change - that is the debounce:
if (raw != open_ && now - rawSince >= DEBOUNCE) { // the new level has held for 30 ms: a real change
Each opening is counted and timed, and when the door stays open for more than three seconds the sketch warns once:
if (open_ && !warned && now - openedAt > LEFT_OPEN) { warned = true; Serial.println(F("WARNING: the door has been left open")); }
The OPEN LED lights while the door is open and starts to blink once it has been left open:
digitalWrite(LED_OPEN, open_ && (!warned || (now / 250) % 2)); // blinks once the door is left open
The OLED shows SHUT or OPEN in big letters, how long the door has been open, the openings, the last opening's length and LEFT OPEN.
MC-38 Simulation Results
Open the project and press Run. The demo runs 12.5 simulated seconds and took about 3 minutes on our PC with the pop-up open and the pictures being taken. Click the contact for its pop-up. Every number below comes from one simulation run, the demo exactly as it ships.
The Door Shut
The demo starts with the door shut: the magnet 2 mm from the switch, the reed closed with 0.00 V across it, and D2 held LOW through it. The monitor prints "The door is shut", the OLED says SHUT and the green SHUT LED is lit. On the sheet the contact's own LED is green and, in its window, the two reeds touch.
The Door Opens
At 2 seconds the door starts to open and swings out to 120 mm within a second. The reed holds on while the gap grows and opens only when the gap passes 20 mm, at 2.247 seconds; D2 goes HIGH through the pull-up. The sketch waits out its 30 ms debounce, prints "Door OPENED (opening 1)", lights the red OPEN LED and starts timing; at 2.5 seconds the gap was 59.7 mm. The door then stays open. Three seconds after it opened, the sketch prints "WARNING: the door has been left open" and the OPEN LED starts to blink. When the run paused at 5.5 seconds, the OLED read OPEN, OPEN FOR 3.0 S, OPENINGS 1 and LEFT OPEN, and the pop-up had timed 3.24 s open with the door wide at 120 mm.
The Door Closes
At 7 seconds the door closes. At 7.6 seconds it was still 61.7 mm away and the reed stayed open; it closed only when the gap was back under 15 mm, at 7.952 seconds - 5 mm nearer than where it had opened, which is the hysteresis at work in the simulation. As the reeds snap together they bounce once, and the pop-up counts that bounce. The sketch, which waits for 30 ms of steady level, ignores it and prints "Door SHUT after 5.71 s" - exactly the time the pop-up measured between the opening and the closing.
A Quick Open and Close
At 10 seconds the door is opened a little and closed again: the gap rises to 60 mm and falls back within 1.2 seconds. The reed opens at 10.121 seconds and closes at 11.114 seconds, 0.99 s later. The sketch prints "Door OPENED (opening 2)" and then "Door SHUT after 1.00 s" - far too short for the left-open warning. That second closing bounced too, so the pop-up ends the run with two bounces, both ignored by the debounce.
The Graphs, the Event Log and the Check Page
The Graphs page plots the gap, the reed, the voltage across it and the openings. The Event log keeps every opening and closing with the gap at that moment. The Check page sums up the run: the door shut with the gap at 2 mm (closed under 15 mm, open over 20 mm), the reed closed with 0.00 V across it and one bounce on each closing (two in all), and 2 openings with 6.7 s open in all, the last 0.99 s - every row green.
The monitor shows the sketch's side: each opening, each closing with its length, and the warning.
A Door Contact, a PIR or a Hall Switch?
A door contact knows one thing for certain: this door is open. A PIR sensor - our PIR Sensor Library for Proteus - sees a warm body moving in a room, whichever way it came in. Together they are the two halves of every burglar alarm. If you need a magnet-worked switch that never wears out and switches in microseconds, for counting turns rather than guarding doors, a Hall switch like the one in our A3144 Hall Sensor Library for Proteus is the electronic cousin of the reed. And our older Magnetic Reed Switch Library for Proteus (2018) shows the bare reed switch on its own.
Try It Yourself
- Click Ajar 18 mm from shut: the reed stays closed - between the 15 and 20 mm gaps it holds its state.
- Then click Open 50 mm and back to Ajar 18 mm: now it stays open - the hysteresis.
- Remove the debounce from the sketch: each closing's bounce counts as an extra opening.
- Change LEFT_OPEN to 10 seconds: the 5-second opening no longer raises the warning.
- Pull the wire off D2 in your mind: with the pull-up the input reads HIGH - an open door. That is the alarm failing safe.
Ideas to Extend the Demo
- A burglar alarm: arm it with a keypad, give a 10-second entry delay, then sound a siren.
- A fridge-door alarm that beeps after 30 seconds open.
- Count the shop door's openings per hour and log them.
Your Own Sketches
The demo sketch is in the zip file, and you can change it in the Arduino IDE. New to Arduino? Start with our Arduino Tutorial for Beginners. Export the compiled binary, and set the UNO's PROGRAM property to the new file. Our guide on How to get the HEX file from Arduino shows you where the file ends up.
Things to Know Before Using a Real MC-38
- Alignment: mount the switch on the frame and the magnet on the door, side by side and within about 10 mm when the door is shut.
- Steel doors: steel weakens the field - use a contact made for steel doors, or space it off with plastic.
- Debounce: 20 - 50 ms in the sketch; the reed bounces as it closes.
- Fail safe: keep the "closed = shut" wiring; a cut wire then looks like an open door.
- Long wires: a long run picks up noise - a small capacitor across the input, or a lower pull-up, helps.
Troubleshooting
- It always reads open: no pull-up, the wire not on GND, or the magnet too far from the switch.
- It always reads shut: the input floats low without a pull-up, or the magnet is stuck next to the switch.
- An opening counts twice: no debounce on the closing.
- It switches late: the gap between the parts is too big when the door is shut.
- The part is not simulated:
TEPMC38.DLLis missing from MODELS and from the project folder.
Limitations of the Simulation
- The reed closed near the magnet and open away from it, with its hysteresis and a bounce on closing, follows the way these contacts behave; the contact is our own drawing.
- Our own choices: the 15 / 20 mm gaps, the 0.1 ohm / 100 Mohm, the 1 ms bounce, the door's swing, the reed window and the LED.
- Not modelled: a steel door, the angle between the parts, wear and the contact's current rating.
- Arduino is a name of Arduino; this library is not made or endorsed by Arduino, Labcenter or any maker of door contacts.
- Tested in Proteus 8.5 in November 2026 (the demo as shipped). Proteus 7 is not supported.
So, that was all about the MC-38 Door Sensor Library for Proteus Simulation. I hope it helps you build your door alarm, your fridge reminder or your shop counter before a single hole is drilled - and shows that security can start with two plastic blocks, a magnet and a pull-up. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!