Aarhus Universitets segl

Jøhnkes blog

Hi there.

This blog is used to document the design process involved in constructing my bachelor-project (both theory and practical stuff). I’ve now finished my bachelor-project (turned it in on the 8th of February) and have moved on to create new versions of Thing (the practical outcome of the project). I’m also in the process of rewritting/updating the bachelor-paper.

The blog includes documentation from the different Arduino/Max MSP/Processing projects that I’ve gone through (mainly my obsession with the pulse sensor). The documentation will sometimes be in the form of written-out tutorials (aimed at beginners like myself) and sometimes in the form of code examples, pictures, Fritzings (Visualized layouts of Arduino boards and connections) and other awesome documentation.

Feel free to contact me at rjoehnke@hotmail.com if you have any questions.

Enjoy!

  • Pulse Sensor with LED connected
  • Pulse Sensor without LED connected (Fritzing, Arduino and Processing code is up – This links to the most recent one – different versions of this setup appears a couple of different places)

 

A short video showing the Poul version of Thing in action.

Thing is designed to help you calm your thoughts and help you slow down. Using infrared light, Thing can detect the pulse in your thumb and use that data to change the brightness of a red light. It’s pretty cool. The idea is quite simply to focus your attention on the pulsating light and calm your thoughts, just as one would do when meditating.

Walnut!

The last  two weeks or so I’ve spent wondering what the next version of Thing might look like. Been sketching a bit and just collecting random thoughts and ideas. This week I went down to Godsbanen (for those of you in Aarhus go check it out, you can read more about it here), where they have a wood-shop with all the machinery that your heart desires. It’s brilliant and pretty cheap as well. And they’re pretty helpful too as I was taken on a grand tour of nearly all the different machines.

So, I went down there and bought some walnut wood as I love the brownish color and grain. Got some help cutting it up and then drilled a few holes I knew the size of. Whats new about this version is that instead of a diffuse red LED Ill be using a super-bright LED. The LED will have its own box so it can be positioned in various ways as a kind of projector. More on this later.  I’ll upload some sketches and more pictures in the coming week.

The new casing

So…

It’s now been a couple of days since I finished my bachelor, and let me tell you, I still have a bit of a “bachelor-hangover”. I could definitely use some time off. Alas, anthropology needs my time and effort, and a lot of it!

Nonetheless, I plan on making a very short introductory video to Thing tomorrow, just to put up on the site for Lone and the censor to have a look at if they so desire. I plan on a better produced final video sometime, maybe I’ll recruit help from one of my friends who’s good at shooting videos and editing them. I also plan on a new version of Thing. 2.0. It’ll be wireless (not really) in the sense of not being connected to the computer, but instead driven by a battery. It’ll feature advanced technology such as a on/off switch and a super-bright LED. For the project I need to find another telephone chord, don’t know where though. Shoulda’ taken two while I was at it last time. Oh well.

I also need to update the code and fritzing while also finishing the write-up on the pulse-sensor tutorial. Lots to do!

It’s the 5th and its stressing

3 days until deadline day and its coming along OK. I’m finishing up the final sections. Need to review the abstract, introduction and well-being sections. Write the last part of the Borgmann section, the “How to design a borgmannian toaster” and the section presenting Thing. Ive got my work cut out for me. My goal is to be done thursday at 17:00, send the paper to Kasper (fellow student) who has kindly agreed to look the paper through and then use the remaining time to polish it off and set the whole thing up in a document. Wish me luck.

February 1st – 3rd – Short Update

So it’s February 1st. The paper is coming along ok, I’ve written 16 pages, though I need to remove the gibberish, write some more stuff into it and tie it all together. Plus all the fidgeting with getting the right text setup and such. I may also have to do the concept video next week if I get the time I got a lot of work to do so the next week up until the deadline on the 8th is going to be hectic (also because the new semester started yesterday and there shitloads to do/read for my anthropology class though that will have to wait).

Two days have passed and Ive gotten quite a bit of work done on the paper. Right now Im trying to finish up the Borgmann section of the paper describing the distinction between focal things and practices and devices. The next step is the section dealing with the promise of technology and then the conclusion on this. Still need to revise the introduction and the “well-being” section, but that shouldn’t take more than a day. Also need to touch up the abstract.

After Im done with the Borgmann section what remains is the “Guidelines for designing digital artifacts and questions to ask yourself before setting it free” – which is also close to done but needs revision too. And maybe rewrite and add a bit to it.

Joehnke out

Sunday

The last couple of days Ive been working hard on the paper. Ive narrowed in my focus on Albert Borgmann and been reading a lot of literature on slow technology and the likes: mostly on how to include “human” values in HCI. Its pretty exciting stuff. Also been re-reading a couple of the main articles Im using for the paper, mostly Fallman and Sengers. Ive made some progress on the paper and have written a lot of separate sections when thoughts on something came up. I need to go through the paper from start to finish and connect the sections into a coherent text and also write some more to it. I bit worried its gonna end up messy and with too “broad” a focus, but the subjects Im dealing with – happiness, the good life and technology – are pretty vast and complex in size, so I guess the messiness really cant be avoided.

In other news the Borgmann book I ordered last week arrived by mail yesterday, so Ive been reading a few pages in that. Its a tough read and I think ill need to read it twice to fully grasp it but its good stuff.

It’s To-Do-Tuesday and Crisis-Wednesday

I’ve got a couple of things on my to-do list for today. Ive been reading a couple of articles and writing bits and pieces into the paper, without really coming closer to a research question. Though I plan on emailing one to Lone tonight.

Practical to-do-list:

  1. Make a plug-and-play pulse sensor (do this when you need to work with your hands).
  2. Make an introduction video to Thing and take pictures.
  3. Maybe see if its possible to get the name engraved in the top case

Update at the end of the day (wednesday morning instead):

I’m having a bit of a crisis. I can’t seem to get any close to a concrete question/topic for the paper. Theres a lot of different angles to be put on Thing. I could talk about the bodily experience of connecting to your pulse (don’t really find that interesting), or how technology can be used to slow down/reflect/moment of mental rest, how can HCI benefit from a philosophy of technology concerning the inverting of the desire for efficiency.

Update at the end of Wednesday: Crisis averted for now

So this is my problem statement as of today. It needs to be more concise but we’ll get around to that later in the writing process, now I just want to get something down on paper.

How can Albert Borgmann’s philosophy of technology be used to inform the design of digital artifacts that promote happiness through contemplation and solitude?

It’s Saturday and the Pulse grows strong today!

Had a very brief relaxation session with Thing today. Im worried the beating of the pulse is stressing so Ive relaxed the LED a little bit (increased the range of the brightness so to make it less intensive) – hope that helps. Will have another session later. On the lighter side of things my pulse seems extra strong today. Have a look:

Saturdays strong pulse. Not bad at all!

It seems the clearest pulse is when you start my pressing lightly and keep adding a little bit of pressure until you’re within the 600-800 range (reading of the analog input). Note: Also works best when your hands are warm.

Had a meeting yesterday with Lone (the bachelor project supervisor/guide). We talked about a few things but mostly moving on and trying to formulate a research question for the paper. She also tried out Thing but though she eventually found it she had a hard time getting good readings of her pulse. Im starting to think its gotten so used to me that it doesn’t want to work with anybody else.

But the talk yesterday also left me somewhat uneasy. Theres not a lot of time left to write this thing and even though the last month has been awesome its also been in a playing-around-no-strings-attached kind of way. Now things are starting to buckle up. So I have to get moving and read a couple of more articles to find out what the paper’s focus is going to be. I’m looking forward to it but it seems more of a “choir” than working on the practical stuff did.

The End of Thing(s)

The last couple of days have been spent finishing up the design of Thing. Ive spent (way too much) time soldering and doing a number of other small tweaks. Ive enjoyed this week a lot but I’ve kinda been neglecting the theory a bit so Ill work on that this weekend :-). However the time spent on the practical stuff has paid off since Ive got everything wired up, the code running and the device functioning as it should. All thats left is applying the last coat of Tung Oil (look it up) to the container and figuring out how to keep everything put inside the container, so its easy to open and close without having to shuffle everything around to make place.

I also need to update the code and maybe the Fritzing as well here on the blog. When I have the time I plan on making at least one “ready-to-go”/plug-and-play heartbeat sensor so other people can explore using your heartbeat as an input. Need to make a video of the design working as well and put it up on youtube.

A Touch of Progress

Finally dragged myself up to the lab today after a couple of days recovering from New Years Eve. Today (and yesterday) Ive been reading up on Albert Borgmann, or rather Daniel Fallman writing about Borgmann. Love that guy – both Borgmann and Fallman. Don’t know why I haven’t heard of them before.It was a coincidence I stumbled upon them as I was talking to a fellow student, Jonas, who has an office space here in the building where the lab is. He had written an exam on Borgmann which he sent to me (but I have yet to read).

Any Given Sunday

Sunday in the Lab

Was supposed to write an entry of what I did sunday, but I guess I never got to it – and now I’ve forgotten. What I do remember is that I did some work on the container (the wooden block to the right in the picture).

Back in the Lab after Christmas Break

Heartbeat after christmas

Today Im back in the lab after a good 6-7 days spent on christmas break. Work starts today though I’m not exactly sure where to start.

Theory:

The theory has been somewhat neglected so I will probably read a few articles and write a bit – need to figure out how to structure the paper and also lay down exactly what the subject is and what it is I’m concentrating on. Found a good articled recommended by a fellow student – its called “The New Good” by Daniel Fallman and it explores how a philosophy of technology can contribute to HCI. Seems relevant and interesting. Overall I find the whole STS (Science and Technology Studies) ordeal and an overall philosophizing about technology really awesome. As of now my subject headline is Contemplative Technology: Designing for Happiness.  It doesn’t seem to quite hit the nail on the head but its getting there.

Practice:

Also need to work on the practical side to perfect the physical design and most important the feedback mechanism is still vague. Heres a “to-do” list:

  1. The shape of the final device (round, square etc.) and spacing between the LED and Transistor.
  2. Shape of the box that will contain the Arduino and the breadboard (a lot of small practical issues concerned with this)
  3. Closing mechanism: got a great idea to use magnets imbedded in the sides (so its easy to open and close)
  4. The wiring needs to come out of one hole in the bottom. A solution could be to drill the two holes for the LED and transistor at an angle – see illustration below:
  5. Need to carve out the “insides” of the box to allow room for the Arduino, breadboard and power supply. I have a router to do this (and a chisel), but I’m concerned it won’t work on such a small piece of wood.

Drilling plan

Thursday’s & Friday’s Progress

Friday:

Friday Picture

Today I’ve been playing around with the Arduino and Processing Code (will be up soon). I’ve smoothened out the readings from the analog input by averaging it out using this example and changed the visualization in Processing using this example (Scroll down to the bottom and just Copy/paste the code into Processing). Also started reading an article titled “The New Good” which is on the philosophy of technology and its relevance for HCI. Pretty interesting.

Found out that it might be more comfortable to hold the device in a different way. More on this later.

A smooth pulse

Thursday:

Today I have made a slight modification to the physical device – made two of the corners round to improve comfort. BAM! Also soldered the end pieces of the wires better and used “krympeflex” so its easier to stick them in the breadboard (still sucks).  The next steps are as following:

  1. Work on the theory side of things
  2. Figure out how to amplify the transistor with an Op Amp (might need help/new parts to do this) – this will make the readings even more accurate
  3. Solder the breadboard together
  4. Make a casing for the breadboard and the Arduino (maybe use a mini-arduino) and find a good looking cable that will run from the device to the arduino
  5. Make the finished prototype – find a suitable wood and finish it with tung oil
  6. Figure out the physical feedback mechanism (!) – See what happens if you pass electricity through aluminum
  7. See if theres a cooler/more smooth way of visualizing the input in Processing (ie. a line going across)

Thursday’s Progress

Thoughts on and pictures of the physical design of the device (work in progress)

Now that I’ve got the heartbeat monitor somewhat working Ive been wondering how to incorporate the sensor into a physical object. One of my ideas is a piece of wood with the sensor on top.  The user would then wrap her hands around it and place her thumb on top. I still haven’t figured out the feedback mechanism (ie. outputting the heartbeat as heat, light, vibration).

The prototype device

And idea would be to hack into a PS3 or Xbox controller and remove the vibrator device and place it inside the stick and have it respond to the heartbeat readings (easier said than done). But there’s something not very pleasant about the vibrating thing, maybe because it reminds me of the stress of having your mobile phone vibrate on incoming calls. Ill figure it out eventually.

So today was by far the most productive day yet. The gallery below shows the progress I’ve made. I just finished up the first prototype, which is a piece of wood with the IR-LED and IR-Phototransistor placed inside two holes I drilled through the wood. I soldered the wires together and finished it of by sanding the whole thing down to make it more comfortable to hold. I also made an attempt at making a clip like the ones you see in hospitals – worked out pretty good but was very uncomfortable – gave the best readings thus far (maybe because it squeezed the finger).

Pictures from today:

Pictures, Fritzing and Code for the Pulse Sensor

NOTE: This setup has been improved somewhat – look at the more recent posts above this one.

So in my experimental phase of this bachelor-project Ive been looking at different ways to gather input from the Arduino. As noted above I have, amongst others, been exploring the temperature and humidity sensor, the MQ 3 gas-sensor which can detect ethanol (alcohol to lay people), and last but not least the sending and receiving of infrared light, in an attempt to detect a persons heartbeat. Theres something fascinating about being able to register (and see/feel/hear) a persons heartbeat (Im still trying to figure out what to do with this input – that is, once I get it up and running!). As I’ve also described below in the post written in Danish, the IR heartbeat sensor works by sending infrared light from the IR-LED to a IR phototransistor. By placing the two beside each other and placing your finger on top of the two, the infrared light will travel from the IR-LED through your finger and into the IR phototransistor. It so happens that with every beat of your heart blood is pumped out into the veins of your body, and when that blood surge reaches your fingertip, the resistance is increased – and the infrared light has a harder time getting through. In this way a heartbeat can be detected by reading the amount of infrared light received by the IR-Transistor.

(Note: Fritzning is an awesome (and free) program you can use to visualize and share your Arduino projects, see http://fritzing.org)

Fritzing:

 

The Arduino code: (based on cmpercussion.blogspot.dk/2009/07/heartbeat-sensor.html)

// Pins
const int sensePin = 0;

// Hearbeat detect variables
int newHeartReading = 0;
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// initialize the digital pin as an output:
}

void loop() {
newHeartReading = analogRead(sensePin);

delay(200); // Short delay for faster response to light.

// Read analogue pin and print
Serial.print("Input value is: ");
Serial.println(newHeartReading);

}

En oversigt og intro til Bachelor-bloggen

Jeg vil det næste stykke tid forsøge at holde bloggen opdateret med nye skridt i min process hen mod et færdigt bachelor-projekt. Det er nemlig sådan at bachelor-opgaven på Digital Design skal indeholde både en praktisk og teoretisk del, hvoraf jeg vil benytte DD lab til det praktiske. Slutproduktet er en 15-20 siders skreven opgaven samt et stykke digital design.  Jeg vil holde bloggen dels for min egen skyld (så jeg har overblik over designprocessen og min egen tankestrøm) men til dels også for at der forhåbentligt er andre der kan følge med og drage inspiration fra min eksperimentering med de forskellige designmaterialer/programmer osv.

Som det ser ud nu (den kedelige del om teori og andet generelt – scroll lidt ned for det “tekniske”):

Det er gået trægt med bachelor’en indtil videre – af forskellige årsager. Derfor har jeg valgt at tage sygeeksamen (hvilket blot betyder, at jeg skal aflevere engang i Februar 2013 i stedet for nu på fredag d. 14 december). Nå, men trods andre snart er færdige med deres bachelor-opgave har jeg endnu ikke formået at få emnet på plads, selvom jeg har haft mange og svær overvejelser om det. Det jeg ved er dog:

Det der interesserer mig i den teoretiske afdeling er hvordan vi mennesker forholder os til teknologien og om vi overhovedet har brug for den. Amerikaneren Adam Greenfield har skrevet en nok så interessant bog der hedder “Everyware: The dawning age of ubiquitous comupting”, hvori han taler om netop den fremtidige teknologiske udvikling (og hvilke udfordringer der er ved ubicomp). Det er god læsning. Det underliggende spørgsmål som jeg egentlig ønsker at få svar på er om vi bliver lykkeligere af proppe vores hverdag med mere og mere teknologi (som I måske har fanget er jeg af den modsatte holdning). Og hvem er det egentlig som driver teknologiudviklingen fremad? Er det de store teknologikoncerner og andre interessenter der udelukkende har til hensigt at skabe profit, eller er det et underliggende menneskeligt behov for at kunne gøre mere/hurtigere/nemmere? Måske en kombi – hvem ved. Det andet emne der interesserer mig er forholdet mellem det analoge og det digitale – med andre ord er der nok tale om det der populært hedder Tangible User Interfaces (eller TUI). Det hænger måske lidt sammen med ovenstående i den forstand at jeg er overbevist om at de rigeste og med meningsfulde teknologier er de der formår at kombinerer det digitale og analoge på den bedst mulige måde. (Se evt. mit yndlingsprojekt Pas a Pas her: http://pasapas-project.com, eller et andet mere kunstnerisk eksempel her: http://pasapas-project.com).

I DD Lab:

 

De sidste par uger eksperimenteret en hel del med Arduino/Max MSP/Dul Radio i mit forsøg på at komme nærmere et emne/produkt til bachelor-opgaven. Det som jeg desværre har lidt svært ved er at forbinde det jeg synes er teoretisk interessant med det jeg synes er praktisk interessant. Lige nu sidder jeg og arbejder med at udvikle en eller anden type (indser hvor forvirret jeg selv er) meditationsværktøj. I den forbindelse har jeg over sommeren udviklet en kærlighed for træ, som jeg rigtig gerne ser integreret i mit slutprodukt. Udover det har jeg leget lidt med DUL-radioen som input (lagt den indeni en træklods – http://www.digitalurbanliving.dk/news/news/dul-radio.php ). Har bl.a bygget en simpel step-sequencer der kan styres af DUL’en, i samme omgang har jeg genbrugt et program vi i læsegruppen lavede sidste år hvor man vha. DUL’en kan manipulere lidt med Carly Rae Jepsens stemme. Jeg er derefter gået videre til Arduino (fedt program/microcontroller der kan alverdens ting, www.arduino.cc), hvor jeg har arbejdet med forskellige sensorer som input – bl.a bygget en breathalizer der vha. en gas sensor kan måle mængden af ethanol (alkohol) i ens blod, en temperatur-måler, og sidst men ikke mindst projektet nævnt i den forrige post – en pulsmåler. Der er 

et eller andet ret interessant ved at bruge et hjerteslag som input (se evt. Lorenzo Hemmers “Pulse Room” her: http://www.lozano-hemmer.com/pulse_room.php). Vha. Arduino-boardet kan man fra en infrarød-LED sende infrarødt lys op gennem fingeren, og ned i en modtager (IR-transistor) placeret lige ved siden af. Idet ens hjerte banker pumpes der blod ud gennem kroppen og ens finger fyldes med blod. Det infrarøde lys har derfor sværere ved at trænge igennem fingeren – og denne forskel kan så registreres af IR-transistoren på Arduino-boardet. Det er garanteret lidt mere kompliceret en som så, men det er sådan jeg umiddelbart har forstået det! Opstilling m.m. kommer (forhåbentligt) herop imorgen. Se evt. http://www.youtube.com/watch?v=BAp1snPchT4 (nøjagtigt det jeg forsøger at lave) og http://cmpercussion.blogspot.dk/2009/07/heartbeat-sensor.html.

Jeg har nok glemt en helt del, det må komme op senere. En sidste ting er at jeg den sidste uges tid har fået øjnene op for Processing – som en måde at visualisere den data der bliver udskrevet fra Arduinoen. Meget mere om det på et senere tidspunkt. Processing er et gratis program der kan hentes her (det ret sejt): http://processing.org.

(Der kommer som sagt billeder op imorgen af alle mine materialer m.v., det er lidt lettere at forklare tingenes tilstand derudfra)

Eftertanker og næste skridt:

1.) Få puls-måleren til at virke optimalt – betyder nok at jeg må købe en bedre og mere stabil IR emitter og detector ved Elektronik-lavpris.dk. Samt lave noget signal-processing i Arduino og/eller Processing.

2.) Få styr på bachelor-opgavens teoretiske del og dennes forbindelse til det praktiske.

Jeg tror forresten jeg vil skrive fremtidige posts på engelsk, så der muligvis er flere der kan få gavn af det jeg skriver/laver.

Bachelor-projektets begyndelse

Lige nu sidder jeg og forsøger på at lave en sensor der, vha. Arduino, kan registrere en persons puls. Det sker ved at infrarødt lys sendes op gennem fingeren og reflekteres ned i en modtager, der kan registrere mængden af IR lys. Sensoreren udnytter det faktum, at hver gang dit hjerte banker sendes der blod ud til resten af kroppen. Mængden af lys der reflekteres varierer derfor alt afhængig af mængden af blod i din fingerspids – og derfor kan din puls måles. Hvad det skal bruges til er ikke helt klart for mig endnu, men forhåbentligt kommer det hen ad vejen!

Jeg vil til at cykle 4.3 km ud til Tilst for at hente en IR sender og IR modtager hos Elektronik Lavpris, da vi desværre ikke har nogen her i labet. (Fik jeg ikke gjort)

 


Heartbeat Sensor Tutorial (with LED)

[Under Construction]

This project is fairly simple and extremely cheap. (Disclaimer: embarking on this project will require some effort). In the end you’ll hopefully have a heartbeat sensor that works by sending infrared light up, through your finger, and into a phototransistor that can measure the amount of light passing through. When your heart beats, blood is pumped from your heart out into your body. When blood fills your fingertip the infrared light has a harder time getting through to the phototransistor [for example, when there is less blood in your finger the amount of infrared light might read 800, the light passes easily through your finger, however, when blood enters the finger it blocks the infrared light from passing through resulting in a reading of 400]. What you’ll see when you read the input is small “spikes” in the readings indicating a heartbeat. What I’ve also done is Ive brought the data into Processing and visualized it (the Processing code can be found below). I’ve also attached an LED to the circuit allowing for the pulse to be outputted as light as well. The heartbeat input can be outputted in a variety of ways, including using a Piezo Speaker.

In a nutshell: Once you place your finger on top of the device, “connecting” the LED and IR-phototransistor, infrared light is sent through your finger and into the IR-phototransistor, which measures the amount of infrared light flowing through your finger. Once your heart beats it fills your fingertip with blood, making it harder for the infrared light to get through. This change can be seen by reading the Analog Input on the Arduino (which reads the IR-phototransistor). The data (numbers from 1-1000) can then be used to make an LED glow depending on the amount of infrared light flowing through.

For this project you will need the following materials:

  1. An Arduino board (I’m using an Arduino Uno)
  2. Arduino which can be downloaded here (it’s free)
  3. Processing (also free!)
  4. IR-LED like this one.
  5. IR-Phototransistor like this one (theres both an emitter/IR-LED and a detector/phototransistor). There are a couple of different versions of this and as long as they have the same wavelength they will work fine (either 800 or 950nm, I think).
  6. 2 x 3904n transistors
  7. 5 x Resistors of varying resistance
  8. 1 x LED (the ones that are “diffused” work best, like this one. It’s also possible to buy LEDs that are ‘superbright’, which instead allow light to pass through a narrow channel making for a much more focused light).
  9. X amount of jumper wires

 

Fritzing

Pulse Sensor New and Improved – Now with light

Arduino Code:

/* Based on
*
* Can you feel my heart beating?

* james robert thompson
* 10/23/2010
*
* Rewritten by Rene Joehnke
*/

const int arrayLength = 90;
int arrayIndex = 0;
int array[arrayLength]; 
int arraySum = 0;
int arraySumOld = 0;
int sensorValueOld;

int pulse[arrayLength];
int pulseSum = 0;

int IRLed = 8;
int brightnessPin = 9;

int rangeLEDmin = 650;
int rangeLEDmax = 750;

// Define the number of samples to keep track of. The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input. Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
const int numReadings = 25;

int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average

int sensorValue = analogRead(A1);

// int inputPin = A0;

void setup() {
Serial.begin(9600);

for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;

pinMode(IRLed, OUTPUT);
pinMode(5, OUTPUT);
}

void loop() {

digitalWrite(IRLed, HIGH);

// subtract the last reading:
total= total - readings[index]; 
// read from the sensor: 
readings[index] = analogRead(A1); 
// add the reading to the total:
total= total + readings[index]; 
// advance to the next position in the array: 
index = index + 1;

// if we're at the end of the array...
if (index >= numReadings) 
// ...wrap around to the beginning: 
index = 0;

// calculate the average:
average = total / numReadings;

average = map(average, 0, 1000, 1000, 0);

/*

**Extra setup: Connect an LED to digital pin 9**

Adjust the 2nd and 3rd variables to the lowest and highest analog output
you read when holding your finger on the device
The 0 and 255 maps the analog input to the brightness of the LED

*/

arraySumOld = arraySum;
//this is the sum of the last "arrayLength" sensor values.
arraySum -= array[arrayIndex];
array[arrayIndex] = average;
arraySum += array[arrayIndex];

pulseSum -= pulse[arrayIndex];
pulse[arrayIndex] = arraySum;
pulseSum += pulse[arrayIndex];

arrayIndex++;
if (arrayIndex > arrayLength-1) {

arrayIndex = 0;

}

Serial.println(average);

int sensorValueMapped = map(average, rangeLEDmin, rangeLEDmax, 0, 255);
analogWrite(brightnessPin, sensorValueMapped);

if (average > rangeLEDmax || average < rangeLEDmin ) {

analogWrite(brightnessPin, 5);

}

//Serial.println(sensorValueMapped);

// Extra setup END

delay(1);
}

Processing Code:

/*
Serial Graphing Sketch
by Tom Igoe
Language: Processing

This sketch takes ASCII values from the serial port 
at 9600 bps and graphs them.
The values should be comma-delimited, with a newline 
at the end of every set of values.
The expected range of the values is between 0 and 1023.

Created 20 April 2005
Updated 27 June 2008
*/

import processing.serial.*;

int maxNumberOfSensors = 6; // Arduino has 6 analog inputs, so I chose 6
boolean fontInitialized = false; // whether the font's been initialized
Serial myPort; // The serial port

float[] previousValue = new float[maxNumberOfSensors]; // array of previous values
float xpos = 0; // x position of the graph
PFont myFont; // font for writing text to the window

void setup () {
// set up the window to whatever size you want:
size(1400, 600); 
// List all the available serial ports:
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino or Wiring module, so I open Serial.list()[0].
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
myPort.clear();
// don't generate a serialEvent() until you get a newline (\n) byte:
myPort.bufferUntil('\n');
// create a font with the fourth font available to the system:
myFont = createFont(PFont.list()[3], 14);
textFont(myFont);
fontInitialized = true;
// set inital background:
background(0);
// turn on antialiasing:
smooth();
}

void draw () {
// nothing happens in the draw loop, 
// but it's needed to keep the program running
}

void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');

// if it's not empty:
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);

// convert to an array of ints:
int incomingValues[] = int(split(inString, ","));

// print out the values
// print("length: " + incomingValues.length + " values.\t");
if (incomingValues.length <= maxNumberOfSensors && incomingValues.length > 0) {

for (int i = 0; i < incomingValues.length; i++) {

// map the incoming values (0 to 1008) to an appropriate
// graphing range (0 to window height/number of values):
float ypos = map(incomingValues[i], 900 , 500, 0, height);

// figure out the y position for this particular graph:
float graphBottom = i * height/incomingValues.length;
ypos = ypos + graphBottom;

// make a black block to erase the previous text:
noStroke();
fill(0);
rect(10, graphBottom+1, 110, 20);

// print the sensor numbers to the screen:
fill(255);
int textPos = int(graphBottom) + 14;
// sometimes serialEvent() can happen before setup() is done.
// so you need to make sure the font is initialized before
// you text():
if (fontInitialized) {
text("Sensor " + i + ":" + incomingValues[i], 10, textPos);
}

// change colors to draw the graph line:
stroke(255);
// stroke(150, 24, 24);
line(xpos, previousValue[i], xpos+1, ypos);
strokeWeight(1.5);

// save the current value to be the next time's previous value:
previousValue[i] = ypos;
}
}
// if you've drawn to the edge of the window, start at the beginning again:
if (xpos >= width) {
xpos = 0;
background(0);

else {
xpos = xpos + 1.1;
}
}
}


I found my pulse!

Processing Visualization of my first pulse

Finally, after experimenting all day it happened. I found my pulse! It seems to have been there all along. After losing faith in the flimsy photo interrupter from yesterday I was at a loss as to what to do today, so I thought I might as well experiment a little. With my finger connecting the IR-LED and the Phototransistor I was getting readings around 120-130 (reading of the Analog 0 on the Arduino). I figured if I could get the IR-LED to shine brighter (or reversely the phototransistor to be more sensitive) I might get higher and more usable readings. Last week I remember having read about a product on the SparkFun website that let you optimize the amount of light emitting form the IR-LED. Here and here. It turns out the whole thing is actually just a transistor, an IR-LED and some resistors (all of which we had lying around the lab). I cleared the breadboard and put the new setup in place and voila, it worked (the short version of a longer struggle involving a few trial and error attempts).

But all is not well. The problem now is that it seems as if the sensor can only detect my pulse if I shine light directly through my finger – the IR-LED placed on one side and the IR-Transistor on the other. Update: It works!

More on all this tomorrow!

Fritzing for the new setup:

Pulse Sensor New and Improved – Now with light

The Arduino Code: NB: Hover your mouse over the code and two icons will appear in the upper right hand corner that will let you copy the code

/* Based on
*
* Can you feel my heart beating?
*
* james robert thompson
* 10/23/2010
*
* Rewritten by Rene Jøhnke
*/

const int arrayLength = 90;
int arrayIndex = 0;
int array[arrayLength];
int arraySum = 0;
int arraySumOld = 0;
int sensorValueOld;

int pulse[arrayLength];
int pulseSum = 0;

int IRLed = 8;
int brightnessPin = 9;

void setup() {
Serial.begin(9600);
pinMode(IRLed, OUTPUT);
pinMode(5, OUTPUT);
}

void loop() {

digitalWrite(IRLed, HIGH);

int sensorValue = analogRead(A1);
sensorValue = map(sensorValue, 0, 1008, 1008, 0);
Serial.println(sensorValue);

// Extra setup: Connect an LED to digital pin 9
// Adjust the 830 and 860 variables to the lowest and highest analog output
// you read when holding your finger on the device
// The 0 and 255 maps the analog input to the brightness of the LED

int sensorValueMapped = map(sensorValue, 780, 880, 0, 255);
analogWrite(brightnessPin, sensorValueMapped);

// Stop the LED from blinking
/*
if(sensorValueMapped < 900) {
analogWrite(brightnessPin, 0);
} else {
analogWrite(brightnessPin, sensorValueMapped);
}
*/
// Extra setup END

arraySumOld = arraySum;
//this is the sum of the last "arrayLength" sensor values.
arraySum -= array[arrayIndex];
array[arrayIndex] = sensorValue;
arraySum += array[arrayIndex];

pulseSum -= pulse[arrayIndex];
pulse[arrayIndex] = arraySum;
pulseSum += pulse[arrayIndex];

arrayIndex++;
if (arrayIndex > arrayLength-1) {
arrayIndex = 0;

delay(5);
}
}

The Processing Code:

/*
Graph

The circuit:
Any analog input sensor is attached to analog in pin 0.

created 2006
by David A. Mellis
modified 9 Apr 2012

by Tom Igoe and Scott Fitzgerald

This example code is in the public domain.

www.arduino.cc/en/Tutorial/Graph

*/

import processing.serial.*;

Serial myPort; // The serial port


int xPos = 1; // horizontal position of the graph

void setup () {
// set the window size:
size(1500, 700);

// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
void draw () {
// everything happens in the serialEvent()
}

void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');

if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);

// draw the line:
stroke(216, 24, 24);
line(xPos, height, xPos, height - inByte);

// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
}

Next up:

  1. Stabilize and optimize the pulse readings (see 4)
  2. Research galvanic skin response
  3. Make a more reliable setup (ie. solder the whole thing together)
  4. Look at Op Amps to optimize the phototransistor (as I did the IR-LED).

UPDATE: A better pulse!

A stronger pulse (also inverted the analog values so the pulse shows as a higher value)