Project 2 – Week 6

During this past week, we have worked mainly on the prototype to get it work and made to a high standard of manufacture. We have mainly been focused on attaching the mechanisms that have been worked out during the project to the egg shape we have. After we managed to do that we began ‘beautifying’ the peacock. What we did here was add the feathers to the tail, attach the blue felt to the body. We have also made some legs for the peacock to make it look more alive.

File_000.jpeg

File_001

File_002

With the code this week we added in a ‘IF’ statement before each of the for loops in the last case. The reason for this is because us for loops we had were just constantly looping as they didn’t know what angle the servo was at. So, what we did was add an IF statement before each for loop to check the angle of the servo, then if the angle of the servo corresponds to the angle we have written in the IF statement it will then proceed with the for loop. To make the HC SR04 sensor visible and in a position where it can detect the movement of the hand closer to the sensor we have soldered some wires to it so that it can be placed on the base of our model.

#include <Servo.h> //include servos

int servoMotorPin = 9; //define servoPin
Servo servoMotor; //name the servo

int myServoPin = 10; //define myServoPin
Servo myServo; //name the servo

int theServoPin = 6; //define theServoPin
Servo theServo; // name the servo

int ledPin = 3; // define led pin

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 initiation for the distance

int peacockSwitch = 0; // intiating peackcockswitch to zero
int last = 0; // initiating last to zero

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(servoMotorPin); //attach the servo to pin 9
  myServo.attach(myServoPin); //attach the servo to pin 10
  theServo.attach(theServoPin); //attach the servo to pin 6
  pinMode(ledPin, OUTPUT); //pin 3 is the output of the LED
}

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: "); //print the value of the distance on the serial monitor
  Serial.println(distance);
  //--------------------------cases---------------------------------
  if (distance == last) {
    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: "); //print the value of the distance on the serial monitor
    Serial.println(distance);
  }
  if (distance != last) {
    if (distance < 50 && distance >= 40 && distance < last) // if distance is less than 60, greater or equal to 50 and less than last
      peacockSwitch = 0;

    if (distance < 40 && distance >= 30  && distance < last) // if distance is less than 50, greater or equal to 35 and less than last
      peacockSwitch = 1;

    if (distance < 30 && distance >= 20 && distance < last)// if distance is less than 35, greater or equal to 20 and less than last
      peacockSwitch = 2;

    if (distance < 20 && distance >= 10 && distance < last)// if distance is less than 20, greater or equal to 5 and less than last
      peacockSwitch = 3;

    if (distance > 55) // if distance is greater than 65
      peacockSwitch = 4;
  }
  switch (peacockSwitch)
  {
    //head moves back
    case 0:
      Serial.println(distance);
      Serial.println("|");
      Serial.println(last);
      servoMotor.write(30);
      delay(1000);
      break;
    //tail moves up
    case 1:
      Serial.println(distance);
      Serial.println("|");
      Serial.println(last);
      myServo.write(80);
      delay(1000);
      break;
    //tails spreads
    case 2:
      Serial.println(distance);
      Serial.println("|");
      Serial.println(last);
      theServo.write(80);
      delay(1000);
      break;
    //lights flash
    case 3:
      Serial.println(distance);
      Serial.println("|");
      Serial.println(last);
      //blinking led
      digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(50);                       // wait for 1/2 second
      digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
      delay(50);                       // wait for 1/2 second
      break;
    case 4:
      Serial.println(distance);
      Serial.println("|");
      Serial.println(last);
      if (theServo.read() == 80)
        for (int i = 80 ; i > 0 ; i -= 1) // integer i is set at 0; if i 
        {
          theServo.write(i);
          delay(20);
        }
      if (myServo.read() == 80)
        for (int i = 80 ; i > 0 ; i -= 1) // integer i is set at 0; if i 
        {
          myServo.write(i);
          delay(20);
        }
      if (servoMotor.read() == 30)
        for (int i = 30 ; i > 0 ; i -= 1) // integer i is set at 0; if i 
        {
          servoMotor.write(i);
          delay(20);
        }

      digitalWrite(ledPin, LOW);
      delay(1000);
      break;
  }
  last = distance; // reset so that the last = distance
}

Final diagram_bb.jpg

We have also produced two presentation boards ready for the exhibition in the atrium. The first board was produced on A2 paper, this has the flow chart of the code displayed on it, the circuit drawn in fritzing and the final images of the model. On the second board, we have produced a ‘how to’ guide for our model so that anyone who wants to use our product can do so.

All in one - Page 1.jpeg

Samuel Doubleday, Rob Harvey

Project 2 – Week 5

In the past week we have looked to put the project together and create the shape of the model by testing out what materials can be used to create a good-looking and structurally sound machine. The body will be created by using a foam core egg, cutting it in half and then hollowing this out using wood then as a stable inner core for the PCB and Arduino to attach to.

File_000

File_001

The head then will be attached on a pivot point ready to be pulled back and forth on command. The tail itself will be attached on a hinge to the back of the body with a servo attached to it by a steel bar to pull this up and down. The gears then will be attached to this body to make the tail fan out.

The coding this week came almost to a stand still point. We wrote out the remainder of the code for the switch cases however this code is still not working and switching between the cases. This needs to be discussed with the tutor as each part we attempt to change seems to do nothing. We need to talk to the tutor in an attempt to figure this out as countless hours spent online researching have not helped as of yet.fritzing 2

#include <Servo.h>

int servoPin = 9;
Servo servoMotor;

int myServoPin = 10;
Servo myServo;

int theServoPin = 6;
Servo theServo;

int ledPin = 3;

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

//boolean last = false;
//boolean current = false;
int peacockSwitch = 0;
//int noCases = 0;
int last = 0;

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
  myServo.attach(myServoPin); //attach the servo to pin 10
  theServo.attach(theServoPin); //attach the servo to pin 6
  pinMode(ledPin, OUTPUT); //pin 3 is the output of the LED
}

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);
  //--------------------------cases---------------------------------

  if (distance < 40 && distance < last)
    peacockSwitch = 0;
  Serial.println(distance);
  if (distance < 35 && distance < last)
    peacockSwitch = 1;
  Serial.println(distance);
  if (distance < 25 && distance < last)
    peacockSwitch = 2;
  Serial.println(distance);
  if (distance < 20 && distance < last)
    peacockSwitch = 3;
  Serial.println(distance);
  if (distance < 20 && distance > last)
    peacockSwitch = 4;
  Serial.println(distance);
  if (distance < 25 && distance > last)
    peacockSwitch = 5;
  Serial.println(distance);
  if (distance < 35 && distance > last)
    peacockSwitch = 6;
  Serial.println(distance);
  if (distance < 40 && distance > last)
    peacockSwitch = 7;
  Serial.println(distance);
  if (distance > 40)
    peacockSwitch = 8;

  switch (peacockSwitch)
  {

    //head moves back
    case 0:
      Serial.println(distance);
      servoMotor.write(30);
      break;

    //tail moves up
    case 1:
      Serial.println(distance);
      myServo.write(80);
      break;

    //tails spreads
    case 2:
      Serial.println(distance);
      theServo.write(80);
      break;

    //lights flash
    case 3:
      Serial.println(distance);
      //blinking led
      digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(500);                       // wait for 1/2 second
      digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
      delay(500);                       // wait for 1/2 second
      break;

    //lights off
    case 4:
      Serial.println(distance);
      //lights off
      digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
      break;

    //tail closes
    case 5:
      Serial.println(distance);
      for (int i = 0 ; i < 80 ; i += 2) // integer i is set at 0; if i <80; i + 2 degree every 10th of a second
      {
        theServo.write(i);
        delay(100);
      }
      break;

    //tail moves down
    case 6:
      Serial.println(distance);
      for (int i = 0 ; i < 80 ; i += 2) // integer i is set at 0; if i <80; i + 2 degree every 10th of a second
      {
        myServo.write(i);
        delay(100);
      }
      break;

    //head returns to original
    case 7:
      Serial.println(distance);
      for (int i = 0 ; i < 30 ; i += 2) // integer i is set at 0; if i <30; i + 2 degree every 10th of a second
      {
        servoMotor.write(i);
        delay(100);
      }
      break;

    case 8:
      Serial.println(distance);
      servoMotor.write(0);
      theServo.write(0);
      myServo.write(0);
      break;

  }
}

Rob Harvey, Samuel Doubleday

Project 2 – Week 4

In the past week we have looked to develop the tail further looking at how the wooden sticks could be hidden using a material other than paper. This solution would be to use some black tights and using its elastic material to also aid us in the retraction of the tail and to weave the peacock feathers in to. This black material will help us make the colourful feathers stand out in the model and give it a cleaner finish than just the wooden sticks.

IMG_5122

IMG_5123

 

 

 

 

 

 

 

We have also looked at adding switches to the code to allow the tail and head to move at different times depending on how far the user is away from the sensor. Witht he code we have managed to write out all the cases in which our code will have but we do not have the correct if statements in place as we are unsure on what they should be.

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

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

boolean distance = false;
boolean last = false;
boolean current = false;
int Cases = 0;

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);

  //------------------------cases-----------------------------
  current = distance;
if (
  cases();
}

void cases() {

  switch (Cases)
  {

    //30-40cm away
    //head moves back
    case 0:
      Serial.println(distance);
      servoMotor.write(30);
      break;

    //25-35cm away
    //tail moves up
    case 1:
      Serial.println(distance);
      servoMotor.write(80);
      break;

    //15-25cm away
    //tails spreads
    case 2:
      Serial.println(distance);
      servoMotor.write(80);
      break;

    //5-15cm away
    //lights flash
    case 3:
      Serial.println(distance);
      //blinking led
      break;

    //if current distance was 15
    //lights off
    case 4:
      Serial.println(distance);
      //lights off
      break;

    //if current distance 25
    //tail closes
    case 5:
      Serial.println(distance);
      for (int i = 0 ; i < 80 ; i += 2) // integer i is set at 0; if i <80; i + 2 degree every 10th of a second
      {
        servoMotor.write(i);
        delay(100);
      }
      break;

    //if current distance 35
    //tail moves down
    case 6:
      Serial.println(distance);
      for (int i = 0 ; i < 80 ; i += 2) // integer i is set at 0; if i <80; i + 2 degree every 10th of a second
      {
        servoMotor.write(i);
        delay(100);
      }
      break;

    //if current distance  40
    //head returns to original
    case 7:
      Serial.println(distance);
      for (int i = 0 ; i < 30 ; i += 2) // integer i is set at 0; if i <30; i + 2 degree every 10th of a second
      {
        servoMotor.write(i);
        delay(100);
      }
      break;

      //default:
      //  Serial.println(distance);
  }
}

Once we have learned this then the only thing left to do will be to put the model together and finally to test out the LED flashing for the flickering of the tail.

IMG_5120

IMG_5117

IMG_5121

IMG_5119

Samuel Doubleday, Rob Harvey

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

Project 2 – Week 2

Over the past week we have looked at developing the mechanism of the peacock’s tail and how it could be simplified to use only one servo. The solution to this would be to use gears and a pulley rod to move the tail outwards and only using one servo on the gears. This gives us an allowance to add more servos in the model to make the tail move upwards on command as well as the peacocks head to move up when needed.

img_4997img_5008img_5011

Another step we took to making the model better was looking at how the tail itself would be constructed using bigger pieces of wood as the base parts of the tail and thus allowing it to become more stable in construction.

img_5035

Finally we looked at how the overall shape of the model could be developed changing the box to a more natural shape and also looking at adding legs to the model and making the peacock look more realistic.

Samuel Doubleday, Rob Harvey

Project 2 – Week 1

In the past week we have looked at ways in improving our project by adding things such as sound to the mechanism to add more authenticity to the project as well as potentially changing the photocell to a motion sensor to get the peacock to react more to its surroundings.

Image result for motion sensor arduino

We have also looked at ways in which the peacock tail could be more appealing looking into thin materials and textiles which could be used as the feathers in the tail. The fabric could be a range of colours and will make the product much more appealing to use and to look at.

Image result for peacock fabric

Another couple ideas we looked as was adding lights to the tail; making the tail light up in a different array of colours when triggered and the tail was moving. On top of this we have looked to improve the model and how the tail mechanism works to try and make the mechanism move as smoothly as possible, making it as efficient as we could.

Rob Harvey, Samuel Doubleday

Week 5 – Arduino

In our final week we have continued to develop our model for our mechanical peacock tail; using experience from past attempts making the arm of the servo move to a certain angle and connecting the two together along with a photocell as our trigger to make the sequence work.

file_001

We faced a few difficulties when creating the model firstly by attaching the servo to the tail, making the tail evenly space out and finding the right code to make the servo spread the tail out quickly and then retract slowly once reaching its optimum angle.

file_002

The solution to help us out with the tail was to use 2 servos in the circuit to allow the arm to start vertically and both spread out to their respective angles. Once this problem was solved we created the final model and attached the servos to the tail, leaving the Arduino and breadboard in a neatly created box hidden away. The photocell was then left outside the box to allow the user to cleanly touch the sensor and trigger the mechanism.

file_004

Samuel Doubleday, Rob Harvey

Week 4 Arduino

During this week, Rob and I have considered the coding of a servo and how we could link it to the coding we already learnt about photocells. We have managed to wire the code so that when the photocell is covered (dark) the servo will rotate. Then when the servo is in natural light it will stay in its original position.code

We have also created a new prototype of our peacock tail. This time we have used lollypop sticks and paper to mimic the shape of the tail and how it fans out.

img_4884

We will be able to link both the coding we have done and the prototype together in the next week. This will bring us towards the closing stage of our project. We also are thinking of wiring in a speaker so sound can be played when the photocell is covered also. We are considering how to code this in and how we could include it within our prototype.

Samuel Doubleday, Rob Harvey

Week 3 – Arduino Project

This week Rob and I have been prototyping the two different movements we may use in our Arduino project. We have also done research into sensors and how they can work within Arduino.

file_002

The first movement we have prototyped is the tail of the peacock. We have explored the way it fans out and have prototyped this using origami. The reason we have done this was so we could visualise the movement further. We have also now started to research into ways we could place this into a product.

file_000

The other movement we have research is the opening of an oyster in response to heat. Again, we have made an origami model just like an oyster with a mouth which opens. This is a more basic movement and would be easier to make into a product but may be too basic for our project. Therefore, we haven’t decided on a final movement yet.

 

Samuel Doubleday – 15021736

Rob Harvey – 15008666

 

Week 2 Arduino Project

This week Rob and I looked further into the design of the oyster shell and the peacock feather. We are still leaving the possibilities of two different movements in place, we are looking to narrow it down to one in the next week.

img_4842

We have two ideas for an oyster shell. The first design is for a jewellery box. The jewellery box will open when heat is detected near a sensor. This is a very good possibility of a product and reflects the movement of the oyster very well. The other design for the oyster, is a fan which when a sensor detects heat it opens out and begins to rotate the fan

jewellery-box-large_02

The one design we have for the peacock feather is a spice rack. When the sensor detects movement the spice rack will rotate the arms round to form a fan shape just like the tail of a peacock.img_4843

Samuel Doubleday – 15021736, Rob Harvey – 15008666