# Trinket Powered Rover

## Red Rover... Red Rover...

Science, Technology, Engineering, (Art) and Math (STEM / STEAM) curriculum is gaining momentum in K-12 education. It's exciting to see so many new makers and engineers learning how fun it is to make! I wanted to design a low cost robot that anyone could build if they have access to a 3D printer.  
  
So... here it is - an autonomous micro rover based on Trinket.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/373/medium800/trinket_IMG_0973.jpg?1388636372)

It's inexpensive and fun, and looks adorable!

# Trinket Powered Rover

## Tools / Materials

When I started designing the rover, I ran into a significant obstacle trying to find inexpensive tracks / treads. I had some success 3D printing ones with [flexible filament](https://www.adafruit.com/product/3222) but the total cost was too high.  
  
That's when I stumbled into these... '[chain bracelets](http://www.orientaltrading.com/christmas-chain-bracelets-a2-13663854.fltr?Ntt=chain%20bracelet)' from [Oriental Trading](http://www.orientaltrading.com/). You can buy a dozen for less than ten dollars; which will make six rovers.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/367/medium800/trinket_IMG_0885.jpg?1388616238)

The pattern is slightly different on the inside and outside; rounded (left) and flat (right). The rounded side fits in the wheel / sprocket perfectly.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/368/medium800/trinket_IMG_0886.jpg?1388616256)

This guide builds on three others...   
  
[Introducing Trinket](http://learn.adafruit.com/introducing-trinket)  
  
[Modifying Servos for Continuous Rotation](http://learn.adafruit.com/modifying-servos-for-continuous-rotation "Link: http://learn.adafruit.com/modifying-servos-for-continuous-rotation")  
  
[Trinket Servo Control](http://learn.adafruit.com/trinket-gemma-servo-control/code)  
  
  
Ready? Here is a list of materials you will need.  

- 1X [Adafruit 3v Trinket](http://www.adafruit.com/products/1500 "Link: http://www.adafruit.com/products/1500")(you can substitute for an Arduino Micro if you like)
- 1X [Tiny Breadboard](http://www.adafruit.com/products/65 "Link: http://www.adafruit.com/products/65")
- 1X [4xAA Battery Holder](http://www.adafruit.com/products/830)
- 2X Continuous Rotation Micro Servos  
- 3X Female / Male Jumpers
- 3X M3 10mm Screws  
- 1X M3 Hex Nut  
- Double-sided Foam Tape

For distance measurement, you can use a [Parallax Ping))) Sensor](http://www.parallax.com/product/28015), [Grove Ultrasonic Ranger](http://www.seeedstudio.com/depot/grove-ultrasonic-ranger-p-960.html), or [Maxbotix Ultrasonic Rangefinder](http://www.adafruit.com/products/980 "Link: http://www.adafruit.com/products/980").  
  
_Let's get fantastic with some plastic!_

# Trinket Powered Rover

## 3D Printing

The rover is comprised of seven plastic parts... the stache' is not optional!

![](https://cdn-learn.adafruit.com/assets/assets/000/013/370/medium800/trinket_rover_001.png?1388616567)

The model archive includes a small and large chassis and three different sonar mounts.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/371/medium800/trinket_rover_002.png?1388616584)

You should be able to squeeze all of the parts into a single print.

[3D Models (.stl files)](http://learn.adafruit.com/system/assets/assets/000/013/044/original/TrinketPoweredRover.zip?1387765228)
Source files are available on [Github](https://github.com/rwinscot/TrinketRover). Or, you could try a re-mix with some elements of [designs](http://www.thingiverse.com/thing:15528)&nbsp;on Thingiverse.

# Trinket Powered Rover

## Assembly

You might need to tap the axle holes... better safe than sorry.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/344/medium800/trinket_IMG_0910.jpg?1388615568)

Or, you could warm / soften the plastic with a hand torch and thread the hole with the screw.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/345/medium800/trinket_IMG_0907.jpg?1388615601)

Make sure that the wheel on the front doesn't bind; you might need to sand around the axle a bit.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/346/medium800/trinket_IMG_0914.jpg?1388615626)

The mounting hole in the wheel is purposefully small to allow for the widest possible screw size. Widen the hole with a drill bit that is slightly larger than the threads of your screw.  
  
Insert your M3 hex nut...

![](https://cdn-learn.adafruit.com/assets/assets/000/013/348/medium800/trinket_IMG_0922.jpg?1388615681)

And screw the sonar mount to the chassis.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/349/medium800/trinket_IMG_0925.jpg?1388615704)

Pilot holes are needed to mount the servo to the chassis. A 1/16 inch bit will do nicely.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/350/medium800/trinket_IMG_0928.jpg?1388615734)

Take it slow... if you hear any kind of cracking you might want to warm / soften the plastic a bit before proceeding.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/351/medium800/trinket_IMG_0931.jpg?1388615762)

Let's get to work on the rear wheels.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/352/medium800/trinket_IMG_0939.jpg?1388615794)

Servo horns are typically white or black... grab one, and trim it to fit.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/353/medium800/trinket_IMG_0945.jpg?1388615819)

I tried using model cement this time... which works, but it will take an hour or so before the wheels are solid enough for final assembly.  
  
5 minute epoxy might be a better alternative.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/355/medium800/trinket_IMG_0950.jpg?1388615870)

Repeat these steps for the other wheel.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/356/medium800/trinket_IMG_0955.jpg?1388615892)

# Trinket Powered Rover

## Electronics

You'll have to decide on what combination of distance sensor + microcontroller you want to use. I've tried them all, and found the following configurations to work well.

- Trinket + Parallax Ping)))
- [Trinket + Maxbotix Proximity Sensor](../../../../trinket-ultrasonic-rangefinder/adding-the-sensor)
- [Trinket Pro + HC-SR04](https://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/)
- [Trinket Pro + Seeed Studio Ultrasonic Ranger](http://wiki.seeedstudio.com/Ultra_Sonic_range_measurement_module/)

Of all the sensors that I tried, the Parallax Ping))) was the easiest to use with Trinket. All you need is GND, VCC, and 1-pin for measurement.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/358/medium800/trinket_IMG_0906.jpg?1388615985)

Snap the sonar into the mount.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/357/medium800/trinket_IMG_0926.jpg?1388615957)

The servos wires end in female connectors, which you will need to convert to male.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/360/medium800/trinket_IMG_0899.jpg?1388616051)

You can do this two ways, replace them with [male ones](http://www.digikey.com/product-detail/en/1318109-1/A29322CT-ND/4430539).

![](https://cdn-learn.adafruit.com/assets/assets/000/013/359/medium800/trinket_IMG_0893.jpg?1388616024)

Or pull out the female connectors...

![](https://cdn-learn.adafruit.com/assets/assets/000/013/361/medium800/trinket_IMG_0960.jpg?1388616078)

Extract a few pins from standard headers.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/362/medium800/trinket_IMG_0961.jpg?1388616102)

Insert the pin into the female receptacle.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/363/medium800/trinket_IMG_0962.jpg?1388616124)

And solder in-place.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/364/medium800/trinket_IMG_0963.jpg?1388616147)

Sweet.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/365/medium800/trinket_IMG_0964.jpg?1388616171)

Here is the circuit diagram to get all the wires in the right place. With the servos, remember that ground is often brown / signal is orange.

![](https://cdn-learn.adafruit.com/assets/assets/000/013/372/medium800/trinket_rover_breadboard.png?1388630983)

# Trinket Powered Rover

## Source Code

_"To control servos with the tiny microcontroller on the Trinket, we'll need a Servo library. The default Arduino Servo library is really only good for Uno/Leonardo/Due and similar beefy processors that can drive servos 'standalone'. Sadly, the Attiny85 can't quite do that as it does not have 16bit timers."_  
  
If you haven't installed the [Adafruit Software Servo Library](http://learn.adafruit.com/trinket-gemma-servo-control/code) yet, read through this guide and install the library.  
  
Good to go?  
  
The following sketch uses the Parallax Ping))) Distance Sensor and is a starting point; ultra-bare bones. And this, is where all the fun begins!  
  
  
```
#include &lt;Adafruit_SoftServo.h&gt;

#define SERVO1PIN 0   // Servo control line (orange) on Trinket Pin #0
#define SERVO2PIN 1   // Servo control line (orange) on Trinket Pin #1

Adafruit_SoftServo servo_left, servo_rght;

// Connect the sonar signal pin to this pin on the Trinket.
const int sonar = 2;

// Moderate speed forward for both servos. Given the orientation of the servos
// one will be going forward, and the other backward. You may need to adjust 
// these slightly to get the rover to move straight forward.
const int left_speed = 75;
const int rght_speed = 90;

// Number in cm when the rover will reverse and try to navigate around.
const int obstacle = 8;

// Multiplier used to determine how far the rover will back-up.
const int back_track = 100;

// Duration of a ping, distance in inches, distance converted to cm.
long duration, inches, cm;

void setup() 
{  
  // Attach servos... and off we go!
  servo_left.attach(SERVO1PIN);
  servo_rght.attach(SERVO2PIN);
} 

void loop() 
{ 
  // Setting servos in forward motion.
  servo_left.write(left_speed - cm);
  servo_left.refresh();
  servo_rght.write(rght_speed + cm);
  servo_rght.refresh();
  delay(15);  

  // establish variables for duration of the ping, and the distance 
  // result in inches and centimeters.
  duration = 0;
  inches = 0;
  cm = 0;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(sonar, OUTPUT);
  digitalWrite(sonar, LOW);
  delayMicroseconds(2);
  digitalWrite(sonar, HIGH);
  delayMicroseconds(5);
  digitalWrite(sonar, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(sonar, INPUT);
  duration = pulseIn(sonar, HIGH);

  // convert the time into a distance.
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);  

  // Long distances will cause the servos to misbehave... cap at 50 cm.
  if ( cm &gt; 50 ) {
    cm = 50;
  }

  if ( cm &lt; obstacle ) {
    // back_track * delay(15) = distance the rover will back-up during 
    // obstacle avoidance.
    for (int i = 0; i &lt; back_track; i++) {
      // Magic numbers... will always backup the same direction. Can you 
      // think of a better way to navigate obstacles?
      servo_left.write(150);
      servo_left.refresh();
      servo_rght.write(50);
      servo_rght.refresh();  
      delay(15);
    }
  }
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
```


## Featured Products

### 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)
### Continuous Rotation Micro Servo

[Continuous Rotation Micro Servo](https://www.adafruit.com/product/2442)
Need to make a _tiny_ robot? This little micro servo rotates 360 degrees fully forward or backward, instead of moving to a single position. You can use any servo code, hardware, or library to control these servos. Good for making simple moving robots. Comes with five horns and...

In Stock
[Buy Now](https://www.adafruit.com/product/2442)
[Related Guides to the Product](https://learn.adafruit.com/products/2442/guides)
### Maxbotix Ultrasonic Rangefinder - LV-EZ1

[Maxbotix Ultrasonic Rangefinder - LV-EZ1](https://www.adafruit.com/product/172)
LV-EZ1 Maxbotix Ultrasonic Rangefinder provides very short to long-range detection and ranging, in an incredibly small package. It can detect objects from 0-inches to 254-inches (6.45-meters) and provides sonar range information from 6-inches out to 254-inches with 1-inch resolution. (Objects...

In Stock
[Buy Now](https://www.adafruit.com/product/172)
[Related Guides to the Product](https://learn.adafruit.com/products/172/guides)
### USB cable - A/MiniB

[USB cable - A/MiniB](https://www.adafruit.com/product/260)
This here is your standard A-miniB USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Teensy v2, USB Lipo charger w/Mini B connector, among other things.

Approximately 3 feet / 1 meter long

Color may vary!

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/260)
[Related Guides to the Product](https://learn.adafruit.com/products/260/guides)
### Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)

[Premium Female/Male 'Extension' Jumper Wires - 40 x 6" (150mm)](https://www.adafruit.com/product/826)
Handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in a 'strip' of 40 (4 pieces of each of ten rainbow colors). They have 0.1" male header contacts on one end and 0.1" female header contacts...

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

[Tiny Premium Breadboard](https://www.adafruit.com/product/65)
This is a tiny little breadboard... half the size of a half-size breadboard!&nbsp;

**As of Sep 8, 2022** - This Tiny breadboard has been updated to make plugging and un-plugging boards and headers a buttery-smooth&nbsp;operation. Updated design also includes a metal...

In Stock
[Buy Now](https://www.adafruit.com/product/65)
[Related Guides to the Product](https://learn.adafruit.com/products/65/guides)
### 4 x AA Battery Holder with On/Off Switch

[4 x AA Battery Holder with On/Off Switch](https://www.adafruit.com/product/830)
Make a nice portable power pack with this 4 x AA battery holder. It fits any alkaline or rechargeable AA batteries in series. There's a snap on cover and an on/off switch which can be handy when wiring to something without a switch.

**New**! We now have 0.1" headers...

In Stock
[Buy Now](https://www.adafruit.com/product/830)
[Related Guides to the Product](https://learn.adafruit.com/products/830/guides)
### 65 Piece Ratchet Screwdriver and Tool Bit Set

[65 Piece Ratchet Screwdriver and Tool Bit Set](https://www.adafruit.com/product/829)
Look, over there at that thing! Take it apart! You can now attack just about every kind of box or enclosure that needs undoing with this ratchet screwdriver set. This set is fine quality and excels at disassembling and assembling larger hardware and makes a good companion to our smaller...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/829)
[Related Guides to the Product](https://learn.adafruit.com/products/829/guides)

## Related Guides

- [Trinket Bluetooth Alarm System](https://learn.adafruit.com/trinket-bluetooth-alarm-system.md)
- [Trinket Audio Player](https://learn.adafruit.com/trinket-audio-player.md)
- [Adding Third Party Boards to the Arduino v1.6.4+ IDE](https://learn.adafruit.com/add-boards-arduino-v164.md)
- [Adafruit Trinket-Modded Stuffed Animal](https://learn.adafruit.com/adafruit-trinket-modded-stuffed-animal.md)
- [Trinket / Gemma IR Control](https://learn.adafruit.com/trinket-gemma-ir-remote-control.md)
- [Bluetooth-Controlled NeoPixel Goggles](https://learn.adafruit.com/bluetooth-neopixel-goggles.md)
- [Trinket / Gemma Mini-Theremin](https://learn.adafruit.com/trinket-gemma-mini-theramin-music-maker.md)
- [Trinket / Gemma Blinky Eyes](https://learn.adafruit.com/trinket-gemma-blinky-eyes.md)
- [Trinket “Question Block” Sound Jewelry](https://learn.adafruit.com/trinket-question-block-sound-jewelry.md)
- [3D Printed LED Fire Horns](https://learn.adafruit.com/3d-printed-led-fire-horns.md)
- [Serial Debugging with GEMMA](https://learn.adafruit.com/serial-debugging-with-gemma.md)
- [Laser Dog Goggles](https://learn.adafruit.com/laser-dog-goggles.md)
- [Trinket USB Volume Knob](https://learn.adafruit.com/trinket-usb-volume-knob.md)
- [Cyber Tank Girl Cosplay](https://learn.adafruit.com/cyber-tank-girl-cosplay.md)
- [Trinket (& Gemma) Servo Control](https://learn.adafruit.com/trinket-gemma-servo-control.md)
