Making Things Interactive

March 9, 2008

NoseTouch Sensor

Filed under: 7: Mid-Term Project,Joshua Smith — jssmith44 @ 8:29 pm

For this project I created a system that follows an individual when in the camera’s field of vision, and detects when the user touches his/her nose. Video is displayed below:The project consists of a Processing application (processing.org), an Arduino application (arduino.cc), and a hardware component.  The computer vision component is processed in the Processing application and the user’s physical location and state (nose touch or no touch) is passed to the Arduino application which drives the hardware.   The following Processing code uses the OpenCV framwork (http://www.intel.com/technology/computing/opencv/) and the Face Detect Library for Processing by Jaegon Lee (http://tokage.cafe24.com/facedetect/)  

import FaceDetect.*;
import processing.serial.*;  

FaceDetect fd;
Serial port;

int viewingAngle = 75;  //Camera's Viewing Angle
int MAX = 4;            // Max number of faces detected at once (for game)
int sPosition = 90;     //servo starting position

int[] x = new int[MAX];
int[] y = new int[MAX];
int[] r = new int[MAX];
int[][] Faces = new int[MAX][3];

void setup(){

  size(640,480);
  fd = new FaceDetect();
  fd.start(width,height, 10);
  println(fd.version()); 
  
 
  noStroke();
  println(Serial.list()); // List COM-ports

  //select second com-port from the list
  port = new Serial(this, Serial.list()[0], 19200); 
}

void draw(){
  background(0);

  Faces = fd.detect();
  int count = Faces.length;
  
   
  if (count>0) {
    for (int i = 0;i<count;i++) {
      x&#91;i&#93; = Faces&#91;i&#93;&#91;0&#93;;
      y&#91;i&#93; = Faces&#91;i&#93;&#91;1&#93;;
      r&#91;i&#93; = Faces&#91;i&#93;&#91;2&#93; * 2;
 println(i+1 + ": " + x&#91;i&#93;+", "+y&#91;i&#93; + ", " + r&#91;i&#93;);
 

  int divider = (width)/viewingAngle;  
  int sPosition= x&#91;i&#93;/divider;  //Calculate servo postion from Face X Coordinate
  sPosition = sPosition - (sPosition%1);
  
 
  

  //Output the servo position ( from 0 to ViewingAngle)
  port.write("s"+sPosition); 

    }
  
  }

    
  int&#91;&#93; img = fd.image();
  loadPixels();
  arraycopy(img,pixels);
  updatePixels();

 if (count == 0)  //identifies nose touch (no faces recognized)
    {port.write("w"); 
   delay(250); }

  strokeWeight(2);
  stroke(255,200,0);
  noFill();
  for(int i =0;i<count;i++) {
    ellipse(x&#91;i&#93;,y&#91;i&#93;,r&#91;i&#93;,r&#91;i&#93;);
  }
  
 
}

public void stop(){
  fd.stop();
  super.stop();
}

&#91;/sourcecode&#93;

  <span style="font-family:Verdana;font-size:13px;line-height:18px;white-space:pre-wrap;" class="Apple-style-span">The Arduino code to communicate with the processing code and drive the servo motor and LED eyeball: (note this code requires installation of the Arduino "Servo" library)</span>  


#include 
Servo servo1; 
int ledPin = 13;

void setup() {
  servo1.attach(14);
  servo1.setMaximumPulse(2500);
  Serial.begin(19200);
  Serial.print("Ready");
}
void loop() {
  static int v = 0;
  if ( Serial.available()) {
    char ch = Serial.read();
    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
        break;
      case 's':
        servo1.write(v);
        v = 0;
        break;
        
      case 'w':
      blink();
      v = 0;
      
      
    }
  } 

 Servo::refresh();
}

void blink(){
  digitalWrite(ledPin, HIGH);   // sets the LED on
      delay(100);                  // waits for .1 second
      digitalWrite(ledPin, LOW);    // sets the LED off
      delay(100);                  // waits for .1 second
    }

(the include file should be “Servo.H”, but I cant get it to show up in the sourecode editor)

Finally, the hardware component consisted of just an aluminum rod, rubber eyeball, red LED, and a servo motor. The Servo motor was connected directly to the Arduino board in the following manner: Orange: 5V; Black: Ground; Yellow: Analog Input 0;
The Led was connected to Ground and Digital Pin 13.  

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

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

Create a free website or blog at WordPress.com.

%d bloggers like this: