Behavior Story (Week 6)

Soothing/Comforting/Purring Pet (Or rather: The Angry Firefly)


Don’t wake up the angry firefly…

The plan for my Behavior Story took a detour when I underestimated how loud/strong the vibration from the mini vibe motor could be. I had initially planned on making a nice, soothing toy/object that created a gentle vibration and pulsing light when you put your hand on it. Instead what I got was an angry cricket/firefly that was irritated when you bothered it.

A photoresistor at the top of the jar detects when the user places his or her hand above it, causing the angry firefly inside to wake up (lighting an LED and powering a mini vibe motor in short pulses) until the user’s hand is removed.


  • 1x Adafruit Trinket Pro 5V (or any other microcontroller that fits in the container of your choice – in this case I was using a glass jar with a plastic lid and needed something compact)
  • 1x Photocell/Photoresistor/LDR
  • 1x 5mm LED (bright white)
  • 1×1300 mAh LiPo Battery* (+battery “backpack” to connect it to microcontroller) *used 9v battery instead – bulkier, but still works
  • 1x 100 ohm resistor (for LED)
  • 1x 100k ohm resistor (for LDR/photocell)
  • Hookup wire/conductive thread + solder + soldering iron etc.

for the vibe motor circuit:

  • 1x NPN Transistor
  • 1x 1k ohm resistor
  • 1x 1N4001 Diode
  • 1x capacitor
  • 1x 33 ohm resistor
  • 1x mini vibe motor


The project is my first attempt at using a Trinket microcontroller with soldered connections – something I tried in order to keep the components as compact as possible. However, the project still required a 9v battery to work effectively (the vibe motor requires a decent amount of power), making it bulkier than intended.

IMG_9686 IMG_9689  IMG_9692IMG_0014IMG_0015IMG_0016IMG_0018IMG_0019IMG_9690IMG_9691


Fritzing Diagram / Breadboard Circuit:





for Arduino code, see below:

The Code:

Jane McDonough
Computational Craft, Fall 2015
October 13, 2015

Behavior Story: Cuddling/Comforting
Create a circuit showing a behavior or action
Tell a story about the object: what is it feeling?
How is this feeling displayed through code?

Circuit uses: Trinket Pro 5V, photoresistor, mini vibe
motor, 5mm LED, and is powered with a 9V battery


int sensorPin = A0; // LDR on analog pin A0
int ledPin = 10; // LED on digital pin 10 (PWM)
int motorPin = 13; // mini vibe motor on digital pin 13

int sensorValue = 0; // stores sensor reading value
int val; //store mapped sensor reading value

int brightness = 0; // for pulse: how bright the LED is
int fadeAmount = 5; // for pulse: points to fade the LED by
void setup() {

pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
pinMode(motorPin, OUTPUT);

// Serial.begin(9600);

void loop() {

sensorValue = analogRead(sensorPin);
val = map(sensorValue, 550,900,255, 0);
analogWrite(ledPin, val);

if (val>200){

analogWrite(ledPin, brightness);
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;

digitalWrite(motorPin, HIGH);
digitalWrite(motorPin, LOW);

analogWrite(ledPin, val);

// Serial.println(sensorValue);
// Serial.println(val);


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>