[pcomp week 3] The Lonely But Tender Ghost (digital and analog inputs, digital outputs)

IMG_0156

This week we learned how to program the Arduino to take inputs from our sensors and program them to make stuff happen.

I went to the Soft Lab workshop on Friday, where I learned how to sew a simple button, so I used that in the first example of alternating LEDs with a switch:

The fun part was using analog sensors to change the brightness of LEDs — I wired up a force sensor and a photocell to control two different LEDs on the breadboard.

I had a ton of ideas for our assignment to do something creative with these sensors this week, many of which sounded great in my mind but in reality were all varying degrees of unfeasible for the time being. One thing that stuck with me — newly inspired by the Soft Lab — was the idea of doing something with a doll or plushie. My goal was to make a plushie that gave you the sense that it had feelings.

I decided to go with a force sensitive resistor. The idea was that I’d make a plushie with LED eyes that would change color depending on how hard you squeezed it.

Here’s the circuit I built on the breadboard:

The map() function was really helpful for me to turn the input from the sensor into three different states, which I could then turn into colors. I learned how to use an RGB LED with the help of this example from Adafruit, and I ended up using the setColor() function written in that sketch in my final code.

IMG_0163

The next step was to make my plushie!

 

IMG_0151 IMG_0153

I realized that my original plan to sew two RGB LEDs into fabric as eyes was actually extraordinarily complicated, so I just made the light separate from the plushie and went with the next best thing: googly eyes.

I built my own force sensitive resistor with some conductive material and Velostat, and sewed it all up in some felt to make my little ghost plushie. I noticed that the input values I got from the commercial FSR went pretty accurately from 0 – 1023, but my homemade FSR pretty much started at 750 or so rather than 0. I adjusted my variable in my code to accommodate it and it worked perfectly well.

I decided to call him the Lonely But Tender Ghost. In his normal state, the light is white. When you squeeze him tenderly, the light turns green. If you squeeze him too hard the light turns red. 😦

This is just a basic first project, but hopefully later on I can further explore building an object that makes you feel like it’s expressing human feelings, perhaps creating sympathy or empathy in you, the user.

My full Arduino code is below.

/*The Lonely But Tender Ghost likes it when you squeeze him gently but doen't like it when you squeeze him too hard. The light turns green when you squeeze him just right. If you squeeze too hard the light turns red. Otherwise, the light is white. */


//setting the pins for each leg of the RGB LED
const int redPin = 11;
const int greenPin = 10;
const int bluePin = 9;
//creating a variable for the value of the force sensor
int forceSensorValue = 0;

void setup() {
  Serial.begin(9600);
  //setting the RGB LED as an output
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop() {
  forceSensorValue = analogRead(A0);
  int force = map(forceSensorValue, 800, 1000, 1, 3); //creating 3 different states of force: 1, 2, and 3
  Serial.println(forceSensorValue); //print value of the force sensor
  Serial.println(force); //print which state it's in: 1, 2 or 3

  if (force == 3) { //if you push really hard, make the LED red
    setColor(255, 0, 0);
  }
  else if (force == 2) { //if you push it just right, make the LED green
    setColor(0, 255, 0);
    //uncomment if instead of green you want rainbow flashing colors...
    //setColor(random(0, 255), random(0, 255), random(0, 255));
    //delay(100);
  }
  else { //if you don't push it at all, make the LED white
    setColor(255, 255, 255);
  }
}

void setColor(int red, int green, int blue) //sets brightness of each LED
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: