Display Door State on Matrix LED

Make things

Display door state on matrix LED with two obniz Boards. You can know if the door is open or not by the face displayed on the matrix LED at your seat far from the door.

Materials

*Included in the Starter Kit.

How to make

Hardware connection

Connect parts to each obniz Board like the table and the image below by referring to HC-SR04(ultrasonic distance sensor) Library and keyestudio Matix LED with HT16K33 Library.

For the door(obniz1)

obniz1 HC-SR04(ultrasonic distance sensor)
0 GND
1 Echo
2 Trigger
3 Vcc

For your seat(obniz2)

obniz2 Matrix LED with HT16K33
0 GND
1 Vcc
2 SDA
3 SCL

Software

To display illustrations on Matrix LED, draw pixel art on the canvas of HTML in drawOpenFace function and drawClosedFace function. You can display your illustration on the canvas of HTML on the Matrix LED as it is.

Please read Drawing shapes with canvas – Web APIs | MDN for details.

async function drawOpenFace(_ctx, _matrix) {
  await _matrix.clear();
  await _ctx.clearRect(0, 0, _matrix.width, _matrix.height);
  for (let i = 0; i < _matrix.height; i++) {
    _ctx.fillRect(i, 4, 1, 1);
    _ctx.fillRect(i, 7, 1, 1);

    if (i === 0 || i === 7) {
      _ctx.fillRect(i, 0, 1, 1);
      _ctx.fillRect(i, 2, 1, 1);
      _ctx.fillRect(i, 5, 1, 1);
      _ctx.fillRect(i, 6, 1, 1);
    } else if (i === 1 || i === 6) {
      _ctx.fillRect(i, 1, 1, 1);
    } else if (i === 2 || i === 5) {
      _ctx.fillRect(i, 0, 1, 1);
      _ctx.fillRect(i, 2, 1, 1);
    }
  }
  _matrix.draw(_ctx);
}

Program

How to use

Connect power to obniz Board with HC-SR04(ultrasonic distance sensor) and fix the wall to detect the door open like the image below.

Then, connect power to obniz Board with Matrix LED and put on your seat. You can know the door state at your seat far from the door.

(In this way regards the state the door completely open as the open state.)