Assignment 2 Interactive Devices

 

Reference:

or this assignment, the devices that I used were servo motors and ultrasonic sensors. The distance sensor would allow movement of the servo motor. When a person moves closer to sensor, it would detect some movement and allow it to move. I was a bit uncertain with the whole concept of my idea, but my idea was to initially show that once a person goes close to a sensor, the movement would stop, and the clothes would go to its original position. This fabric is supposed to move on its own when servo moves, I thought that adding string attached to the main fabric would allow other fabrics to move. IT worked, but the movement was too fast. The feedback that I got was the “Delay” function was the main issue since I wanted the servo to move slowly. Perhaps I could improve by making sure the servo was coded well.

It was my first try with the sewing method, so since Galina taught us that a little bit, I had the privilege of getting my own sewing machine from home. With some fabrics I took from Product design room, I used that for sampling and incorporated certain floral designs in my project. I am happy to know that I picked up sewing skills pretty fast.

 

Code for Assignment 2

 

// Include the Servo library

#include <Servo.h>

#include <Stepper.h>

const int trigPin = 6;

const int echoPin = 7;

int servoPin = 3;

int servoPin1 = 4;

 

 

long duration;

int distance;

int setSpeed;

Servo Servo1;

 

void setup() {

Serial.begin(9600); // Starts the serial communication

Servo1.attach(servoPin);

//  Servo1.attach(servoPin1);

pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

pinMode(echoPin, INPUT); // Sets the echoPin as an Input

pinMode(servoPin, OUTPUT);

}

 

void loop() {

{

 

digitalWrite(trigPin, LOW);

delayMicroseconds(10);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = duration * 0.034 / 2;

Serial.print(“Distance: “);

Serial.println(distance);

}

 

 

if (distance <= 20) {

Servo1.attach(servoPin);

Servo1.write(130);

delay(100);

Servo1.write(180);

delay(100);

}

if (distance <= 50 && distance > 20) {

Servo1.attach(servoPin);

Servo1.write(80);

delay(100);

Servo1.write(100);

delay(100);

}

 

if (distance > 50 && distance <= 200) {

 

Servo1.attach(servoPin);

Servo1.write(150);

delay(200);

Servo1.write(130);

delay(200);

}

if (distance > 200) {

Servo1.detach();

delay(100);

}

}

Author: Najiha

Always looking for something more.

Leave a Reply