The Near You project was my final project for Rest of You, one of the best classes I’ve had at ITP, and the beginning prototype for my intended final project. The basic idea is that, when someone looks at a picture of you, you get a warm feeling of being thought of. For this project, the picture the visuals of a Processing sketch that is taking images from the attached camera and running face detection software to determine if anyone is looking at the picture. If someone is looking, the sketch sends a message to a linked bluetooth device to heat up a locket that the pictured individual is wearing.
Full circuit with Arduino, Bluetooth, and the resistor heater. Ignore the Arduino Pro Mini board. That’s part of a transition I’m making…
My circuit is displayed above. The hardware is programmed in Arduino and uploaded to the Arduino Duemilanove. The Duemilanove’s TX and RX pins are connected to a BlueSMiRF Bluetooth module. Pin 7 is connected to an LED for debugging purposes (it blinks on the completion of every loop). Pin 8 is hooked up to a transistor to switch on and off the 9V heater circuit.
Processing Code
import hypermedia.video.*;
import processing.serial.*;
Serial myPort; // The serial port
OpenCV opencv; // Face detection
boolean firstContact; // true if this is the first exchange with the bluetooth
boolean isLooking; // true if face detection recognizes a face in the camera
PImage b; // image that is shown in the frame (preferably of the locket wearer)
void setup() {
size( 732, 543 ); // change according to the size of framed picture (b)
// setup face recognition
opencv = new OpenCV(this);
opencv.capture( width, height );
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load the FRONTALFACE description file
// List all the available serial ports
println(Serial.list());
// Last time I used this my bluetooth module was [6] on the list.
// change the number according to where your bluetooth module appears as
// don't forget to setup your bluetooth with system preferences before
// trying to find it with Processing
myPort = new Serial(this, Serial.list()[6], 9600);
firstContact = false;
isLooking = false;
// setup image of loved one
b = loadImage("grad.JPG");
image(b, 0, 0);
}
void draw() {
}
// check if someone is looking at the picture and respond
boolean checkIsLooking () {
isLooking = false;
opencv.read();
// detect anything ressembling a FRONTALFACE
Rectangle[] faces = opencv.detect();
// draw detected face area(s)
fill(255,0,0);
for( int i=0; i
isLooking = true;
rect(width-10, 0, 10, 10);
}
if( isLooking ) {
return true;
}
return false;
}
void serialEvent(Serial myPort) {
println("starting serial event");
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
if (myString != null) {
myString = trim(myString);
println( myString );
// if you haven't heard from the microncontroller yet, listen:
if (firstContact == false) {
if (myString.equals("hello")) {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you've had first contact from the microcontroller
myPort.write('A'); // ask for more
}
}
// if you have heard from the microcontroller, proceed:
else {
// split the string at the commas
// and convert the sections into integers:
int sensors[] = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
}
// if someone is looking, then true, if no one is looking then send false
// this is the section that tells the arduino whether to heat up or not.
if( checkIsLooking() ) {
myPort.write( 1 );
println( "You're looking" );
}
else {
myPort.write( 0 );
println( "You're NOT looking" );
}
}
}
Arduino Code
int ledPin = 7; // connects to LED for debugging
int transistorPin = 8; // controlls circuit of 9V battery and heater
// through a transistor
void setup()
{
pinMode( ledPin, OUTPUT );
pinMode( transistorPin, OUTPUT );
digitalWrite(ledPin, HIGH);
digitalWrite(transistorPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
digitalWrite(transistorPin, LOW);
// start serial port at 9600 bps:
Serial.begin(9600);
establishContact();
}
void loop()
{
// flash ledPin for debugging purposes
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
// check for message from Processing.
if (Serial.available() > 1) {
int inByte = Serial.read();
// if Processing sends a 1, that means the resistors should heat up
if( inByte == 1 ) {
digitalWrite( transistorPin, HIGH );
}
else {
digitalWrite( transistorPin, LOW );
}
// respond to Processing to get next value
Serial.println("A");
}
delay(10);
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("hello"); // send a starting message
delay(300);
}
}
Reference
Resistor heater tutorial
Controlling high current loads with transistors tutorial
Related posts:
- Connecting My Foot With My Sister’s Face My Sister & I Have Issues… Anyone who knows...
- Power Glove Concept Communication has always been something of interest to me....
- eGlove Because two gloves may be better than one but...
- Physical Computing Final: Life (week 1, Monday) Earlier in Life… I have already written code to run...
- Marionette…OF DOOM Concept Often, my ideas just come to me and I...

One Trackback
[...] Read the rest on my blog. [...]