# Trinket-Powered Conference Room Occupancy Display

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/013/007/medium800thumb/trinket_clip3.jpg?1448311435)

http://youtu.be/q9Uz5PuGDlE

Every facility has a conference room or other meeting space. And when the door is closed, it is always a guessing game whether the room is occupied or not. This inevitably leads to someone opening the door and disturbing what is happening inside. It could interrupt a meeting or spoil an important experiment.  
  
Commercial sensor/indicator combinations can cost over $400 dollars. If you have many rooms, the cost could be prohibitive.  
  
This project started as an inquiry by the Indiana University IT Department who wrote to Adafruit asking if there was a less expensive alternative to commercial units by using Adafruit's Trinket mini-microcontroller. This project is inspired by that inquiry.

![](https://cdn-learn.adafruit.com/assets/assets/000/012/935/medium800/trinket_Project.jpg?1387161606)

# Trinket-Powered Conference Room Occupancy Display

## Build

![](https://cdn-learn.adafruit.com/assets/assets/000/012/927/medium800/trinket_Proto_Box.jpg?1387127726)

The [small weatherproof enclosure](http://www.adafruit.com/products/903) is a good sized enclosure for the project. The [1/2 sized Perma Proto Board](http://www.adafruit.com/products/571) fits inside the box and clears the rounded divots with a bit of modding..   
  
The [2.1mm panel mount barrel jack](http://www.adafruit.com/products/610) is used for power - solder power wires on prior to installation (large lug is positive). Drill a 1/2 inch hole just past the cover hole. The plastic dimple was chisled to fit it in that location. Thread the jack in securing with the included plastic screw ring. A cable gland is used to run the PIR sensor wires through the enclosure keeping things weathertight. Drill a 5/8 inch hole (for the large gland, a smaller if you use the small gland) between the power jack and the other case cover hole. There is a small lip on the case - I dremeled it down a bit to have the gland fit snug. You can run penetrations through the back as an alternative if you want the look to be "cable free".  
  
Best to make mounting holes in the back of the case if needed to screw the case into the wall. This would probably be harder later in the build given the amount of items we are putting in.  
  
The 1/2 Perma Proto is nearly perfect. The corners should be cut just a bit on one side and the hole on that side slightly enlarged to allow it to fit snug screwed on the brass mounting hole. A short M4 screw is fitted in the enlarged hole. The board should be mounted so the screw is in the standoff furthest from the penetrations.

# Wiring Diagrams
  
A passive-infrared sensor (PIR) is the gold standard for tracking movement in a general area. It does not provide distance like ultrasonic or other sensors but can have a wide field of view and good sensitivity to warm bodies.   
  
A Trinket receives the signal from the PIR. When the room is occupied, the sensor tripped, Trinket will display a red X on an Adafruit 8x8 bi-color LED matrix. If there is no movement, a green square is displayed.   
  
The function of a PIR can be found in [this older tutorial by LadyAda](http://www.ladyada.net/learn/sensors/pir.html). Also [Learning Arduino Lesson 17](http://learn.adafruit.com/arduino-lesson-17-email-sending-movement-detector) features this sensor.   
![](https://cdn-learn.adafruit.com/assets/assets/000/012/997/medium800/trinket_Trinket_Occupied_Board_cropann.jpg?1387396364)

![](https://cdn-learn.adafruit.com/assets/assets/000/012/998/medium800/trinket_Trinket_Occupied_Final_mod_crop.jpg?1387396381)

## Populating the Board
You can refer to the Fritzing diagrams on the Overview Page for the parts placement.   
  
I used two pieces of female header, 5 pins each, to mount the Trinket to the board. This allows the Trinket to easily be removed for programming. A 4 position header mounts the display. Another couple pieces of header from the scrap box are used to steady the top end for an even mount. Socket headers are not required but make it very easy to change out components and wire underneath. ![](https://cdn-learn.adafruit.com/assets/assets/000/012/928/medium800/trinket_Board-Buildup.jpg?1387129914)

![](https://cdn-learn.adafruit.com/assets/assets/000/012/929/medium800/trinket_Board-Annotated-Wide.jpg?1387140137)

The wiring is straightforward:

- Pin 0 on Trinket to the display I2C data line  
- Pin 2 on Trinket to the display I2C clock line  
- BAT on Trinket to the + line on the protoboard which is connected to 5 volts  
- GND on Trinket to the - line on the protoboard which is connected to power ground  
- Pin 1 on Trinket is connected to a 1500 ohm resistor to +5 volts (available at Radio Shack, Maker Shed, and other electronics outlets)  
- Pin 1 on Trinket is also connected to the PIR data line (center)  

The red power line on the PIR and display goes to 5 volt + line on the protoboard  
The black ground line on the PIR and display goes to the ground - line on the protoboard  
  
Be sure you interconnect the top and bottom power busses with interconnect wires (towards the left).  
  
I mounted pins to the power lines to plug in the power jack (upper left). I also put pins on power and Trinket Pin 1 to easily connect the PIR wire.  
  
Double check your wiring to the diagrams and pictures.  
![](https://cdn-learn.adafruit.com/assets/assets/000/012/936/medium800/trinket_IMG_2425.jpg?1387161983)

Mount the board inside the enclosure with the screw. If it does not fit, you must take some material off the right ends and enlarge the hole for the screw.  
  
Plug in the power from the power panel mount jack to the + and - on the board. Run a cable from the PIR to the +, -, and Pin 1 on Trinket per the Fritzing diagram. You can now plug the display in.  
  
Leave the Trinket out as we are going to program that next.

# Trinket-Powered Conference Room Occupancy Display

## Code

For Trinket, you need to have a modified Arduino Integrated Development Environment (IDE) to compile and load code. Please see the tutorial [Introducing Trinket](http://learn.adafruit.com/introducing-trinket "Link: http://learn.adafruit.com/introducing-trinket") for the steps necessary to set up your programming environment.

Info: 

Three Arduino libraries are used to facilitate programming:

- The Arduino IDE **Wire** library&nbsp;provides I2C communications between the Trinket and the display. &nbsp;The Adafruit\_LEDBackpack code loads in the Wire library so we do not need to do it in the main sketch unless we want to use I2C communications for other devices.
- The [Adafruit LED Backpack library](https://github.com/adafruit/Adafruit-LED-Backpack-Library "Link: https://github.com/adafruit/Adafruit-LED-Backpack-Library") has routines to talk to the display. &nbsp;This library was updated in 2016 to use the Trinket compatible Wire library.
- The [Adafruit GFX library](https://github.com/adafruit/Adafruit-GFX-Library "Link: https://github.com/adafruit/Adafruit-GFX-Library") is required to accompany the backpack library. The statement to include this library is done in the LEDBackpack library. [Adafruit BusIO](https://github.com/adafruit/Adafruit_BusIO) must also be installed manually if using an older version of the Arduino IDE (pre-1.8.10), newer versions handle this automatically with the GFX library.

Using the Adafruit libraries take up a fair amount of space but simplifies programming.   
  
Please see the Adafruit tutorial [All About Arduino Libraries](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use) for information on adding these libraries to your Arduino environment. Install the libraries into your _arduinosketch_/libraries directory. Restart the IDE to ensure the libraries load.  
  
Cut and paste the following code into your IDE window:

```auto
/*************************************************** 
  Adafruit Trinket-based Room Occupancy sensor and display
  
  Featuring a Trinket 5V and the
  8x8 Bi-color LED Matrix and I2C Backpack
  
  For Trinket, this program is within 120 bytes of the maximum
    code size of 5,310 bytes.  Adding significantly more
    functionality may not be possible.  

Version 2.0 New Wire Library support for newer IDE
            Mike Barela for Adafruit Industries
 ****************************************************/

// The Adafruit_LEDBackpack library will pull in the standard Arduino 
//   Wire library and needs the Adafruit_GFX library to be installed also!
#include "Adafruit_LEDBackpack.h"

const int PIRpin = 1;    // PIR signal pin on Trinket Pin #1
uint8_t pirState = LOW;  // Stores state of the PIR sensor

Adafruit_BicolorMatrix matrix = Adafruit_BicolorMatrix();

void setup() {
  pinMode(PIRpin, INPUT); // Initial state is low
  matrix.begin(0x70);     // pass in the address
}

static const uint8_t PROGMEM   // X and square bitmaps
  x_bmp[] =
  { B10000001,
    B01000010,
    B00100100,
    B00011000,
    B00011000,
    B00100100,
    B01000010,
    B10000001 },
  box_bmp[] =
  { B11111111,
    B10000001,
    B10000001,
    B10000001,
    B10000001,
    B10000001,
    B10000001,
    B11111111 };

void loop() {
  int sense = digitalRead(PIRpin);  // Read PIR Sensor
  if(sense == HIGH) {     // If high and it was low, sensor tripped
    if(pirState == LOW) { //   and we display a red X
      matrix.clear();
      matrix.drawBitmap(0, 0, x_bmp, 8, 8, LED_RED);
      matrix.writeDisplay();
      pirState = HIGH;
    }
  } else {
    if(pirState == HIGH) {  // If low and state was high, sensor set
      matrix.clear();       //  and we sisplay a green box
      matrix.drawBitmap(0, 0, box_bmp, 8, 8, LED_GREEN);
      matrix.writeDisplay();
      pirState = LOW;
    }
  }

}
```

Ensure you set the Arduino IDE as follows:  
  
Tools -\> Board to: Adafruit Trinket 8MHz  
Tools -\> Programmer to: USBtinyISP  
  
Press the verify checkmark icon to verify your code compiles. If it does not, check the code and the libraries. Note there are only a few bytes left in the code space so adding functionality might take up too much space. This includes adding the delay function.  
  
Take your Trinket out of the circuit and plug it into the USB cable.  
  
Then press the Trinket reset button on the board then quickly click the upload icon (right arrow) in the Arduino IDE. This will upload the code to the Trinket.

Danger: 

## Considerations
The code space is very tight using all the libraries. More code space could be obtained by using low level I2C calls. This was done in the [Space Invaders pendant tutorial](http://learn.adafruit.com/trinket-slash-gemma-space-invader-pendant/source-code "Link: http://learn.adafruit.com/trinket-slash-gemma-space-invader-pendant/source-code"). This would require additional work to get the correct calls coded and since this project works great as is, we didn't spend the extra hacking-time! # Trinket-Powered Conference Room Occupancy Display

## Wrap-up 

## Adjustment
The PIR has two adjustment potentiometers on the back.   

1. The first adjusts the sensitivity of the sensor. You should start with a reading towards the "min" side, and adjust clockwise as necessary.  
2. The second adjusts the time the sensor stays "latched" or in the on state. When testing, leave this at the left which is a short time. Adjust clockwise for longer intervals.

![](https://cdn-learn.adafruit.com/assets/assets/000/012/934/medium800/trinket_PIR.jpg?1387160395)

Test the unit by making all the connections and the PIR is pointed away from movement or covered by a cardboard box. The green square should be displayed.

![](https://cdn-learn.adafruit.com/assets/assets/000/012/937/medium800/trinket_IMG_2421.jpg?1387162214)

Move in front of the sensor and the red X should be displayed.

![](https://cdn-learn.adafruit.com/assets/assets/000/012/938/medium800/trinket_IMG_2422.jpg?1387162279)

If the display does not change, check your wiring to the sensor and the potentiometers.  
  
Once it is working, you can adjust the potentiometers to increase sensitivity and/or the delay used.   
  
One programming note: the Arduino delay software routine cannot be used with the libraries as it adds a bit too much code. Try to adjust using the PIR potentiometers.

## Mount
Mount the display box near the entrance to the room monitored. Mount the PIR sensor so it has a "field of view" of a wide area of the inside of the room. For a conference room, the table area would be best (do not aim above peoples heads).  
  
Run power from an outlet to the display box. Ensure you have a 5 volt DC supply.   
![](https://cdn-learn.adafruit.com/assets/assets/000/012/940/medium800/trinket_Room-Layout.jpg?1387163027)

If you only want the display to show through the clear cover, you can make a mask from white paper. You can have the LED display show through the paper or cut out a square just for the display.

http://youtu.be/q9Uz5PuGDlE


## Featured Products

### Adafruit Trinket - Mini Microcontroller - 5V Logic

[Adafruit Trinket - Mini Microcontroller - 5V Logic](https://www.adafruit.com/product/1501)
 **Deprecation Warning: The Trinket bit-bang USB technique it uses doesn't work as well as it did in 2014, many modern computers won't work well. So while we still carry the Trinket so that people can maintain some older projects, we no longer recommend it.** <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1501)
[Related Guides to the Product](https://learn.adafruit.com/products/1501/guides)
### Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack

[Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack](https://www.adafruit.com/product/902)
What's better than a single LED? Lots of LEDs! A fun way to make a small colorful display is to use a [1.2" Bi-color 8x8 LED Matrix](http://www.adafruit.com/products/458). Matrices like these are 'multiplexed' - so to control all the 128 LEDs you need 24 pins....

In Stock
[Buy Now](https://www.adafruit.com/product/902)
[Related Guides to the Product](https://learn.adafruit.com/products/902/guides)
### PIR (motion) sensor

[PIR (motion) sensor](https://www.adafruit.com/product/189)
PIR sensors are used to detect motion from pets/humanoids from about 20 feet away (possibly works on zombies, not guaranteed). This one has an adjustable delay before firing (approx 2-4 seconds), adjustable sensitivity **and** we include a 1 foot (30 cm) cable with a socket so you...

In Stock
[Buy Now](https://www.adafruit.com/product/189)
[Related Guides to the Product](https://learn.adafruit.com/products/189/guides)
### Adafruit Perma-Proto Half-sized Breadboard PCB - 3 Pack!

[Adafruit Perma-Proto Half-sized Breadboard PCB - 3 Pack!](https://www.adafruit.com/product/571)
Customers have asked us to carry basic perf-board, but we never liked the look of most basic perf: its always crummy quality, with pads that flake off and no labeling. Then we thought about how people **actually** prototype - usually starting with a solderless breadboard and then...

Out of Stock
[Buy Now](https://www.adafruit.com/product/571)
[Related Guides to the Product](https://learn.adafruit.com/products/571/guides)
### 5V 2A (2000mA) switching power supply - UL Listed

[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)
This is an FCC/CE certified and UL listed power supply. Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 2000mA. 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one...

In Stock
[Buy Now](https://www.adafruit.com/product/276)
[Related Guides to the Product](https://learn.adafruit.com/products/276/guides)
### Small Plastic Project Enclosure - Weatherproof with Clear Top

[Small Plastic Project Enclosure - Weatherproof with Clear Top](https://www.adafruit.com/product/903)
Store your project safe and sound in this nice weatherproof box with a clear top. We picked up this box because we like the machinable ABS plastic body and tough clear polycarbonate cover, the built in weatherproof gasket seal, and the easy-open screws that can be taken apart as many times as...

In Stock
[Buy Now](https://www.adafruit.com/product/903)
[Related Guides to the Product](https://learn.adafruit.com/products/903/guides)
### Panel Mount 2.1mm DC barrel jack

[Panel Mount 2.1mm DC barrel jack](https://www.adafruit.com/product/610)
This power jack is designed to easily attach to a panel up to 8mm thick (0.315" or 5/16") and fit 2.1mm power plugs snugly and securely. Perfect for adding a power connector to your project enclosure. We like this jack in particular for its long body (so you can use it on thicker...

In Stock
[Buy Now](https://www.adafruit.com/product/610)
[Related Guides to the Product](https://learn.adafruit.com/products/610/guides)
### Cable Gland PG-9 size - 0.158" to 0.252" Cable Diameter

[Cable Gland PG-9 size - 0.158" to 0.252" Cable Diameter](https://www.adafruit.com/product/761)
We have some great [waterproof and weather-proof items in the adafruit shop](https://www.adafruit.com/?q=waterproof&), but once you have a project built, you'll want to enclose it. But how to keep an enclosure weather/waterproof while still attaching cables for power, data...

In Stock
[Buy Now](https://www.adafruit.com/product/761)
[Related Guides to the Product](https://learn.adafruit.com/products/761/guides)

## Related Guides

- [Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack.md)
- [PIR Motion Sensor](https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor.md)
- [Trinket Powered Analog Meter Clock](https://learn.adafruit.com/trinket-powered-analog-meter-clock.md)
- [Secret Knock Activated Drawer Lock](https://learn.adafruit.com/secret-knock-activated-drawer-lock.md)
- [Introducing Trinket](https://learn.adafruit.com/introducing-trinket.md)
- [Ninja Timer: Giant 7-Segment Display](https://learn.adafruit.com/ninja-timer-giant-7-segment-display.md)
- [Reverse Geocache Box](https://learn.adafruit.com/reverse-geocache-engagement-box.md)
- [Galaxy Pendant](https://learn.adafruit.com/life-proof-led-necklace.md)
- [Pro Trinket as a USB HID Mouse](https://learn.adafruit.com/pro-trinket-usb-hid-mouse.md)
- [Breadboards for Beginners](https://learn.adafruit.com/breadboards-for-beginners.md)
- [Trinket RGB Shield Clock](https://learn.adafruit.com/trinket-rgb-shield-clock.md)
- [NeoPixel Bracelet](https://learn.adafruit.com/neopixel-bracelet.md)
- [Collin's Lab: Breadboards & Perfboards](https://learn.adafruit.com/collins-lab-breadboards-and-perfboards.md)
- [3D Printed Camera LED Ring](https://learn.adafruit.com/3d-printed-camera-led-ring.md)
- [3D Printed LED Knuckle Jewelry ](https://learn.adafruit.com/3d-printed-led-knuckle-jewelry.md)
- [3D Printed Adabot Figurine](https://learn.adafruit.com/3d-printed-adabot-figurine.md)
- [3D Printed Daft Punk Helmet](https://learn.adafruit.com/3d-printed-daft-punk-helmet.md)
