Arduino Garage Door Sensor: How to Build, Wire and Fix One

You are currently viewing Arduino Garage Door Sensor: How to Build, Wire and Fix One

An Arduino garage door sensor is a do-it-yourself door monitor: a small microcontroller board, usually an Arduino or a Wi-Fi board like the ESP32, reading a magnetic switch that tells it whether the garage door is open or closed. It isn’t a garage door brand, and it isn’t the pair of safety eyes near the floor. This guide covers what to build, how to wire it, and how to fix the problems these projects run into most.

Short Answer: Mount a magnetic reed switch on the door frame and its magnet on the door, wire one lead to a digital pin and the other to ground, and set the pin to INPUT_PULLUP. False readings usually mean a floating pin, contact bounce or a magnet set too far away. A relay can’t trigger openers with a yellow learn button.

Last verified: November 16, 2026, against Arduino’s digital pin and digitalRead documentation, Chamberlain’s door control troubleshooting page, and ratCloud’s ratgdo product page. How we research.

What an Arduino Garage Door Sensor Is, and What It Isn’t

The sensor itself is simple. A reed switch is two thin metal contacts sealed in a small case. When a magnet comes close, the contacts touch and the circuit closes; when the door moves the magnet away, it opens again. The board watches that switch and does something with the result: lights an LED, sounds a buzzer, or sends a phone alert over Wi-Fi.

Arduino board on a breadboard with jumper wires and a lit LED

What it isn’t: the safety reversing sensors, the two small “photo eyes” near the floor that stop a closing door when something crosses the beam. Those belong to your opener, and your opener won’t close the door without them. If your door won’t close and a light on one of those eyes is blinking, skip to the last section, because that’s a different problem with a different fix.

Parts You Need

A basic open-or-closed monitor needs very little. The choice that matters most is the board: a plain Arduino Uno or Nano is fine for an LED or buzzer in the garage, but if you want a phone alert you need a board with Wi-Fi.

PartWhat it doesNotes
Arduino Uno or NanoReads the switch, drives an LED or buzzerNo Wi-Fi on its own
ESP32 or ESP8266 boardSame job, plus Wi-Fi for phone alertsMost garage projects end up here
Magnetic reed switch and magnetDetects the closed positionGarage-rated “overhead door” contacts tolerate a wider gap than small hobby switches
Second reed switch (optional)Detects the fully open positionLets you tell open, closed and stuck halfway apart
Two-conductor wire, 5V USB supplyConnects the switch and powers the boardKeep the wire run short or twisted

Some builders use an ultrasonic distance sensor on the ceiling instead of a reed switch, reading whether the door panel is overhead. It works without touching the door, but a reed switch is cheaper, simpler and far less fussy, so start there.

How to Wire and Code the Reed Switch

Mount the reed switch on the door frame near the bottom or top of the opening, and the magnet on the door so the two line up when the door is fully closed. Then run one lead of the switch to a digital pin and the other to GND. No resistor is needed if you use the board’s built-in pull-up.

White magnetic reed contact mounted on a garage door frame with its magnet on the door

Arduino’s documentation explains why that pull-up matters. A pin set to plain INPUT with a loose wire attached “will report seemingly random changes in pin state” from electrical noise. Setting the pin to INPUT_PULLUP turns on an internal resistor, which Arduino says is between 20k ohm and 50k ohm on most AVR boards, and the other side of the sensor goes to ground. The pin then reads HIGH when the switch is open (door up) and LOW when the magnet closes it (door down).

A minimal sketch that prints one message each time the door changes state, with a short debounce so a single closing doesn’t register several times:

const int DOOR_PIN = 2;
int lastState = -1;

void setup() {
  Serial.begin(9600);
  pinMode(DOOR_PIN, INPUT_PULLUP);   // switch between pin 2 and GND
}

void loop() {
  int state = digitalRead(DOOR_PIN); // LOW = magnet near = door closed
  if (state != lastState) {
    delay(50);                       // let the contacts settle
    if (digitalRead(DOOR_PIN) == state) {
      Serial.println(state == LOW ? "Door closed" : "Door open");
      lastState = state;
    }
  }
}

If your readings come out backwards, you have a normally closed switch rather than a normally open one. Swap the two messages in the code; the wiring stays the same.

Can the Arduino Open and Close the Door Too?

Monitoring is the easy half. Controlling the door is where most projects stall, and the reason is printed on the opener: the color of its learn button.

Chart: a relay will not trigger a yellow learn button Security+ 2.0 opener, but usually works on older openers with other learn button colors

On many older openers the wall button is a plain switch: pressing it briefly connects two wires. A relay module wired across those two terminals does the same thing, so the board can “press the button” for you. Chamberlain and LiftMaster openers with a yellow learn button use Security+ 2.0, and their wall controls send coded data instead. Chamberlain’s own troubleshooting page says that touching the wires together on these encrypted serial door controls will not activate the opener, which is exactly what a relay does. So the relay clicks and nothing happens.

Your options on a yellow-button opener:

  • A Security+ 2.0 board. ratgdo, sold by ratCloud, is an ESP-based board that speaks the opener’s protocol. Its maker says it controls the door, light and lock on yellow-button openers, reads the door’s position, and works locally with no subscription.
  • A spare remote. Hobbyists wire a relay across the button of a spare Security+ 2.0 remote so the board “presses” it. It works but needs soldering and a battery or power supply for the remote.
  • An off-the-shelf hub. If you’d rather not build anything, a myQ hub or a meross controller does the same job; our garage door monitor comparison covers them.

Two safety rules apply to any build that can close the door. Closing a door you can’t see is what door makers call unattended close, and Chamberlain’s manuals limit it to sectional doors, not one-piece doors. And never wire anything into the safety sensor terminals or jumper them out: those eyes are what stop the door on a child, a pet or a car. Our guide on why a doorbell button won’t work as a garage door button covers the wall-terminal side in more detail.

Arduino Garage Door Sensor Not Working? Common Faults and Fixes

Most problems with these builds come down to a handful of causes. Work down the table from the top; the first two cover the majority of “it says open when it’s closed” complaints.

Hands testing a garage door reed switch with multimeter probes while the magnet sits on the door edge
What you seeLikely causeFix
Readings flicker between open and closed with nothing movingFloating input pin or electrical noise on a long wireUse INPUT_PULLUP (or a 10k ohm external pull-up), shorten or twist the wire, keep it away from the opener’s power cord
Reads “open” even though the door is shutMagnet too far from the switch, or misalignedClose the door and move the magnet until it sits within the switch’s rated gap; use a garage-rated contact for wide gaps
Several alerts every time the door closesContact bounceAdd a debounce delay or state-change check, as in the sketch above
Reads “closed” when the door stopped a few inches shortOne switch can only see one positionAdd a second switch at the fully open position, or move the closed switch so it only triggers at the very bottom
Alerts stop for hours, then come backWeak Wi-Fi in the garage; metal doors block signalCheck signal where the board sits, move it toward the house, add an extender, or use a board with an external antenna
Relay clicks but the door doesn’t moveYellow learn button (Security+ 2.0)Use a Security+ 2.0 board or a spare remote, as described above
Door won’t close at all after you installed the projectWires landed on the safety sensor terminals, or a safety eye got knockedDisconnect your project wires from the opener and check the photo eyes

To check the switch itself, set a multimeter to continuity and touch the probes to the switch’s two terminals with the door closed. It should beep (closed circuit) with the magnet near and go silent when you open the door. If it never changes, the switch or magnet is the problem, not your code. The fault homeowners hit most often with these builds is simply magnet distance: a switch that works on the bench can fail on a door that closes a little differently each time.

If You Meant the Opener’s Safety Sensors

If you searched for this because your garage door won’t close and a sensor light is blinking, the problem is your opener’s safety eyes, not an Arduino. Those are fixed by cleaning the lenses, realigning the two eyes until both lights are steady, shading the receiver from low sun and checking the wires.

Garage door safety sensor mounted low on the door track
A safety reversing sensor mounted near the floor. Still from “Replace Garage Door Sensors Quickly and Easily” by Dan Jiles, licensed CC BY 3.0.

Our step-by-step guide on how to fix a garage door sensor covers every major brand, and if you have a Genie, our page on a Genie sensor blinking red explains each blink count.

Frequently Asked Questions

Do I need a resistor for a reed switch on an Arduino?

Not if you set the pin to INPUT_PULLUP. That turns on a resistor built into the chip, and you wire the switch between the pin and ground. If you use plain INPUT instead, add an external pull-up or pull-down resistor; Arduino’s documentation suggests 10k ohm as a good value. Without one, the pin floats and gives random readings.

Can an Arduino garage door sensor work with myQ?

Not directly. myQ is Chamberlain’s cloud service, and a homemade sensor can’t join it. You can run your own sensor alongside a myQ opener, since the reed switch only watches the door. For control as well as status on a yellow-button myQ opener, a Security+ 2.0 board such as ratgdo is the route most builders take.

Is it safe to control a garage door with an Arduino?

Monitoring is completely safe because the board only reads a switch. Control is safe as long as the opener’s own safety system stays in charge: leave the photo eyes and their wiring alone, test that the door still reverses on an obstruction, and only close the door remotely if it’s a sectional door, as the opener manuals require.

Garageblog Team

The My Garage Blog editorial team researches garage door opener problems using manufacturer owner's manuals, official support pages and published standards, and writes step-by-step guides with the sources linked. We are researchers, not licensed technicians. See how we research: https://mygarageblog.com/how-we-research/

Leave a Reply