Close

Door Detection

A project log for TARDIS Themed Board Game Cabinet

Board game cabinet with a Doctor Who TARDIS theme with door sensors, LED strips, roof light and sound

cafelizardocafelizardo 04/04/2022 at 09:220 Comments

The original plan was to use analog inputs to somehow measure the angle of the doors and adjust the audio sound effects on the fly as well as trigger the lights.  Couldn't figure it out so I settled for using Hall effect sensors in the cabinet that are triggered by magnets in the doors.


Code snippet for detecting if any of the 4 doors are open or closed.

const int DOOR_1 = 40;
const int DOOR_2 = 41;
const int DOOR_3 = 42;
const int DOOR_4 = 43;

// live or prototype
int invert = -1;

  // initialize inputs
  pinMode(DOOR_SWITCH, INPUT_PULLUP);
  pinMode(DOOR_1, INPUT_PULLUP);
  pinMode(DOOR_2, INPUT_PULLUP);
  pinMode(DOOR_3, INPUT_PULLUP);
  pinMode(DOOR_4, INPUT_PULLUP);


int getDoorPosition() {
    return 0
        +  1 * (digitalRead(DOOR_1) ^ (1 - invert))
        +  2 * (digitalRead(DOOR_2) ^ (1 - invert))
        +  4 * (digitalRead(DOOR_3) ^ (1 - invert))
        +  8 * (digitalRead(DOOR_4) ^ (1 - invert))
      //+ 16 * (digitalRead(DOOR_SWITCH) ^ (1 - invert))
        ;
}

Discussions