Raspberry Pi Enclosure




Introduction: Raspberry Pi Enclosure

About: I am a graduate student in conservation biology at Clemson University. When I'm not studying in the library or out in the field collecting data, I love designing and building DIY projects!

This instructable has everything you need to build your own 3d printed Raspberry Pi enclosure. This enclosure is for the Raspberry Pi 3 model A+ and uses an Adafruit LED power button with safe shutdown script.

Here's the supplies and tools you'll need:


    • Raspberry Pi 3 model A+ (Adafruit product 4027)
    • The 3d printed enclosure (available as an .stl file below)
    • Adafruit metal momentary button with LED (Adafruit product 560)
    • Adafruit 15mm heatsink (Adafruit product 3082)
    • Jumper wires with .1" female headers (Adafruit product 794)
    • M2.5 by 4mm screws (x4)


    • Soldering iron and solder
    • Scissors
    • A small phillips screwdriver
    • Superglue

    Step 1: Printing the Enclosure

    The enclosure for this project is made from two parts, a lid and a base. Both are available below as .stl files. If you're interested in designing your own Raspberry Pi 3 A+ enclosure in Tinkercad I've also attached an .stl file with just the ports.

    The base is 100 x 100 x 26 mm with 2 mm thick walls. The lid is 2 mm tall and fits flush onto the base. The standoffs for the Pi are 5 mm in diameter and 5 mm tall with 2 mm tapping holes. The rear of the enclosure has fitted through holes for the micro USB, HDMI, and AV ports. The front of the enclosure has a 16 mm hole for the power button. There is no hole for the side USB port, but there is enough room in the enclosure to add a small adapter for wireless accessories.

    I sliced the models in Cura 4.3 using recommended settings for high detail:

    • 0.2 mm layer height
    • 20% grid infill
    • 30 mm/s printing speed
    • automatic support generation enabled
    • 0.5 mm wall thickness
    • brim type skirt

    The parts were printed on a Lulzbot Mini v2 in 2.85 mm PLA, but most 3d printers should be able to handle these prints. If you don't have a 3d printer, the .stl files can be uploaded to Treatstock.com (a 3d printing service) and printed/mailed for about $15 USD. If printed separately, the base takes approximately 5.5 hours and uses 47 g of material, the lid takes 3 hours and uses 27 g of material.

    • 205 c* nozzle temperature
    • 60 c* bed temperature

    Step 2: Installing the Heatsink

    The Raspberry Pi 3 will automatically throttle CPU speed to avoid overheating, so to keep the Pi running at 100% in a sealed enclosure a heatsink is a good idea. This 15 mm tall heatsink from Adafruit (product 3082) has thermal adhesive pre applied to the bottom, just peel and stick.

    Step 3: Installing the Button

    The Adafruit momentary power button (product 559) for this project has a built in LED ring with inline resistor so it can be wired directly to the Pi GPIO pins. The outermost pins are the + and - for the LED and are labeled. The three center pins are a common ground, a normally open pin and a normally closed pin. You'll need to attach 4 wires: + and - for the LED and ground and NO1 for the switch. Simply thread the switch into the enclosure and use the included nut to lock it in place.

    The momentary switch is connected to pin 5 and ground pin 6. The order doesn't matter.

    The + pin from the LED is connected to the serial console TxD pin 8 and the - is connected to ground pin 9.

    See the pinout image for reference.

    Step 4: Installing the Pi

    The Raspberry Pi is held in place using 4 m2.5 screws. The standoffs in the case are 5 mm tall, so you'll need screws that are 3 or 4 mm long. The standoffs have 2 mm tapping holes which is slightly less than the diameter of the screws. They can be threaded by simply screwing into them, just be careful to keep the screw vertical.

    Step 5: Adding the Script

    The Power Button

    In order to use the power button to safely shutdown and turn on the Raspberry Pi you'll need to install a safe shutdown script. Credit for the script goes to Barry Hubbard who wrote the original python code, ETA Prime who popularized this mod on YouTube, and to 8 Bit Junkie who wrote the atomization script.

    In order to install the script, make sure your Pi is connected to wi-fi and enter the terminal. Enter the following commands, and hit enter after each one:

    Curl https://pie.8bitjunkie.net/shutdown/setup-shutdow... --output setup-shutdown.sh

    sudo chmod +x setup-shutdown.sh


    The first line will connect to the 8 bit junkie website and download the shutdown script. The second line sets up the proper chmod to run the script and the third line actually installs the script. For some operating systems the power button is now active. If you are running RetroPie 4.5 or later, there is one additional step to do in terminal:

    Type sudo nano /etc/rc.local to bring up the rc.local file.

    On the line directly above the "exit 0", add python /home/pi/scripts/shutdown.py &

    Press ctrl + x, hit Y to save changes, and hit enter to exit the file.

    Reboot the Pi. The power button should now be functional.

    The LED

    The LED is connected to the serial console GPIO pin which monitors activity. It lights up when the Pi is on, and goes out when the Pi is fully shutdown and safe to unplug. In order to set it up, you'll just need to add a line of code to the boot configuration file:

    Type sudo nano /boot/config.txt to bring up the configuration file.

    Scroll to the bottom and add enable_uart=1

    Press ctrl + x, hit Y to save changes, and hit enter to exit the file.

    Reboot the Pi. The LED should now be functional.

    Step 6: Final Assembly

    You're almost done! Before you finish assembly remember to double check if everything is functional:

    • The power button should both turn on and turn off the Pi
    • The LED should remain lit while the Pi is on and turn off after shutdown
    • The ports on the Pi should line up with the through holes in the enclosure
    • The Pi should be securely mounted on the standoffs
    • Remember to install the micro SD card and test boot the Pi

    If everything looks good then you're ready for the final assembly. The lid for the enclosure is designed to fit flush with the top of the base and uses a guide to keep it lined up with the edges. Simply add a few drops of superglue to the rim of the base and press the lid on top. Clean up any excess glue before it dries and you're done!

    This enclosure can be used in many different ways, but works best for media centers and RetroPie game consoles. I built this enclosure originally as a retro game console using a bluetooth controller and it works great! If you have any questions, feel free to leave a comment. Thanks for reading!

    Be the First to Share


      • Toys & Games Contest

        Toys & Games Contest
      • Home Decor Challenge

        Home Decor Challenge
      • Box Challenge

        Box Challenge



      1 year ago

      does it work with the 3b?


      Reply 1 year ago

      The enclosure will not work with the Raspberry Pi 3 B due to the additional USB and ethernet ports. But, the power button and LED indicator (along with the scripts) should work with any Pi model that has the 40 pin GPIO header.