Project 2 – Week 3

In the past week we have looked at using different types of fabric as the peacocks tail to try and give a springy effect to the mechanism. This worked well but needed a lot of force to move the tail apart with the material involved.

We also tested out the ultrasonic range sensor and coded this up to the servo to replace the photocell. This will mean that as you get closer to the peacock the tail and head will gradually move depending on how close you get to the peacock. At the moment we only have one sevo coded in, we need to purchase further servo’s so that we code them and then wire them into our breadboard.

The fritzing diagram of the cicuit in the video above…

fritzing 1The code for the above video…

const int trigPin = 12; //defining the pins
const int echoPin = 13;

long duration; //this is the long variable for the travel time
int distance;   // the long variable for the distance

#include <Servo.h>
int servoPin = 9;
Servo servoMotor;

void setup() {

  Serial.begin (9600); //start the serial communication
  pinMode(trigPin, OUTPUT); //pin 12 is the output of the sensor
  pinMode(echoPin, INPUT);  //pin 13 is the input of the sensor
  servoMotor.attach(servoPin); //attach the servo to pin 9
}

void loop() {

  //-----------------------sensor setup------------------------------------

  digitalWrite(trigPin, LOW); //to make the sensor read as low
  delayMicroseconds(2); //delay 2 microseconds

  digitalWrite(trigPin, HIGH); //to generate the ultrasound wave
  delayMicroseconds(10); //stay high for 10 microseconds#
  digitalWrite(trigPin, LOW); //the set the trig pin back to low so the signal isnt constantly sent

  duration = pulseIn(echoPin, HIGH); //read the travel time of the soundwave and put that value in the variable duration
  distance = duration * 0.034 / 2; //multiply the duration by the speed of sound

  Serial.print("Distance: "); //pirnt the value of the distance on the serial monitor
  Serial.println(distance);

  //------------------Servo code------------------------------------

  if (distance > 20) //if disance is less than 20
  {
    servoMotor.write(80); //servo rotate 80 degrees

  }
  if (distance < 20) //if distance greater than 20
  {
    for (int i = 0 ; i < 80 ; i += 1) // integer i is set at 0; if i <80; i + 1 degree every 10th of a second
    {
      servoMotor.write(i); // servo rotate i
      delay(75); // delay 100
    }
  }
}

 

We also looked at ways to make the body of the peacock more aesthetically pleasing and more like a peacock instead of a box as in the previous model. The next step is to try and find a peacock doll to then house the main body and complete the look. This will make the model far more attractive and ready to be on show.

IMG_5044IMG_5046

Rob Harvey, Samuel Doubleday

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