# Close Encounters Hat

## Overview

http://youtu.be/Wuqd7JNdLTY

The Close Encounters hat is a nod to the incredible movie -- with lights and sounds that mimic the mother ship, all stowed under the brim. A photocell triggers the action for GEMMA, while the NeoPixels and piezo buzzer provide the show. Get ready to change up that next kiss or rock a dark movie theater.

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/018/271/medium800/sensors_HAT.jpg?1405998092)

# Close Encounters Hat

## Tools and Supplies

![](https://cdn-learn.adafruit.com/assets/assets/000/017/878/medium800/sensors_Hat_Supplies.jpg?1404776641)

If you order the [GEMMA Sensor Pack](http://www.adafruit.com/product/1849), you'll have most everything you need. The one exception is the amount of NeoPixels. Since there are five lights/sounds for Close Encounters, you may want to purchase 6 additional NeoPixels to supplement the 4 that come with the kit. That way you'll have lights for the front and back of your hat.  
  
This intermediate level wearables project requires some soldering and sewing. We recommend checking out the following guides before you begin:

- [Adafruit Guide To Excellent Soldering](../../../../adafruit-guide-excellent-soldering "Link: https://learn.adafruit.com/adafruit-guide-excellent-soldering")
- [Adafruit NeoPixel Überguide](../../../../adafruit-neopixel-uberguide "Link: https://learn.adafruit.com/adafruit-neopixel-uberguide")
- [Introducing GEMMA](../../../../introducing-gemma)&nbsp;or&nbsp;[Introducing Gemma M0 guide](../../../../adafruit-gemma-m0/)

Make sure you have the Adafruit Arduino software installed for GEMMA, or hop on [Codebender](../../../../flora-and-codebender).  
  
For this project you'll need:

- [Gemma M0](https://www.adafruit.com/product/3501)&nbsp;or&nbsp;[Original Gemma](http://www.adafruit.com/products/1222)&nbsp;(M0 type is recommended!)
- [NeoPixels (Total of 10)](http://www.adafruit.com/product/1506)
- [Photo Cell](https://www.adafruit.com/products/161)
- [Piezo Buzzer](https://www.adafruit.com/product/1740)
- [500mAh LiPoly Battery](http://www.adafruit.com/product/1578) and [Charger](http://www.adafruit.com/product/1304)
- [10k Resistor](https://www.adafruit.com/product/2784)
- [Conductive Thread](https://www.adafruit.com/product/640)
- [Alligator clips](https://www.adafruit.com/product/1592)
- [Soldering iron](https://www.adafruit.com/products/180) and [Solder](https://www.adafruit.com/products/145)
- [Heat Shrink Tubing](https://www.adafruit.com/products/344)
- [Wire strippers](https://www.adafruit.com/products/527), and [Flush Diagonal Cutters](https://www.adafruit.com/product/152)
- (optional but very helpful) [Third Hand Tool](https://www.adafruit.com/product/291 "Link: https://www.adafruit.com/product/291")
- One stainless steel snap
- [Sewing needle](http://www.adafruit.com/product/615) and Thread
- Scissors
- Adhesive Velcro
- Bucket Hat (we recommend getting one size up to save room for the battery

# Close Encounters Hat

## Circuit Diagram

Click to enlarge.

![](https://cdn-learn.adafruit.com/assets/assets/000/049/639/medium800/led_pixels_Close_Encounters_Hat.png?1514145133)

Info: 

- Gemma D0/A2 pin \<--\> Piezo (+)
- Gemma D1/A0 pin \<--\> NeoPixels
- Gemma D2/A1 pin \<--\> Photocell \<--\> 10k Resistor
- Gemma Vout \<--\> Resistor and NeoPixel (+)
- Gemma Gnd \<--\> Photocell,&nbsp; NeoPixel (-), Piezo (-)

# Close Encounters Hat

## Prepare Sensor and Piezo Buzzer

# Close Encounters Hat

## Stitch Parts in Hat

https://www.youtube.com/watch?v=eGtGoPhjmcc

# Close Encounters Hat

## Hat Power

# Close Encounters Hat

## Arduino Code

Info: 

If this is your first time using GEMMA, work through the&nbsp;[Introducing G](http://learn.adafruit.com/introducing-gemma)[EMMA](http://learn.adafruit.com/introducing-gemma)&nbsp;or&nbsp;[Introducing Gemma M0 guide](../../../../adafruit-gemma-m0/)&nbsp;first; you need to customize some settings in the Arduino IDE. Once you have it up and running (test the 'blink' sketch), then follow the instructions on the following page for installing the NeoPixel library:

## **[NeoPixel Überguide:&nbsp;Arduino Library Installation](../../../../adafruit-neopixel-uberguide/arduino-library-installation)**
Plug in your circuit and load up the sketch below:

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Close_Encounters_Hat/Close_Encounters_Hat.ino

# Close Encounters Hat

## CircuitPython Code

![](https://cdn-learn.adafruit.com/assets/assets/000/049/640/medium800/led_pixels_gemma-cp.jpg?1514145968)

Info: 

Below is CircuitPython code that works&nbsp;similarly (though not exactly the same) as the Arduino sketch shown on a prior page. To use this, plug the GEMMA M0 into USB…it should show up on your computer as a small&nbsp; **flash drive** …then edit the file “ **main.py** ” with your text editor of choice. Select and copy the code below and paste it into that file,&nbsp; **entirely replacing its contents** &nbsp;(don’t mix it in with lingering bits of old code). When you save the file, the code should&nbsp; **start running almost immediately** &nbsp;(if not, see notes at the bottom of this page).

**If GEMMA M0 doesn’t show up as a&nbsp;drive, follow the GEMMA M0 guide link above to prepare the board for CircuitPython.**

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Close_Encounters_Hat/code.py

This code requires the&nbsp; **neopixel.mpy** &nbsp;and **simpleio.mpy&nbsp;** libraries. A factory-fresh board will have neopixel.py installed. If you’ve just reloaded the board with CircuitPython, create the “lib” directory and obtain&nbsp;[neopixel.mpy and simpleio.mpy from the latest Adafruit\_CircuitPython\_Bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest).&nbsp;

# Close Encounters Hat

## Wear It!

![](https://cdn-learn.adafruit.com/assets/assets/000/018/602/medium800/sensors_girlHAT2.jpg?1407190620)

If you have done everything correctly, your hat should light up and make the famous notes when it is dark. You can also trigger this reaction yourself by cupping your hand around the grommet that holds the photo cell. Have fun and let everyone know that you are the biggest Spielberg fan around!


## Related Guides

- [Sewable NeoPixels](https://learn.adafruit.com/flora-rgb-smart-pixels.md)
- [AM Radio Morse Code Paddle](https://learn.adafruit.com/am-radio-morse-code-paddle.md)
- [HalloWing Flapping Bat](https://learn.adafruit.com/hallowing-flapping-bat.md)
- [Talking Musical NeoPixel Clock with Infrared, BLE and Touch Controls](https://learn.adafruit.com/talking-musical-neo-pixel-clock-with-infrared-ble-and-touch-controls.md)
- [AdaBox 007](https://learn.adafruit.com/adabox007.md)
- [Prop It Game](https://learn.adafruit.com/prop-it-game.md)
- [Gemma Color Touch Pendant Necklace](https://learn.adafruit.com/gemma-color-touch-pendant-necklace.md)
- [Adafruit IO Basics: Color](https://learn.adafruit.com/adafruit-io-basics-color.md)
- [Infinity Mirror Valentine's Candy Box](https://learn.adafruit.com/infinity-mirror-candy-box.md)
- [Capacitive Touch Unicorn Horn](https://learn.adafruit.com/capacitive-touch-unicorn-horn.md)
- [Twinkly Earwarmer Headband](https://learn.adafruit.com/twinkly-ear-warmer.md)
- [Blahaj Alarm and Lamp](https://learn.adafruit.com/blahaj-alarm.md)
- [Best Beginner Boards for Teachers](https://learn.adafruit.com/best-beginner-boards-for-teachers.md)
- [NeoPixel LED Mickey Ears](https://learn.adafruit.com/neopixel-led-mickey-ears.md)
- [Using Crickit and Adafruit IO together](https://learn.adafruit.com/crickit-and-adafruitio.md)
- [Gemma M0 Vibration Sensor Motion Alarm](https://learn.adafruit.com/motion-alarm.md)
