# Adafruit Trinket-Modded Stuffed Animal

## Overview

People love stuffed animals! One of the first toys a child gets is some representation of an animal. Over time, these beloved companions become part of what we surround ourselves with.  
  
This project provides ideas for creating stuffed, papercraft or other toy animals with characteristics you want. You can chose your animal, make it move and have it make sounds. Assembly is straightforward, the most complex component is using your imagination.  
  
The basic circuit shows you how to use a servo motor, a piezo speaker, and a photocell to provide interactivity with your animal.

http://www.youtube.com/watch?v=czxEULNZulo

Info: 

## Choosing Your Animal
  
Technically you do not even have to use an animal - this can be for simple robots or other items.   
  
This tutorial will demonstrate animating a bird. I went looking for what materials I could use for the bird body. The electronics dictate the minimum size of the bird. It can be as large as you wish (you must scale the servo and power for large items). Digging in the closet, I found a Beanie Baby bird named Beak that was well suited to animation. A moderate-sized Angry Bird toy would work well also.  
  
Nearly any animal may be represented. You can use existing animals or fabricate your own with paper or 3D printing ![](https://cdn-learn.adafruit.com/assets/assets/000/012/196/medium800/trinket_Beanie-Baby-beak.jpg?1384185097)

# Adafruit Trinket-Modded Stuffed Animal

## Animal Sounds

Sound is a very personal part of a project. Everyone has their particular vision of how something sounds.  
  
To experiment with sounds, the sound creation program below may be used. The program comes with several pre-programmed sounds:

- A bird chirp
- Cat meows (a meeee-ow, a me-oooow, and a mew)
- Dog sounds (ruff and arf)

  
Ruff or woof are conventional representations in the English language of the barking of a dog. [Onomatopoeia](http://en.wikipedia.org/wiki/Onomatopoeia) or imitative sounds, vary in other cultures: people "hear" a dog's barks differently and represent them in their own ways. Some of the equivalents of "woof" in other European and Asian languages are in [Wikipedia](http://en.wikipedia.org/wiki/Bark_(sound)#Representation "Link: http://en.wikipedia.org/wiki/Bark\_(sound)#Representation"). You can hear different sounds at the wonderful website [http://www.bzzzpeek.com/](http://www.bzzzpeek.com/).  
  
Part of the creative process is making your animal sound like what you believe it should sound like. This will probably involve a fair amount of experimentation. Sampled real sounds take up too much memory for Trinket and a ROM takes too many microcontroller pins. So the method used here is turning a digital pin on and off very fast to make sounds at various frequencies.   
  
If you have an Arduino Uno/Leonardo/Mega/etc. handy, you can use a serial monitor to select frequencies using a potentiometer and see the values on the serial monitor. If you have a Trinket, you can listen to a tone but not see the output frequency easily.   
  
You can add frequency / duration values together to make more complex sounds. You can also vary a tone up or down to get effects you want. Map out your sound into component sounds, for example "meow" for a cat. Start with the M sound: use the varyFrequency function to find a "mmm" (maybe 5100). The sound is short so we try 50 milliseconds. The "e" is "eeee", lasts longer, so the frequency 394 sounded right and the sound is longer so trial and error got 180 milliseconds. The "o" is a more complex sound, starting high (990) and getting a bit lower (1022). How long you run the loop and specify the duration for each sound will vary the sound. Finally "w" is enough like "m" that I repeat it as I could find no better sound. That is meeeow. You can also see meoooow and mew as variations. You may feel they do not sound enough cat-like which is ok, you can define your purr-fect sound using these methods.  
![](https://cdn-learn.adafruit.com/assets/assets/000/012/195/medium800/trinket_Tone-Test-Rig.jpg?1384183305)

```
/*******************************************************************
  Adafruit Animal - Sound testing module
 
  Works on Arduino Uno, Leonardo, Mega, Menta, etc.
  can work on Trinket with right pin mapping and no Serial port
 *******************************************************************/

// pins
#define SPEAKER   11   // Piezo Speaker pin (positive, other pin to ground)
#define POT       A0   // for Trinket, use 1 for #2, 3 for #3, 2 for #4
                       //   for Uno/Leo/Mega A0 to A5
// define serial if using debug on Uno/Leo/Mega, Trinket/Gemma comment out
#define SERIAL    
 
void setup() {
#ifdef SERIAL
   Serial.begin(9600);
#endif
  pinMode(SPEAKER,OUTPUT);  // important to set pin as output
}
 
void loop()  {
//  varyFrequency();  // uncomment to search for correct tone value
  
// the sounds below are defined - comment out those you do not want or
//   comment out if using varyFrequency() to select play with tones
  chirp(); 
  delay(2000);  
  meow();
  delay(2000);  
  meow2();
  mew();
  delay(2000);    
  ruff();
  delay(2000);  
  arf();
  delay(2000);
  
// scale();  // if you would like to hear the whole frequency
             //   range, you can use this function
}
 
void varyFrequency() {   
//  use potentiometer to produce one tone per value of pot
//  good for getting pitch value to use in making sound routines
  int reading;
  const uint8_t scale = 1; // 1 for high frequencies, scale up to 15 for lowest freqs

  reading = scale * analogRead(POT);
  playTone(reading, 1000);
#ifdef SERIAL
  Serial.print("Freq = ");
  Serial.println(reading);
#endif
}

void chirp() {  // Bird chirp
  for(uint8_t i=200; i&gt;180; i--)
     playTone(i,9);
}

void meow() {  // cat meow (emphasis ow "me")
  uint16_t i;
  playTone(5100,50);        // "m" (short)
  playTone(394,180);        // "eee" (long)
  for(i=990; i&lt;1022; i+=2)  // vary "ooo" down
     playTone(i,8);
  playTone(5100,40);        // "w" (short)
}

void meow2() {  // cat meow (emphasis on "ow")
  uint16_t i;
  playTone(5100,55);       // "m" (short)
  playTone(394,170);       // "eee" (long)
  delay(30);               // wait a tiny bit
  for(i=330; i&lt;360; i+=2)  // vary "ooo" down
     playTone(i,10);
  playTone(5100,40);       // "w" (short)
}

void mew() {  // cat mew
  uint16_t i;
  playTone(5100,55);       // "m"   (short)
  playTone(394,130);       // "eee" (long)
  playTone(384,35);        // "eee" (up a tiny bit on end)
  playTone(5100,40);       // "w"   (short)
}

void ruff() {   // dog ruff
  uint16_t i;
  for(i=890; i&lt;910; i+=2)     // "rrr"  (vary down)
     playTone(i,3);
  playTone(1664,150);         // "uuu" (hard to do)
  playTone(12200,70);         // "ff"  (long, hard to do)
}

void arf() {    // dog arf
  uint16_t i;
  playTone(890,25);          // "a"    (short)
  for(i=890; i&lt;910; i+=2)    // "rrr"  (vary down)
     playTone(i,5);
  playTone(4545,80);         // intermediate
  playTone(12200,70);        // "ff"   (shorter, hard to do)
}

// play tone on a piezo speaker: tone shorter values produce higher frequencies
//  which is opposite beep() but avoids some math delay - similar to code by Erin Robotgrrl

void playTone(uint16_t tone1, uint16_t duration) {
  if(tone1 &lt; 50 || tone1 &gt; 15000) return;  // these do not play on a piezo
  for (long i = 0; i &lt; duration * 1000L; i += tone1 * 2) {
     digitalWrite(SPEAKER, HIGH);
     delayMicroseconds(tone1);
     digitalWrite(SPEAKER, LOW);
     delayMicroseconds(tone1);
  }     
}

// another sound producing function similar to http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html
void beep (int16_t frequencyInHertz, long timeInMilliseconds) {
    long x;	 
    long delayAmount = (long)(1000000/frequencyInHertz);
    long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
    for (x=0;x&lt;loopTime;x++) {	 
       digitalWrite(SPEAKER,HIGH);
       delayMicroseconds(delayAmount);
       digitalWrite(SPEAKER,LOW);
       delayMicroseconds(delayAmount);
    }	 
}

void scale() {
  for(uint16_t i=50; i&lt;15000; i++)  {
     playTone(i,20);
  }
}
```

# Adafruit Trinket-Modded Stuffed Animal

## Circuit

The electronics are fairly straightforward, using a Trinket 3V. The circuit uses pins #0, #1, and #2 making it compatible with Gemma as well. Solder the included male header pins to the Trinket pins.  
  
A Quarter-size Adafruit Perma Proto board is used as the base. Hook-up wire connects various pads to route signal and power. A 1000 ohm (1K Ohm) resistor is needed in addition to the parts listed for the photocell circuit.  
  
Optionally, female headers may be used to make the Trinket removable from the Proto board - cut two 5 pin sections. Male headers may be used to connect off-board components: 2 two-pin and 1 three-pin section connect the servo, piezo, and photocell. Connections are via strips of female-female jumper wires, although any flexible wire may be used. Using headers allows for easy removal of the board from the project if needed.  
  
The Perma Proto may be cut at row B to make the board smaller if your Animal is smaller than can be accommodated by the full board.

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/012/305/medium800/trinket_Trinket_Animal_3V_fritzing_edit_cut2.jpg?1384700633)

![](https://cdn-learn.adafruit.com/assets/assets/000/012/306/medium800/trinket_IMG_2365small.jpg?1384701778)

I mounted the servo onto the Perma Proto board to provide a base for moving the servo (it needs something to push against). You can mount it in many ways but it generally needs a firm mount to achieve the movement you may want. The proto mounting hole was enlarged slightly with a drill bit to allow a small screw to pass through at the correct place.

## Circuit Variations
**Trinket:** You can use a 5 volt Trinket with a 5 volt supply, perhaps 4 AAA or AA batteries. The servo is generally 5 volt so be careful at running at 6 volts (check the servo data sheet). You can put a diode in series with a 6 volt supply to drop the voltage about 0.7 volts. Gemma would also work well especially if you want to use a LiPo battery, but Proto mounting would be more of a challenge.  
  
**Photocell:** If you want the circuit to always run when on, you can eliminate the photocell and 1000 ohm resistor. You will need to remove the analogRead and if statement in the code that acts on the reading.  
  
**Speaker:** If you want better sounds, you can feed the pin 1 sounds to a transistor to switch a more conventional speaker - you may need some appropriate resistors to bias the transistor correctly.  
  
**Servo:** If you use a larger servo, you may need more battery capacity. If you do not need your Animal to move, you can eliminate the servo and the wire from Pin 0, power and ground. You could then trim the amount of Proto board used by cutting at line 12.  
  
**Battery:** The 3 volt Trinket runs well on LiPo batteries stocked by Adafruit. The [3.7 volt 1200 mAh](http://www.adafruit.com/products/258 "Link: http://www.adafruit.com/products/258") is a good size and capacity. If you use a LiPo, you may want some type of on/off switch. AA and AAA battery packs may have the switch built in. You can see on the actual picture, I used two of the gold pins from the female headers to make an ad-hoc JST male connector for a LiPo in the upper left corner. A Gemma would already have the JST battery connection if you want to consider that as an option. # Adafruit Trinket-Modded Stuffed Animal

## Arduino Code

The code below is for the bird project. You can change the chirp function for one of the other sounds defined on the Animal Sounds page.  
  
The code reads the photocell and if the value is less than a certain amount (you pet the animal, lowering the light level), the animal makes sounds and moves. You can change the sensitivity of the photocell (800) to a value between 200 and 1100 depending on ambient light you expect.  
  
The register/interrupt code allows the servo to be refreshed periodically to have it stay where it is commanded to. The Arduino Servo library does not work for Trinket/Gemma so the [Adafruit Softservo library](https://github.com/adafruit/Adafruit_SoftServo "Adafruit Softservo library")&nbsp;is used.

Open up the Arduino library manager

![](https://cdn-learn.adafruit.com/assets/assets/000/084/059/medium800/trinket_library_manager_menu.png?1573528909)

Search for the&nbsp; **Adafruit SoftServo** &nbsp;library and install it

![](https://cdn-learn.adafruit.com/assets/assets/000/084/060/medium800/trinket_softservo.png?1573528970)

We also have a great tutorial on Arduino library installation at:  
[http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use "Link: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use")

Please ensure your Arduino IDE is version 1.6.7 or above to support Trinket optimally. &nbsp;You can download the Arduino IDE at [arduino.cc](http://arduino.cc/ "arduino.cc").

The code below may be copied into a new project window in the Arduino IDE.

Info: 

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

# Adafruit Trinket-Modded Stuffed Animal

## CircuitPython Code

![](https://cdn-learn.adafruit.com/assets/assets/000/062/534/medium800/trinket-cp.jpg?1537894894)

 **Trinket 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 in the&nbsp;[**Adafruit** &nbsp;](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwiK-__azsnXAhWFsVQKHeLhDgcQFgg8MAA&url=https%3A%2F%2Flearn.adafruit.com%2Fadafruit-trinket-m0-circuitpython-arduino%2Foverview&usg=AOvVaw1KR3kAPHYx-DXtGZjUQX60)**[Trinket M0 guide](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwiK-__azsnXAhWFsVQKHeLhDgcQFgg8MAA&url=https%3A%2F%2Flearn.adafruit.com%2Fadafruit-trinket-m0-circuitpython-arduino%2Foverview&usg=AOvVaw1KR3kAPHYx-DXtGZjUQX60).**

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 “ **code****.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/Trinket_Modded_Stuffed_Animal/code.py

# Installing Libraries
The simpleio.mpy library must be installed for the above code to run correctly. The latest version of the&nbsp;[Adafruit CircuitPython Library Bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest/)&nbsp;contains both libraries. You want to download the latest stable&nbsp; **mpy** &nbsp;bundle which will have a filename like this:

**adafruit-circuitpython-bundle-x.x.x-mpy-date.zip**

The Trinket M0 has limited space, but so in this case we will be selective about which files are copied over to the CIRCUITPY drive. A detailed explanation for&nbsp;[installing libraries is available](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

Copy the following file from the unzip'd CircuitPython Library Bundle to the CIRCUITPY drive to a new folder called 'lib'.&nbsp;

- simpleio.mpy

# Adafruit Trinket-Modded Stuffed Animal

## The Bird

The Animal I chose uses a classic Beanie Baby toy. The code uses the chirp sound from the sounds page for the piezo and the servo moves a wire which animates the head.

![](https://cdn-learn.adafruit.com/assets/assets/000/012/267/medium800/trinket_IMG_2347.jpg?1384553567)

The seams on the bottom are carefully cut, allowing you to save the beans and fluff stuffing. A piece of stiff wire is cut to stuff up the head into the beak. A spare piece of house wiring 10 to 12 gauge works well but anything fairly stiff but bendable will do.   
  
The photocell is pushed through the seam at the forehead. A dot of super glue holds the photocell to the animal. A piece of flexible wire (like rainbow wire with connectors cut off one end) can be soldered carefully to trimmed photocell leads. Protect the soldered ends with hot glue, Sugru, or other material.

![](https://cdn-learn.adafruit.com/assets/assets/000/012/307/medium800/trinket_IMG_2360small.jpg?1384702223)

Drill a hole in the servo horn to match the diameter of the wire for the head. The single arm works fine but the double arm or circle will work as well. Strip and bend the end of the wire so it will fit on the servo horn and stay somewhat secure but move when needed.   
  
Push the wire up through the beak. the other, stripped end is bent slightly and threaded into the servo horn.

![](https://cdn-learn.adafruit.com/assets/assets/000/012/308/medium800/trinket_IMG_2359small.jpg?1384702366)

If you want to maximize the speaker sound, you can place it so the hole is exposed to the exterior of the animal. The fabric does not mute the chirp sound by much.

# Adafruit Trinket-Modded Stuffed Animal

## Your Animal

And the project in action:

http://www.youtube.com/watch?v=czxEULNZulo

The fun part of this project is you can animate any Animal or object you want. Do you want a cat, dog, cow? It's possible. Paper, plastic, 3D, that works very well.  
  
You can also animate other objects like small robots. With Trinket, pins #3 and #4 are free which allows for additional servos. Continuous rotation servos may be used to move forward and backward.  
  
You can animate several parts with one servo using the round servo horn with multiple holes and wires.  
  
Post your creations in the [Trinket Adafruit forum](http://forums.adafruit.com/viewforum.php?f=52).


## Featured Products

### Adafruit Trinket M0 - for use with CircuitPython & Arduino IDE

[Adafruit Trinket M0 - for use with CircuitPython & Arduino IDE](https://www.adafruit.com/product/3500)
The&nbsp;Adafruit Trinket M0 may be small, but do not be fooled by its size! It's a tiny microcontroller board, built around the Atmel ATSAMD21, a little chip with _a lot_ of power. We wanted to design a microcontroller board that was small enough to fit into any project, and low...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3500)
[Related Guides to the Product](https://learn.adafruit.com/products/3500/guides)
### Adafruit Trinket - Mini Microcontroller - 3.3V Logic

[Adafruit Trinket - Mini Microcontroller - 3.3V Logic](https://www.adafruit.com/product/1500)
 **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/1500)
[Related Guides to the Product](https://learn.adafruit.com/products/1500/guides)
### Micro servo

[Micro servo](https://www.adafruit.com/product/169)
Tiny little servo can rotate approximately 180 degrees (90 in each direction) and works just like the standard kinds you're used to but _smaller_. You can use any servo code, hardware, or library to control these servos. Good for beginners who want to make stuff move without...

Out of Stock
[Buy Now](https://www.adafruit.com/product/169)
[Related Guides to the Product](https://learn.adafruit.com/products/169/guides)
### Piezo Buzzer

[Piezo Buzzer](https://www.adafruit.com/product/160)
Piezo buzzers are used for making beeps, tones and alerts. This one is petite but loud! Drive it with 3-30V peak-to-peak square wave. To use, connect one pin to ground (either one) and the other pin to a square wave out from a timer or microcontroller. For the loudest tones, stay around 4 KHz,...

In Stock
[Buy Now](https://www.adafruit.com/product/160)
[Related Guides to the Product](https://learn.adafruit.com/products/160/guides)
### Panel Mount 10K potentiometer (Breadboard Friendly)

[Panel Mount 10K potentiometer (Breadboard Friendly)](https://www.adafruit.com/product/562)
This potentiometer is a two-in-one, good in a breadboard or with a panel. It's a fairly standard linear taper 10K ohm potentiometer, with a grippy shaft. It's smooth and easy to turn, but not so loose that it will shift on its own. We like this one because the legs are 0.2" apart...

In Stock
[Buy Now](https://www.adafruit.com/product/562)
[Related Guides to the Product](https://learn.adafruit.com/products/562/guides)
### Photo cell (CdS photoresistor)

[Photo cell (CdS photoresistor)](https://www.adafruit.com/product/161)
CdS cells are little light sensors. As the squiggly face is exposed to more light, the resistance goes down. When it's light, the resistance is about ~1KΩ, when dark it goes up to ~10KΩ.

To use, connect one side of the photocell (either one, it's symmetric) to power...

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

[Adafruit Perma-Proto Quarter-sized Breadboard PCB - 3 Pack!](https://www.adafruit.com/product/589)
Customers have asked us to carry basic perf-board, but we never liked the look of most basic perf: it's 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...

In Stock
[Buy Now](https://www.adafruit.com/product/589)
[Related Guides to the Product](https://learn.adafruit.com/products/589/guides)
### 3 x AAA Battery Holder with On/Off Switch and 2-Pin JST

[3 x AAA Battery Holder with On/Off Switch and 2-Pin JST](https://www.adafruit.com/product/727)
This battery holder connects 3 AAA batteries together in series for powering all kinds of projects. We spec'd these out because the box is slim, and 3 AAA's add up to about 3.3-4.5V, a very similar range to Lithium Ion/polymer (Li-Ion) batteries and have an on-off switch. That makes...

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

## Related Guides

- [Adafruit Trinket M0](https://learn.adafruit.com/adafruit-trinket-m0-circuitpython-arduino.md)
- [Trinket (& Gemma) Servo Control](https://learn.adafruit.com/trinket-gemma-servo-control.md)
- [Color Balancing Video Camera Light feat. DotStars](https://learn.adafruit.com/color-balancing-light-box-with-dotstar-cool-warm-white-leds.md)
- [Tap Tempo Trinket](https://learn.adafruit.com/tap-tempo-trinket.md)
- [CircuitPython 101: Basic Builtin Data Structures](https://learn.adafruit.com/basic-datastructures-in-circuitpython.md)
- [Motorized Turntable](https://learn.adafruit.com/motorized-turntable-circuitpython.md)
- [Trinket Bluetooth Alarm System](https://learn.adafruit.com/trinket-bluetooth-alarm-system.md)
- [Storage humidity and temperature monitor](https://learn.adafruit.com/storage-humidity-and-temperature-monitor.md)
- [NeoPixie Dust Bag](https://learn.adafruit.com/neopixel-pixie-dust-bag.md)
- [Mini VOTE Keyboard](https://learn.adafruit.com/vote-keyboard.md)
- [CircuitPython Essentials](https://learn.adafruit.com/circuitpython-essentials.md)
- [3D Printed LED Fire Horns](https://learn.adafruit.com/3d-printed-led-fire-horns.md)
- [Breadboards for Beginners](https://learn.adafruit.com/breadboards-for-beginners.md)
- [Glowy Message Crown](https://learn.adafruit.com/glowy-message-crown.md)
- [Trinket “Question Block” Sound Jewelry](https://learn.adafruit.com/trinket-question-block-sound-jewelry.md)
- [Trinket USB Volume Knob](https://learn.adafruit.com/trinket-usb-volume-knob.md)
