Projects / Automatic sliding door model

Automatic sliding door model

Beginner2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. UNO

    Build the rail and panel

    It should slide by hand.

  2. UNO

    Fit the motor and string

    Pull the panel both ways.

  3. UNO

    Mount the limit switches

    At each end of travel.

  4. UNO

    Wire the L298N and Uno

    Remove the ENA jumper.

  5. UNO

    Test the motor alone

    Short bursts each way.

  6. UNOmotion

    Add the PIR and upload

    Wait for it to settle.

  7. UNO

    Tune the speed and time-out

    Adjust for your door.

In short

How do you build an automatic sliding door model?

A PIR sensor opens a cardboard sliding door with a geared motor and limit switches, like a supermarket door. You need Arduino Uno R3, PIR Motion Sensor HC-SR501, L298N Dual H-Bridge Module, BO motor straight 100 RPM, Limit switch (micro switch with lever) × 2, Battery holder 4 × AA with switch and AA alkaline battery × 4. It takes 7 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
PIR OUTUno D2Motion signal
PIR VCC and GNDUno 5V and GNDPower
Open limit switchUno D3 and GNDDoor fully open (internal pull-up)
Closed limit switchUno D4 and GNDDoor fully closed (internal pull-up)
L298N IN1 and IN2Uno D5 and D6Motor direction
L298N ENAUno D9Motor speed (remove the ENA jumper)
MotorL298N OUT1 and OUT2Door drive
4xAA holder plusL298N 12V terminalMotor power
Battery minusL298N GND and Uno GNDCommon ground

Code

This is a small model of a shop door: a sliding panel of card or foam board on a rail, pulled by a string or a rack by a small geared motor. Two micro switches tell the Uno when the door is fully open or fully closed, so the motor never pushes against the end. The sketch is a four-state machine: closed, opening, open and waiting, and closing. If the PIR sees movement while the door is closing, it reverses at once, just as a real door does. A time-out stops the motor if a limit switch is never reached, which protects the motor and the 4xAA pack when a switch is misplaced or the string jams. Run the motor at moderate speed so a hand caught in the model is not hurt, keep fingers clear of the string and pulley, and never use this idea on a real door that a person or pet could be trapped in. Remove the L298N's ENA jumper so the Uno can set speed. The PIR takes about thirty seconds to settle after power-up. Arduino IDE, board "Arduino Uno".

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// Automatic sliding door model: opens on motion, waits, closes, reopens if motion returns while closing.
// Board: Arduino Uno. Limit switches wired to GND, so LOW means pressed.
const uint8_t PIR = 2, LIM_OPEN = 3, LIM_CLOSED = 4, IN1 = 5, IN2 = 6, ENA = 9;
const int SPEED = 180;                    // 0 to 255
const unsigned long WAIT_MS = 5000, TIMEOUT_MS = 8000;
enum State { CLOSED, OPENING, OPEN_WAIT, CLOSING };
State state = CLOSED;
unsigned long stamp = 0;
void motorStop()  { digitalWrite(IN1, LOW);  digitalWrite(IN2, LOW);  analogWrite(ENA, 0); }
void motorOpen()  { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);  analogWrite(ENA, SPEED); }
void motorClose() { digitalWrite(IN1, LOW);  digitalWrite(IN2, HIGH); analogWrite(ENA, SPEED); }
void setup() {
  pinMode(PIR, INPUT);
  pinMode(LIM_OPEN, INPUT_PULLUP); pinMode(LIM_CLOSED, INPUT_PULLUP);
  pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(ENA, OUTPUT);
  motorStop();
  delay(30000);                           // let the PIR settle after power-up
}
void loop() {
  bool motion = digitalRead(PIR) == HIGH;
  switch (state) {
    case CLOSED:
      if (motion) { motorOpen(); stamp = millis(); state = OPENING; }
      break;
    case OPENING:
      if (digitalRead(LIM_OPEN) == LOW) { motorStop(); stamp = millis(); state = OPEN_WAIT; }
      else if (millis() - stamp > TIMEOUT_MS) { motorStop(); state = OPEN_WAIT; stamp = millis(); }
      break;
    case OPEN_WAIT:
      if (motion) stamp = millis();       // keep it open while someone is there
      if (millis() - stamp > WAIT_MS) { motorClose(); stamp = millis(); state = CLOSING; }
      break;
    case CLOSING:
      if (motion) { motorOpen(); stamp = millis(); state = OPENING; }   // reopen if someone steps in
      else if (digitalRead(LIM_CLOSED) == LOW) { motorStop(); state = CLOSED; }
      else if (millis() - stamp > TIMEOUT_MS) { motorStop(); state = CLOSED; }
      break;
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Wave at the PIRDoor opens and stops at the open switch
Stand still in frontDoor stays open
Walk awayCloses after about five seconds
Wave while closingReverses and opens

If it does not work

Motor runs the wrong way

Swap the two motor wires.

Door never stops

Check the limit switch wiring to GND.

Motor stutters

Weak batteries; use fresh cells.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the automatic sliding door model?

Arduino Uno R3, PIR Motion Sensor HC-SR501, L298N Dual H-Bridge Module, BO motor straight 100 RPM, Limit switch (micro switch with lever) × 2, Battery holder 4 × AA with switch and AA alkaline battery × 4.

How long does the automatic sliding door model take to build?

About 120 minutes for a beginner maker, in 7 steps.

How do I know the automatic sliding door model works?

Wave at the PIR: Door opens and stops at the open switch. Stand still in front: Door stays open. Walk away: Closes after about five seconds.

Motor runs the wrong way: what should I check?

Swap the two motor wires.

Door never stops: what should I check?

Check the limit switch wiring to GND.

Motor stutters: what should I check?

Weak batteries; use fresh cells.