The Panda That Wanted To Be A Polar Bear

Allen has a polar and he loves it. He’s been sleeping with the polar bear since forever and his obsession with it is becoming unhealthy. For my stupid pet trick I wanted to find a way for Allen to move on from the polar bear but I couldn’t. I didn’t have the courage to steal the polar bear and transform it into a horrific thing and then give it back to Allen. I just couldn’t do that him. The last time he cried he was three months old and didn’t want to break his little heart.

So I stole a panda bear from one of my friends, opened its back, and inserted an Arduino, LEDs, two servos, a speaker, and a pressure sensor.   The idea was to make a panda bear that would always make noise. The user, thinking that it would quiet down by hugging it would hug the bear making its eyes move, turn red, and making the noise even more annoying. With the amount of movement, sound, and light depending on the pressure of the hug.

Screen Shot 2015-10-12 at 2.17.39 PM

This is me with the bear:

Photo on 10-6-15 at 7.42 PM

The code:

//Sensor Pin = A0
//LED Pin1 = D2
//LED Pin2 = D3
//LED Pin3 = D4
//Motor1 = D5
//Motor2 = D6
//Sound = D7

const int sensorPin = A0;
int piezo = 7;
#include <Servo.h>
Servo myservo1;
Servo myservo2;

void setup() {
  Serial.begin(9600);
  for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
    pinMode(pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);

    pinMode(piezo, OUTPUT);
    myservo1.attach(5);
    myservo2.attach(6);
  }
}

void loop() {
  int sensorVal = analogRead(sensorPin);
  Serial.print("sensor Value: ");
  Serial.println(sensorVal);            // reads the value of the potentiometer (value between 0 and 1023)
  int val = map(sensorVal, 0, 1023, 0, 179);


  if (sensorVal <= 50) {
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    //motor does not move
    for (int i = 45; i < 500; i = i + 13) {
      tone(piezo, i);
      //delay(100);
      //tone
    }
  }
  else {
    if (sensorVal >= 50 && sensorVal <=200) {
      digitalWrite(2, HIGH);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      myservo1.write(val);
      myservo2.write(val);
      delay(15);
      for (int i = 45; i < 500; i = i + 150) {
        tone(piezo, i);
      }
    }

      else {
        if (sensorVal >= 200 && sensorVal <= 600) {
          digitalWrite(2, HIGH);
          digitalWrite(3, HIGH);
          digitalWrite(4, LOW);
          myservo1.write(val);
          myservo2.write(val);                 // sets the servo position according to the scaled value
          delay(15);
          for (int i = 45; i < 500; i = i + 170) {
            tone(piezo, i);
            //delay(100);
            //tone;
          }
        }
        else {
          if (sensorVal >= 600 && sensorVal <= 1000) {
            digitalWrite(2, HIGH);
            digitalWrite(3, HIGH);
            digitalWrite(4, HIGH);
            myservo1.write(val);
            myservo2.write(val);
            delay(15);
            for (int i = 45; i < 500; i = i + 170) {
              tone(piezo, i);
              //delay(100);
              //tone;
            }
          }
        }
      }


      delay(1);
    }
  }

And a video of how it worked:

Movie on 10-6-15 at 7.42 PM

Leave a Reply