Development Procedure
- December 8th, 2011
- Write comment
Potential Encounter Scenario (‘User’ Scenario)
You notice a strange orange glow emanating from a back alley on your way home from work. You’ve walked past this same part of town almost every day for the past three years and its always been the same litter strewn back street as always, but tonight you notice a strange orange glow emanating from the far end. You begin to move in for a closer, and see a small house-like shape with a pupil of subdued orange light in the center of the roof. It’s an eye. Whatever this paper craft model is, it appears to be sleeping. Not that it this thing has circadian rhythm – it’s just a piece of cardboard – probably some kind of arts project. Suspiciously, you step forward, and feel a sudden jump in your heart as the eye opens, throwing a beam of light onto your body, accompanied by a strange mechanical sound. Who the hell put this thing here? You take out your ipohone, capture a quick bit of footage, and head back home out of the cold.
TECHNICAL DESCRIPTION and STAGES OF DEVELOPMENT
Click for video.
Ping and Led Code:
const int pingPin = 7;
const int led = 9;
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode (9, OUTPUT);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
if (cm < 20) { //if object is closer than 20 cm to the sensor...
// turns the LED on
digitalWrite(led, HIGH);
delay (1000); // Wait 1 second
}
else {
digitalWrite(led, LOW); //if the object is further away than 20 cm the program turns the led off
}
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
Proximity Activated Servo
Ping and Serve Code:
const int pingPin = 7;
const int servo = 9;
#include
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
void setup() {
// initialize serial communication:
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
if (cm < 80) {
myservo.write(0);
}
else {
myservo.write(100);
}
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
}
Servo with Eye and Light Test
Rationale for Technology Choices
For detecting the proximity of the ‘user’ or the human animal who might happen across this on their way home from a late night at the office, I chose to use an Ultrasonic Rangefinder (over other proximity sensors such as an IR sensor) because the piece is designed to be situated outside where light interference would cause problems with detection.
The Ping US Rangefinder is fairly accurate to within about 3cm, which suited this work as the servo needs to be activated when the user is about one meter away. A potential problem with this choice is that the user may be wearing sound absorbing materials such as wool, but in my testing this did not appear to be a problem.
My choice of servo was limited due to financial constraints at the time. The flaw of this basic servo is in the distinct sound it makes upon activation – something which immediately reveals the electo/mechanical interior of what might other wise be a fairly enigmatic structure. A better choice would have been a small rotary motor which could have been set up to receive a smaller charge (thus quieter mechanical sound) that winds up a piece of fabric that would be painted to resemble a closed eye. The effect would have been closer to feeling like your approach suddenly woke this creature up, and its now looking you in eye.








