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!
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.
Busy week in the lab.
As mentioned in the previous post Ive been trying to figure out how to make the packaging for Thing. My first attempt was making it out of wood (seen in the pictures in this post). But wood is costly and it takes time to route out the insides of the container. It also needs some form of closing mechanism. So wanting to find an alternative I decided to try out cardboard, as its inexpensive and relatively easy to work with. It also allows for printing. The downside is that its not very durable and that sucks because I’d like people to be able to easily and safely carry Thing around – to work, vacation etc. The other option is to make a box out of veneer which is inexpensive but does require some work to put together.
Nonetheless, a few days ago I started experimenting with the cardboard packaging and built my first box. I searched far and wide for a cardboard box template and found this site. I then printed out a miniature box and assembled it. The next step was to make it full size so I took some paper and started to measure Thing and draw the whole template out. See the pictures below. Oh and I also made “holders” for the box. The holders are there to keep Thing in place and also act to protect the LEDs and the phototransistor from the lid of the box.
Yesterday I went down to Art de Voss, a local art shop, and bought some paper. Then I biked on over to Godsbanen and used an hour or so to design a proposal for the packaging. I’ve been trying to rework the “Thing” logo, font type (Let me know if you have any suggestions!!) and also, as mentioned before, the names for the two versions . I was a little bit in a rush so I just decided to name them after my grandparents Poul and Ella. I think Im gonna keep it that way. The name of the version is on one end and the “production number” ie. 01, 02, 03 on the other end – I thought it be kinda cool to know what “number” Thing you have. I don’t know about that though, it needs more work. (The paper btw is 300 gsm – I think – and is 70 cm x 100 cm).
Godsbanen, besides having a wood workshop, also has a print shop, where they can print almost anything. After a long wait and a failed attempt it finally worked. I ruined my favorite paper on the first attempt so the paper color screwed up the print color a bit. Here are some pictures of the final boxes.
Friday June 28th Update:
I almost love cardboard as much as I love wood. Man it’s great to work with. To the point now I made a new box out of some stronger cardboard, the cardboard I used for the ones above is just too flimsy (realizing this having to carry it around in my bag the last few days). So stronger cardboard it is! Other than thicker cardboard I also changed the design slightly. I removed the lid and a flap from the template above, then I made a duplicate of the first one but 4mm wider and longer so it would fit as a lid. You have to check out the pictures below!
Back in the lab after my trip, the last week has been spent working on finishing up the final version of Thing. Still needs some finishing touches but check out the awesome pictures below!
A few notes on the final prototype:
– The dimensions of the final prototype is a bit smaller than the Projector version – it sits better in the hand that way
– I’ve altered the angle of the switch so it turns on/off by switching it up/down (up is on)
– Nothing is glued into place. Instead the components are held in place by small wooden spheres. I’ve done this to allow for much easier repair (with glue its almost impossible to take the components out without ruining the wood). If I have to say it myself its quite clever! The only downside is that if you apply a lot of force they slide down, but with normal use it shouldnt be a problem. And if they slide down its easy to open Thing and push them into place again. See picture below.
Now that Ive gone this far I decided I might as well try to do some packaging as well – and an instruction manuel too. Hope to get that finished within the next week so I can have a finished ‘product’. The concept video is still a work in progress – that is, I haven’t exactly started working on it yet, but I’ll get to that soon enough.
Stay safe,
René
It’s been far too long since the last update so here is a lengthy one!
First of all: I realize I haven’t uploaded any pictures of the handheld Thing with the a super-bright “projector” LED, so here it is!
Here’s a short video as well: Pulse Video
It’s been tested by people here in the lab, a couple of people at Godsbanen and my family. It works great :-). People tend to push down very hard on the Led and Phototransistor to begin with but with a little direction they usually get “in to the zone” after a short while. When I come home I’ll have to set up more extensive testing where I just hand them Thing, give them a very short brief and then let them figure it out. Perhaps let them inside a dark room for a few minutes and see if they can get a small meditative session going. I also need to talk to people who have experience with meditation here in Aarhus to see what they think.
Last week I finished my anthropology exam so I spent a few days in the lab working on the new version of the handheld Thing. This time the LED will be a diffused red 10 mm LED placed at the end, after the LED and phototransistor. I also decided to make a charger box (see pictures) to go along with Thing so it’s possible to charge the LiPo battery. I tested out the circuit boards and they worked fine, though it seems the strength of the LED and IR-LED aren’t as strong as the old version. But Ill experiment with that when I get home. It works and thats the most important thing! I also made a container for Thing so I can transport it around a bit easier, I also got Thing and my name engraved in it.
When I come home I’ll finish up Thing 3.0 and maybe work on a whole new mini version that I have a few ideas on – mainly trying to make it as small as possible. I also need to schedule time with the laser again as I have an idea for securing the LED and Phototransistor in place. I expect Ill have more ideas on the trip so the new version may have several new features :-)!
May 1st I set off to the Dominican Republic so the blog is going to be quite until mid June when I get back.
See you on the other side!
René
Last week I found out that Fritzing, the program I used in the start to visualize my circuit (so I can put it up on the blog and in the tutorial), also fabricate custom boards! This means I don’t have to solder the whole thing everytime I make a new version of Thing and I can make the boards even smaller (not that it matters that much because I can already make them small enough to fit inside the wood containers. The good thing is that its affordable too. 6 boards costs around 650 kr.- including shipping. Not bad at all. The only challenge is to get the circuit right, as my knowledge of electricity is still questionably at best.
Update: Got some help from Lasse Vestergaard to double check the circuit. I ordered 6 boards yesterday that is set for shipping on the 10th. With a little luck they’ll be in my hands on the 13th-14th. Update:
Also went down to Godsbanen and made another handheld box for Thing so I can put the new PCB inside once it arrives, just hope everything works once I get all the parts assembled. More on that at the end of the month. The blog will most probably be quite for the next few weeks as I have an anthropology exam due on the 22nd.
Stay safe!
Ok so the assembly friday wasn’t exactly smooth sailing, but, nonetheless, it has been done! The handheld Thing (really need to come up with a spiffier name for it) works flawlessly, you should see it. The original Thing is a little unstable, I’m worried theres something wrong with the Arduino Pro Mini, as I can’t seem to locate the problem anywhere else. O well, it works most of the time. I’ve written an email to Peter Friis, an engineer at CAVI who is very much down with electronics and the likes, who can hopefully help.
The plan was initially to take a break from Thing, but I really feel like going forward with it. I hope Peter can help optimize the circuit and power supply (thinking of changing the Pro Mini to a 3.2v instead of the 5v I’ve used so far, so that it can run off an 3.7v LiPo battery instead). More on that later. I’m also looking into getting the circuit printed (Fritzing, the program I use to visualize circuits, manufactures custom made boards!) Need to figure out how to set it up properly though, maybe Lasse Vestergaard (a clever fella who runs a course on the Digital Design programme) can help as he has some experience from the DUL-Radio project.
I’m also in the process of making a poster (in wood of course) for Thing, so I might be able to present it when/if that time comes. In truth this is just an excuse to try out the KERN laser cutter at Godsbanen.
Today I experimented with making a circuit in wood. Worked ok, but needs improvement. Take a look below.
Tuesday was a nightmare.
Everything seemed to go wrong in some way or another. I had a lot of problems with the handheld device. To boil it down, the lesson I learned was this: When making a pulse sensor, don’t use loctite glue. The readings were all wrong when I finally hooked everything up to the computer. Turned out the loctite had eroded the metal/shrink wrap (found this out when I, after a few hours of testing different things, decided to drill out the led and phototransistor). As though this wasn’t enough, the Arduino Pro Mini started turning off and on every other second.
It was a shitty day.
However, all’s well that ends well! Wednesday turned out much better. I got the whole thing sorted by a couple of hours of good old trial and error – testing the different components. The battery was the problem to the turning off/on problem – I even had an epiphany: maybe the walnut wood would work with the led and phototransistor placed closer together? I had thought of this earlier but for some reason never tested it out. When I did, it turned out to work! I tested out a couple of different set-ups which resulted in the led and phototransistor being placed 13mm apart instead of 19 mm – and the readings were as good if not better than before! I went straight to Godsbanen to construct a new box – I had ruined the extras I had made. While there, the walnut wood I had left fitted perfectly with a new handheld device (though a bit shorter). And as I wasn’t particularly excited about the color of the pine wood – it looked yellowish when tung oil was applied – I decided to start over with the handheld Thing. Back in the lab I drilled holes and sanded down the box and the handheld and gave them both a coat of tung oil and left them overnight.
Today, thursday, I routed out the handheld device (see picture below) and gave the box tung oil.
Began by routing the outlines of the boxes two boxes: one for the arduino and one for the battery. The two smaller boxes (can’t see them properly in this picture) at each end are for the toggle switch and the LED.
So it seems my days here in the lab are numbered. Tomorrow I count on a trouble-free assembly of both the box and the handheld. What’s left is to glue the phototransistor and led in place and test it out. I also need to drill out holes for the magnets (forgot about this until right now). After that, when (hopefully) everything works, Ill leave Thing for a bit to get back to my regular life! Scratch that, I need to make a concept video for it first.
This week, and last week, I’ve been working on a handheld version of Thing. The concept is to put all the electronics inside a rectangular box so it’s possible to walk around, projecting your pulse out into the room (see pictures).
In other news:
The pine box for Thing 2.0 is done being oiled up, so today Ill try to make time to fiddle around with putting the LED and phototransistor in it. A little worried the wood is still too dark (the end grain has turned out darker than the rest of the wood).
Handheld Thing
Getting ready to route out the insides to make room for the breadboard
MAR / 2013
Assembly of Thing 2.0, 2.0, went wrong. I accidentally pressed the LED and phototransistor too far down into the box. Alas, this is not the only problem!
The main issue: is that the dark walnut wood doesn’t reflect the infrared light as well as the pine wood I used for the first version. This means that the readings aren’t precise enough. I thought I had tested this out by placing a piece of black cloth on the older version and then checking the readings (which were fine). But I guess it wasn’t quite good enough.
The solution: is to either use a lighter wood or alternatively place the Led and Phototransistor closer together, but I’m not at all sure this will fix the problem. A third solution might be to paint a white box or some other shape around the LED and phototransistor.
The next step: is to construct either the main box and the LED projector box, or just the main box, in a lighter type of wood.
Yo. Hello. The last few days I’ve been hard at work finishing up the new version of Thing. Today, it didn’t quite go as planned. When I tried to glue the IR-LED and phototransistor in place, the IR-LED stopped working. It got stuck pretty good in there because of the glue, so there was really no way of saving it. I think it might have been the loctite glue that did a number on the wiring. Next time Ill use the same method as the first version (hot glue). Now I’ll have to make a new wooden box, sand it, tung oil it, and pull the wiring through (took an hour last time).
On the positive side I’ve found a clever (though somewhat obvious) solution to the main box dilemma of having to put he electronics inside (My last idea was to split it in two and carve out the insides – see the last post). Instead, and this makes little sense when describing it, I’ve inserted the wires into one hole and guided them up trough the top two holes, without having to slice up and carve out the insides of the box. I then solder the LED and phototransistor onto the wires.
The last few days I’ve been hard at work on Thing 2.0. Been down at the Godsbanen wood shop finishing up the wood and also worked a bit on the electronics. It’s coming together nicely and I’ve even made a few adjustments here and there.
To finish the wood: Ive been following instructions from this blog post. First sanding down the wood 80, 120, 220 and then wetting it, quickly drying it with a heat gun and then polishing it (removing the small spikes that come up as the wood gets wet). I use one of those kitchen pads that are dirt cheap at your local supermarket, works great. Last I coat the wood in tung oil (may be hard to get a hold of depending on where you are in the world, but its good stuff as its all natural) If you are in Aarhus, or Denmark, you can order it through these guys – it’ll set you back around 180 KR (30$)).
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
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!
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.
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
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.
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:
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?
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 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.
Came up with the idea to use a cord from an old phone to connect Thing (trying out a name for it) to Arduino Mini Pro.
Routed out the insides of the container to allow more room for wiring, the LED etc.
Thing in Progress
Drilling plan for Thing.
Magnets
Yesterday – Sunday the 6th – I worked on the container for the Arduino and breadboard which came along pretty nicely. I went to the mall next door to find magnets for the closing mechanism, found some but they were expensive so I decided to wait. Luckily I found some in the lab (may need to pay for those) but they were perfect for the job! Small and round they could easily be placed in the four holes I drilled into each corner of the container. I just tested it a couple of minutes ago and it works like a charm :-).
Im not much for to-do lists but I need to review the last couple of steps and the next ones going forward:
1. Solder the IR Led/transistor circuit
2. Solder a separate Red LED circuit (buy a bigger LED from elektronik-lavpris.dk)
3. Work on the physical design of the thing (Cylinder, cube or rectangle?)
4. Thoughts on the physical feedback (leaning towards warmth) – also had thoughts on the computer going into sleep mode once the thing is activated.
5. Read a couple of articles I found yesterday
Todays progress: Shrinkify!
Decided what I wanted to do the most today was to get my hands dirty so I went into “practical” mode. This is the result.
Arduino Pro Mini
Arduino Pro Mini Setup soldered onto Proto Shield with option of external battery
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).
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).
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:
Drilling plan
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:
Thursday’s 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:
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:
*/
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:
UPDATE: A better pulse!
A stronger pulse (also inverted the analog values so the pulse shows as a higher value)
And I broke it. The photointerruptor arrived today from Elektronik-Lavpris.dk (http://elektronik-lavpris.dk/p107822/GP2S24J0000F_Photointerr._Refl._0,7mm_DIP4/). I put the sensor into my circuit and moved it around a few times, which resulted in two broken legs (the sensor legs not mine). Not good. Luckily I’ve got a spare (though with shorter legs) so Im going to try fiddling around with that. Im a little bit in despair as to what my next step is. I find myself at a critical point in the project where I need to move on from the responsibility-free-playing-around-with-sensors stage, to a more focused one in which I need to figure out what I plan to do with the heartbeat sensor (when I eventually get it to work) and also get moving on the “theory part” of the whole ordeal. On the practical side Ive been thinking of using the heartbeat sensor to make a handheld device which returns to you your own heartbeat in some form of physical feedback (could be heat pulsing in the same rate as your heartbeat, or vibration – who knows). The device could be connected to your laptop with a USB cable so when activated it would put your computer to sleep – allowing you a couple of minutes with just you and your heartbeat.
A few interesting links you might find useful:
1) Calculate your resistors! Its pretty easy once you figure out the gist of things.
2.) Collin’s heart sensor Another heartbeat sensor project I found, unfortunate that the guy doesn’t upload his code.
Today I’ve been trying to clean up the visualization in Processing. I’ve also changed the resistance going to the transistor from 560K ohm to 240K ohm. This makes for less noise in the readings (don’t ask me why). The picture below shows the Processing sketch, which reads the value from Analog 0 on the Arduino and visualizes it in the shape of a line moving across the screen. It’s hard to tell whether the small “indents” are in fact heartbeats or just some random noise (Ive tried putting two fingers on my neck, while holding my finger over the sensor – but haven’t been able to find a clear connection yet). What is encouraging though is that the readings are pretty stable when holding a “dead” object on top of the sensor, compared to when putting my finger on it. So maybe the graph below does show my heartbeat, I just need to figure out of to amplify the signal, so the heartbeats are more clearly depicted.
Processing – Heartbeat
The Processing code (If you want to copy the code, hover your mouse over the code and an icon named “Copy to clipboard” will appear in the upper right hand corner. On another note, remember to close down the Serial Monitor in Arduino while running the sketch in Processing – the two will interfere with each other):
// Graphing sketch
// Created 20 Apr 2005
// Updated 18 Jan 2008
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
int myHeight = 4;
void setup () {
// set the window size:
size(1000, 600);
smooth();
// 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, 500, 0, height);
// draw the line:
// ellipse(500, 200, xPos - inByte, xPos - inByte);
stroke(216, 24, 24);
line(xPos, height/2, xPos, height/2 - inByte);
strokeWeight(2);
stroke(216, 24, 24);
line(xPos, height/2, xPos, height/2 + 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++;
}
}
}
Have fun,
P.S: Still waiting on the new sensor to arrive.
Mihaly – Flow
Yesterday the lab ordered a couple of new sensors, including a better IR emitter and detector (http://elektronik-lavpris.dk/p107822/GP2S24J0000F_Photointerr._Refl._0,7mm_DIP4/), which will probably arrive tomorrow (friday the 14th). My Pulse Sensor setup works OK as of now – the “only” problem being the instability of the readings (the readings from it are not accurate enough to detect a heartbeat). I suspect its the rather crude setup with the LED and transistor next to each other which is the root of the problem. Hopefully this will be fixed with the arrival of the new IR emitter and detector-in-one. Otherwise I might have to (as some others before me have had to to) amplify the transistor so it will be more sensitive to the IR light coming in (what this Im not entirely sure). Im hoping the sensor arriving tomorrow will make my readings more accurate and the use of the code from this guy.
So, while waiting for the sensor I decided to read a bit of theory on happiness and technology. I found a couple of interesting articles.
1. Positive Computing: Technology for a Wiser World
2. Phoebe Sengers (2011) What I Learned on Change Islands: Reflections on IT and the Pace of Life.
3. Mihaly Csikszentmihalyi – FLOW- Optimal experience
Here is a little bit of code for the Lilypad Accelerometer which I (very briefly) set up at the end of my lab day yesterday. The code is actually just a slight rewrite of the example code in Arduino, which can be found inside Arduino -> File -> Examples -> Basics -> AnalogReadSerial. Now all this does is read the analog input (A0), so all you have to do is take a pair of crocodile clippers and hook one up from the x (or y or z) on the Lilypad Accelerometer to the Analog Pin 0 on the Arduino. Then do the same for Ground and the 5v power. See the Fritzel below for help – its the blue link named Lilypad Accelerometer (In there we also hook up the y to A1 and z to A2).
We now need to add a bit of code to the Arduino Sketch, so it knows it also has to read the Analog input A1 (y axis) and A2 (z axis). Next, upload the program by pressing Command/Ctrl + U (or simply by pressing the thumbnail that looks like a circle with and arrow pointing to the right – it’s located in the top menubar, the second one from the left). Remember to plug in your Arduino. If this is your first time setting up the Arduino you might have to go to the Tools menu -> Board -> Arduino Uno (or whichever board you are using), you might also have to set the serial port, go Tools -> Serial Port -> choose the USB port your Arduino is connected to. Select a different port if you still get an error. When its done uploading the sketch to the Arduino, Open up the Serial Monitor (the thumbnail is in the upper right hand corner – it looks like a loupe with a dotted line running across) or by pressing Command/Ctrl + Shift + m.
The Fritzing: Lily Accelerometer
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int xValue = analogRead(A0);
int yValue = analogRead(A1);
int zValue = analogRead(A2);
// print out the value you read:
Serial.print("X value is: ");
Serial.println(xValue);
Serial.print("Y value is: ");
Serial.println(yValue);
Serial.print("Z value is: ");
Serial.println(zValue);
Serial.println(" "); // Makes a space between the readings
delay(1000); // delay of 1000 ms (1 second) - Gives us time to better read the Serial Monitor
// speed this up by lowering the number
}
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);}
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.
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)
[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:
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;
}
}
}
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
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:
UPDATE: A better pulse!
A stronger pulse (also inverted the analog values so the pulse shows as a higher value)