top of page
Blog: Blog2
  • sal5014

P.Comp Week 5: The Start of a Monster

This week I was very excited to do my homework because I started out with an idea in mind. Several weeks ago I decided to make a monster for my mid-term and shared the idea with my classmate Helen. We decided that it would be a great project for our midterm and it would be complicated enough that it will incorporate several of our labs and even more.


This is what we'd like to make:


We want it to be able to produce sound(bark), jump at people, follow them with their eyes and perhaps even chomp at them?


This is the general idea and structure we'd like to use:


We're making a hollow base to hide our circuits. This base will be covered in fake chain and have wheels in order to move it. The structure of the monster will be made out of paper mache, clay and plaster in two parts: the bottom half is 75cm wide, and the top slightly bigger at 85cm wide in order to fit over the bottom and be able to hinge at the mouth. there will be a foam or clay base in the back to stop the top part from hinge-ing too far. We'll hide speakers inside the mouth and use LED strips for the eyes.


For this week we decided to work on the eyes using ultrasonic sensors that will detect distance in order to direct the LED strips so that it looks as if our monster follows you with its eyes.


We started with two sensors first:




When we managed to make our 5 sensors work and prepared our circuit.




The next step is to add the bit of code that will make our sensors be the input and the output would be the behavior of our LEDs (to fill left or right, depending on where our monster is looking).

This is the code we used to make the above circuit work:

int trigPin1=10; int echoPin1=11;

int trigPin2=13; int echoPin2=12;

int trigPin3=8; int echoPin3=9;

int trigPin4=7; int echoPin4=6;

int trigPin5=5; int echoPin5=4;

//array  SensorInput[]; //int SizeofArray = 3;

void setup() {   Serial.begin (9600);   pinMode(trigPin1, OUTPUT);   pinMode(echoPin1, INPUT);    pinMode(trigPin2, OUTPUT);   pinMode(echoPin2, INPUT);    pinMode(trigPin3, OUTPUT);   pinMode(echoPin3, INPUT);    pinMode(trigPin4, OUTPUT);   pinMode(echoPin4, INPUT);    pinMode(trigPin5, OUTPUT);   pinMode(echoPin5, INPUT);

}

void loop() {   long duration1, distance1;   digitalWrite(trigPin1, LOW);  // Added this line   delayMicroseconds(2); // Added this line   digitalWrite(trigPin1, HIGH);   delayMicroseconds(10); // Added this line   digitalWrite(trigPin1, LOW);   duration1 = pulseIn(echoPin1, HIGH);   distance1 = (duration1/2) / 29.1;

   if (distance1 >= 500 || distance1 <= 0){     Serial.println("Out of range");   }   else {     Serial.print ( "Sensor1  ");     Serial.print ( distance1);     Serial.println("cm");   }   delay(2000); long duration2, distance2;   digitalWrite(trigPin2, LOW);  // Added this line   delayMicroseconds(2); // Added this line   digitalWrite(trigPin2, HIGH);   delayMicroseconds(10); // Added this line   digitalWrite(trigPin2, LOW);   duration2 = pulseIn(echoPin2, HIGH);   distance2= (duration2/2) / 29.1;

   if (distance2 >= 500 || distance2 <= 0){     Serial.println("Out of range");   }   else {     Serial.print("Sensor2  ");     Serial.print(distance2);     Serial.println("cm");   }   delay(2000);   long duration3, distance3;   digitalWrite(trigPin3, LOW);  // Added this line   delayMicroseconds(2); // Added this line   digitalWrite(trigPin3, HIGH);   delayMicroseconds(10); // Added this line   digitalWrite(trigPin3, LOW);   duration3 = pulseIn(echoPin3, HIGH);   distance3= (duration3/2) / 29.1;

   if (distance3 >= 500 || distance3 <= 0){     Serial.println("Out of range");   }   else {     Serial.print("Sensor3  ");     Serial.print(distance3);     Serial.println("cm");   }   delay(2000);

  long duration4, distance4;   digitalWrite(trigPin4, LOW);  // Added this line   delayMicroseconds(2); // Added this line   digitalWrite(trigPin4, HIGH);   delayMicroseconds(10); // Added this line   digitalWrite(trigPin4, LOW);   duration4 = pulseIn(echoPin4, HIGH);   distance4= (duration4/2) / 29.1;

   if (distance4 >= 500 || distance4 <= 0){     Serial.print("Sensor4  ");     Serial.print(distance3);     Serial.println("cm");   }   else {     Serial.print("Sensor4  ");     Serial.print(distance4);     Serial.println("cm");   }   delay(2000);

  long duration5, distance5;   digitalWrite(trigPin5, LOW);  // Added this line   delayMicroseconds(2); // Added this line   digitalWrite(trigPin5, HIGH);   delayMicroseconds(10); // Added this line   digitalWrite(trigPin5, LOW);   duration5 = pulseIn(echoPin5, HIGH);   distance5= (duration5/2) / 29.1;

   if (distance5 >= 500 || distance5 <= 0){     Serial.println("Out of range");   }   else {     Serial.print("Sensor5  ");     Serial.print(distance5);     Serial.println("cm");   }   delay(2000);

// //template<typename SensorInput> void sortArrayReverse(SensorInput array[], size_t sizeOfArray, bool (*largerThan)(SensorInput, SensorInput));

}


9 views0 comments

Recent Posts

See All
bottom of page