Project Sniffles – Sensory Replication using Arduino – Final Week

Upon completion of the project and on the day before hand in our final post will be a collection of the final model, a in depth flowchart and code that we used to power him.

First is the completed model. This is something me and Stefan are immensely proud of, it took a while for the plushie to get here but when it arrived we really needed to crack the mechanism and internals. As you can see from the images and the video below it works well and performs reliably. Only thing that we want to change later is the servo’s angle. Currently it’s at 90 degrees at rest then 180 when curled up. We can’t get any more rotation on the servo as it won’t go past 180 and would require us to take him apart so something to do after

Next our code was a tricky nut to crack but we got there in the end. We had a working code early on but we felt like with the extra time we could really get a complex and cohesive code. One problem we wished we could fix was the vibration motor with varying speeds at different distances. This wasn’t possible with the time as servo’s and DC motors don’t like working together with Arduino.

A1 Code.jpg

The circuitry for Sniffles was basic enough because we used a lot of code to control things. We made a voltage regulating circuit to control the DC motors but in the end, we had to stick to digital writes (ON & OFF) because of our code problem. Again, we intend to change this before our second-year show.

#include <Servo.h>
Servo Servo1;
int motorPin = 8;
int ServoPin = 3;
int trigPin = 10;
int echoPin = 13;
int cases;
int distance;

void setup() {
  // put your setup code here, to run once:
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motorPin, OUTPUT);
  Servo1.attach(ServoPin);
}

void loop() {

  proximity();

  if (distance <= 20 && distance >= 2)
    cases = 1;
  if (distance <= 30 && distance >= 21)
    cases = 2;
  if (distance <= 40 && distance >= 31)
    cases = 3;
  if (distance >= 50)
    cases = 4;



  switch (cases) {
    case 1: //full scare
      // Write servo to the scared position
      Serial.println(cases);


      digitalWrite(motorPin, HIGH);

      Servo1.write(180);


      break;

    case 2: // full shake no scare
      // revert servo back to the original
      Serial.println(cases);

      digitalWrite(motorPin, HIGH);

      //      if (Servo1.read() == 180)
      //        for (int i = 180 ; i > 90 ; i -= 2)
      //        {
      //          Servo1.write(i);
      //          delay(40);
      //        }

      Servo1.write(90);
      break;


    case 3: // semi shake
      // Vibrate
      Serial.println(cases);

      analogWrite(motorPin, LOW);

      //      if (Servo1.read() == 180)
      //        for (int i = 180 ; i > 90 ; i -= 2)
      //        {
      //          Servo1.write(i);
      //          delay(40);
      //        }

      Servo1.write(90);

      break;

    case 4: // not scared
      // Servo back to original
      Serial.println(cases);

      digitalWrite(motorPin, LOW);

      //      if (Servo1.read() == 180)
      //        for (int i = 180 ; i > 90 ; i -= 2)
      //        {
      //          Servo1.write(i);
      //          delay(40);
      //        }

      Servo1.write (90);
      break;

  }

  delay(100);
}

void proximity() {

  float duration;
 // int distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(10);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = int((duration / 2) * 0.0344);

  if (distance >= 400 || distance <= 2) {
    Serial.print("Distance = ");
    Serial.print(distance);
    Serial.println("Out of range");
  }
  else {
    Serial.print("Distance = ");
    Serial.print(distance);
    Serial.println(" cm");
//    delay(10);
  }
//  delay(1000);

  //return distance;
}



Overall me and Stefan are extremely proud of what we’ve done in the 3 months we had, to get a very well built model and code to work cohesively was a big task for us but we have done very well. We’ve finally got something that made us proud to present and show. Our favourite part of creating Sniffles was how well he has gone down with the people using him, showing that sensory replication using electronics can put smiles on people’s faces.

Thanks for following the blog!

Thomas Bown & Stefan Gution

Advertisements

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 )

Google+ photo

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

Connecting to %s