Motion Sensitive Doors

August 2007



The doors themselves are very straightforward: DoorAssembly.ldr

The frame containing the doors is a bit tricky to build: Doors.ldr

The step-by-step building instructions for the frame.


I decided to use a state machine implementation for the door controller. Apart from opening when a person approached, I didn’t want the doors to close when someone was about to walk through them. While it is possible to write this simple algorithm as straight C code, I thought it might be better to experiment a bit.

The state transition diagram contains four states:

  1. 1.DoorsClosed - the doors have been closed

  2. 2.DoorsOpening - the doors are in the process of opening

  3. 3.DoorsOpen - the doors are now open

  4. 4.DoorsClosing - the doors are in the process of closing

In reading a state transition diagram the arrows between the states indicate what condition holds and what action must be taken. So to transit from the DoorsClosed state to the DoorsOpening state the condition states that the person sensor must be triggered and the action states that the motor must be set to open the doors. A key transition is from the DoorsClosing state to the DoorsOpening state; if the doors are closing and a person walks in front of them then the doors will re-open to avoid crushing the person!

The RobotC Source code for the automatic shop doors is available. You’ll notice that the state machine is encoded using a C switch() statement with each state being a case in the switch. The conditions on the edges in the state graph are if() statements and the actions are taken in the body of the if block. This makes it very simple to convert a state diagram into code and ensure that you have not forgotten any state transitions!

The following wiring connections are assumed:

1.Port A: legacy LEGO mindstorms motors

2.Port 1: door open sensor

3.Port 2: ultrasonic sensor

4.Port 3: door closed sensor



Normal operation of the doors

But sometimes the doors get jammed!

Last updated 23 May, 2008

All content © 2008 Mark Crosbie

LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this site. This site, its owner and contents are in no way affiliated with or endorsed by the LEGO Group. For more please read the LEGO Fair Play policy.

An example of coding a state-machine to manage the operation of an everyday device; automatic doors. You know the type; you walk up and the door opens before you, and hopefully doesn’t close on top of you! This is a one-way only door as I only have one ultrasonic sensor to detect when someone approaches the door. I’ve deliberately left the mechanisms exposed so you can see how it all works. The biggest challenge was in constructing the door frame to allow the doors to slide on it. I’m still not entirely satisfied with the movement of the doors. The doors are made from LEGO train window parts.