# Trinket / Gemma Blinky Eyes

## Overview and Parts

You have one day to make a halloween decoration! What will you do!? Well, if you have a Trinket and a couple of LEDs + a photo cell you can build these randomly blinky eyes that turn on when it gets dark  
  
A recent MAKE project, [Spooky Blinky Eyes](http://makezine.com/projects/spooky-blinking-eyes/) by Bill Blumenthal, demonstrates an ATTiny45 processor fading a pair of LED eyes that randomly blink, giving a more realistic effect than standard "always on" LED eyes.

![](https://cdn-learn.adafruit.com/assets/assets/000/011/821/medium800/trinket_IMG_2334.jpg?1382482504)

Info: 

The effect is due to come clever programming of the timers available on the ATTiny processors featured on the Adafruit Trinket and Gemma microcontrollers. Pins 0 and 1 are capable of pulse width modulation. The timers are set to fade the pins in and out by changing the pulse width back and forth. The blink effect is using an algorithm called a [linear feedback shift register](http://en.wikipedia.org/wiki/Linear_feedback_shift_register "Link: http://en.wikipedia.org/wiki/Linear\_feedback\_shift\_register") (LFSR) to pseudo-randomly turn the eyes off and on quickly.  
  
This project adapts the original code for use on the faster ATTiny85 processor and for the Arduino integrated development environment (IDE). It also adds a Cadmium Sulfide (CdS) photocell to allow the eyes to come on only below a certain light level. During sunlight, this will save battery power.

## **Parts List**

- **Adafruit&nbsp;[Gemma M0](https://www.adafruit.com/product/3501),&nbsp;[Trinket M0](https://www.adafruit.com/product/3500),&nbsp;**[**Trinket Mini**](http://www.adafruit.com/category/261)&nbsp;or&nbsp;[**Gemma v2**](http://www.adafruit.com/products/1222)&nbsp;microcontroller board (if Trinket, either the&nbsp;[3.3V](http://www.adafruit.com/products/1500)&nbsp;or&nbsp;[5V](http://www.adafruit.com/products/1501)type works). We recommend using the&nbsp;**[Trinket M0](https://www.adafruit.com/product/3500).**
- [Cadmium Sulfide Photocell](http://www.adafruit.com/product/161 "Link: http://www.adafruit.com/product/161")
- 2 LEDs (I used two [5 mm red](http://www.adafruit.com/products/297 "Link: http://www.adafruit.com/products/297") for the evil look, you can use any size or color)
- (1k) ohm resistor
- [Tiny Breadboard](https://www.adafruit.com/products/65 "Link: https://www.adafruit.com/products/65") (or other suitable wiring surface)
- [6 volt coin cell battery pack](http://www.adafruit.com/products/783 "Link: http://www.adafruit.com/products/783")
- 2 [CR2032 Batteries](https://www.adafruit.com/products/654 "Link: https://www.adafruit.com/products/654")
- A prop to put your circuit in

# Trinket / Gemma Blinky Eyes

## Wiring

## The circuit is fairly straightforward and can be assembled well within an hour

Headers (included with Trinket) may be soldered to facilitate attachment to a breadboard or proto board. Other parts may be pressed into the breadboard. Ready-made hookup wire or cut to fit wires make the connections.

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/053/613/medium800/trinket_Trinket_Blinky_Eyes.png?1525876543)

The same circuit with Gemma. The LEDs share D0. D2/A1 is hooked to the junction of the photocell and a 1000 ohm (1K) resistor. If you wish to just rely on the power pack on/off switch, you can eliminate the photocell and 1K resistor.

The battery pack works well with wearables. It has a JST connector to plug directly into Gemma. It also has the on/off switch to save power when the circuit is not being used.

![](https://cdn-learn.adafruit.com/assets/assets/000/053/614/medium800/trinket_Gemma_Blinky_Eyes.png?1525876557)

# Trinket / Gemma Blinky Eyes

## Arduino Code

## Preparing Your Trinket

Be sure you have a 3 volt Trinket or Gemma. Follow the [Introducing Trinket](http://learn.adafruit.com/introducing-trinket "Link: http://learn.adafruit.com/introducing-trinket") or [Introducing Gemma](http://learn.adafruit.com/introducing-gemma) tutorials rather carefully to ensure your Arduino integrated development environment (IDE) is set up.&nbsp;

Info: 

Remember you must press the hardware reset button on the Trinket / Gemma then quickly press upload in the Arduino software to upload a sketch. If you get an error, try the reset-upload process again. If you continually cannot load the blink sketch, check to make sure the Trinket / Gemma is connected (without any wires connected to pins #3 and #4) and the Arduino IDE software has all the required changes. This project does not use pins 3 and 4, they are shared with the USB connector (Gemma does not have these pins).

The following uses PWM for the eye brightness. Controlling the counter which helps random blinks still uses hardware Timer 1. A random functionality could be used but would not give as nice a "randomness" and possibly not be timed right given all that is going on with the state machine.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Gemma/Trinket_Gemma_Blinky_Eyes/Trinket_Gemma_Blinky_Eyes.ino

The Arduino code compiles to 1626 bytes.

# Trinket / Gemma Blinky Eyes

## CircuitPython Code

![](https://cdn-learn.adafruit.com/assets/assets/000/053/615/medium800/trinket_gemma-cp.jpg?1525876934)

 **Trinket M0 and Gemma M0&nbsp;** boards can&nbsp;run&nbsp; **CircuitPython** &nbsp;— a different approach to programming compared to Arduino sketches. In fact,&nbsp; **CircuitPython comes&nbsp;factory pre-loaded on Trinket M0**. If you’ve overwritten it with an Arduino sketch, or just want to learn the basics of setting up and using CircuitPython, this is explained&nbsp;in the&nbsp;**[Adafruit Trinket M0 guide](../../../../adafruit-trinket-m0-circuitpython-arduino/overview)****&nbsp;or **&nbsp;** [Adafruit&nbsp;Gemma M0 guide.](../../../../adafruit-gemma-m0/overview)**

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 Trinket 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 Trinket M0 doesn’t show up as a&nbsp;drive, follow the Trinket M0 guide link above to prepare the board for CircuitPython.**

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

# Trinket / Gemma Blinky Eyes

## Building Your Project

Blinky eyes may be placed into nearly anything. That is most of the fun in this project. Select where you would like to put them then build the appropriate lighted eyes, put them in and you have a complete project ready to go.  
  
For my project, I went to that staple of American shopping experiences: Walmart. There in the Halloween section is the 97 cent box. I found an assortment of small sippy cups crying to be liberated from their straws and modded to be small, scary light sensitive balls of evil. You may chose to place the eyes into any item or even a board to hide in a window or the bushes.

![](https://cdn-learn.adafruit.com/assets/assets/000/011/756/medium800/trinket_sippy-cups.jpg?1382311408)

Removing the straws, I drill small holes in the eyes then use a larger 5 mm but to size the holes the same as the LEDs I chose. The hole in the top where the straw was will serve as the place the photocell will be mounted to detect whether it is dark enough to turn on the eyes.  
  
I placed the photocell and LEDs on the ends of male to female jumper wires. Any hookup wire will do, but the jumper wires hook right in to my breadboard and the components. You will want to trim the component leads a bit before placing in the female end to avoid the wires touching and shorting out.  
  
Put the batteries in the holder and for Trinket plug into the breadboard with the red lead to the BAT+, the black to GND. If you use Gemma, plug the battery holder JST (white) connector into the Gemma battery socket. Lower the board into your selected container and thread the LEDs into the eye holes. If you want, a dab of glue will hold the LEDs in place. Thread the photocell through a hole in the top and secure with tape, [Sugru](http://www.adafruit.com/products/436 "Link: http://www.adafruit.com/products/436"), or other substance being careful not to twist the wires or make them touch.   
  
Turn on the curcuit and put the lid on. Now when it is dark enough, the lights will fade in and out and "blink" (go on and off quickly). Enjoy your scary eyes project.

## Low Light Sensitivity
If you find the photocell sensitivity too high or low (which may vary due to the cell's characteristics or the actual value of the 1K resistor), change the value of SENSITIVITY near the top of the code. Valid numbers are zero to 1023, you will want to select a number from about 150 to 800. The lower the number, the darker it must be. 
## Related Guides

- [Sewable NeoPixels](https://learn.adafruit.com/flora-rgb-smart-pixels.md)
- [Adafruit Trinket M0](https://learn.adafruit.com/adafruit-trinket-m0-circuitpython-arduino.md)
- [No-Code WipperSnapper Water Detection](https://learn.adafruit.com/water-detection-with-wippersnapper.md)
- [Using Crickit and Adafruit IO together](https://learn.adafruit.com/crickit-and-adafruitio.md)
- [reef-pi Guide 7: Dosing Controller](https://learn.adafruit.com/reef-pi-guide-5-dosing-controller.md)
- [RGB & HSV NeoPixel Dialer](https://learn.adafruit.com/rgb-hsv-neopixel-dialer.md)
- [CircuitPython Libraries on Linux and the NVIDIA Jetson Nano](https://learn.adafruit.com/circuitpython-libraries-on-linux-and-the-nvidia-jetson-nano.md)
- [Storage humidity and temperature monitor](https://learn.adafruit.com/storage-humidity-and-temperature-monitor.md)
- [Bo-Katan LED Headband](https://learn.adafruit.com/led-headband.md)
- [LED Masquerade Masks with n00ds](https://learn.adafruit.com/led-masquerade-masks-with-n00ds.md)
- [NeoPixel LED Mickey Ears](https://learn.adafruit.com/neopixel-led-mickey-ears.md)
- [CircuitPython Media Dial](https://learn.adafruit.com/media-dial.md)
- [Neopixel Jewel 10 Minute Necklace](https://learn.adafruit.com/10-minute-neopixel-necklace.md)
- [NeoPixel Flame Torch](https://learn.adafruit.com/neopixel-flame-torch.md)
- [Gemma M0 Vibration Sensor Motion Alarm](https://learn.adafruit.com/motion-alarm.md)
- [GEMMA M0 Case](https://learn.adafruit.com/gemma-m0-case.md)
- [Color-sensor Driven NeoPixel Dress](https://learn.adafruit.com/color-sensor-driven-neopixel-dress.md)
