Pulse (heart beat) Project

One of the most popular projects I’ve ever done has been the pulse sensor and over time I’ve had more than one request to make it battery powered, do a ‘proper’ circuit diagram and make it more permanent (i.e. remove from the breadboard). So, the time has come. This is a completely new article and you don’t need to read the previous one (here of you want to) to build this. This will take you through all the steps and there will be some repetition from the first article but also some new content to make building your own slightly easier. The code itself will receive a very minor tweak as well to eliminate a common issue that people came across (if they did not read a linked article).

A video is available that supports this article, see below:

Pulse sensors now seem to be cheap and plentiful (around 1.6 USD, a little less than 1.6 GBP and around 1.80 Euros). Here’s the build on a breadboard.

The heart beat sensor I bought is shown below:

They should NOT be used as a medical device (XTroncial official disclaimer!), if you have any concerns about any part of your health – see a Doctor, not a web page about hooking up cheap heart rate sensors to cheap micro-controllers!  But…. having said that, for fun I’ve found it very accurate in its readings, combined with some sort of graphical plot on a display its a really neat easy project.

The full circuit
Here’s the full circuit of what we will build

Here it is on breadboard

and again in strip-board (more on this later)

How they work
As can be seen there are only three wires to these devices. One is power, the other ground and the final one is the analogue signal.  So, these are not digital devices like the temperature sensor or the many other sensors available. This device outputs a voltage from 0V to VDD (supply voltage) depending on what they “sense”. They work by emitting an Infra-Red signal from an IR-Diode onto your skin. Just underneath your skin are capillaries carrying blood. Every time your heart pumps there is  an small increase in blood flow/pressure. This swells the capillaries slightly, this slightly more filled capillary reflects more infra-red than at times when the heart is not giving your blood a “push”. An Infra-detector on the device senses the different reflected IR levels. Some simple comparator circuitry converts this into a voltage signal which we can read with the Arduino’s analogue inputs.

Connecting it up and initial tests
Any micro-controller with an analogue input should work as the device operates from 3 -6V range (maybe even higher). Just connect the signal line (labelled “S” on my device) to an analogue input pin (A0 for our circuit). The value you read from the pin will be in the range of zero to whatever the top value is on your particular micro-controller. To show your heart beat graphically you can use the Arduino IDE in-built serial monitor plotter. Load up the code below into your IDE, then upload to your Arduino. Then select “Tools->Serial Plotter”

Here’s my screen shot showing you what to expect. The Arduino Serial Plotter plots a value sent to it on a graph against time.

Adding the OLED 128×64 (SSD1306 Driver) display
The in built plotter is great for a quick play but it doesn’t show you your heart rate in BPM (Beats Per Minute) at the same time. So for this project we’re adding in our own OLED display. These are readily available and the set up has been discussed in this article before, but we’ll go through it again here. Firstly ensure you’ve bought a OLED 128×63 I²C display (SSD1306 driver) display. It should have four connections, 5v, Gnd, SDA and SCK. Connect up as shown above.

Installing the OLED display libraries
The first is the driver for 1306 OLED display driver chip. Go to the Arduibo IDE library manager, “Sketch->Include Library->Manage Libraries”. Type “Adafruit SSD1306” into the search field. The first result should be the one you require titled “Adafruit SSD1306 by Adafruit”. Install this. The second library is the “Adafruit GFX library”, type in “adafruit graphics” and install the graphics library. The final code is below, copy and paste into your Arduino IDE. Upload and you should see a trace going across the screen. Gently rest you finger on the sensor and your trace should appear (if not see below after code).

Not working?
If it works then great, you’ve done it, if not then the most likely culprit(apart from bad wiring – please check!) is the I²C address of your display. These tend to be either 0x3C or 0x3D. So first try changing the line

#define OLED_Address 0x3C

to

#define OLED_Address 0x3D

and recompile/upload. If this doesn’t work it may be that your screen has an even different address to the most common ones.  In this case you need to load a  I²C address scanner onto your Arduino to get the screen to return its address and use that one in the code above. See this Link for a suitable scanner.

Use and limitations
As mentioned these are cheap but remarkable sensors but don’t expect to strap one to your finger and go jogging. They are very sensitive to movement and moving your hand about will cause massive swings of values – even if taped on. Also, tape them on too tightly and it reduces sensitivity dramatically. They can only be used if your hand is still, having said that you could still measure your Heart Beat at resting and just after exercise to compare. If you have any tips for monitoring with these devices whilst exercising please leave a comment.

Adding the “Beep”
To make this a little more “realistic” you could add a sound output as shown above using a Piezo sounder/buzzer. Simply connect it to pin D8 and GND and you’ll be good to go. This code beeps every heart-beat. it does not sound a “flat-line” single tone if limited activity. This is because it was not always very reliable due to the nature of the sensor which detects spurious pulses. In the real world a heart-beat monitor has several sensors monitoring actual heart activity.

Building onto prototype board and adding battery power
Arduino’s can be battery powered and to do this you supply you voltage to the VIN pin and any GND (ground) pin. The voltage should be in the range 7v to 12v. The Arduino has a built in voltage regulator and this will ensure that only 5v goes to the board and out of its pins. Why 7v?  For the voltage regulator to work correctly it needs at least 2v above the regulated 5v otherwise it will not work correctly. The other problem is that the higher you go above 7v the more extra energy it has to get rid of. It’s not magic, if you supply 10v it has to get rid of 5 volts worth of extra energy and it does this in the form of heat (it gets hot). But as mentioned there is always some waste as it has to burn off at least 2 volts when you supply the minimum 7. So ideally 7v is the optimum as it meets the minimum requirement and wastes the least extra energy. 7 volts however is not a common battery voltage nor is it that easy to make by putting smaller batteries in series together so you can quite often see those small rectangular (labelled PP9 in UK) 9V batteries used as they are small and easily sourced. And indeed I’ve used them in projects but for their size and because they will waste 4 volts of that energy when powering our boards they do not return a good energy return for the price paid (they are relatively expensive). My current preferred battery power source is using a 5 cell AA battery holder which should give a nominal voltage of 7.5V (a little higher when new) and this is what I will use with this project. You could use a lithium-ion cell but you will need 2 in series and be able to re-charge them correctly as well, so we’ll keep it simple. Here’s a picture of the battery holder I will use,

So far we’ve used a breadboard for speed of getting our project up and running and took power from the computer (as it was used to upload code). Now we are going to give it a more permanent home on some pro-typing board. My preferred type is strip-board. Strip-board is the prototyping board that has rows of copper strips as apposed to perf-board which just has copper pads. I prefer strip-board also sometimes referred to as veroboard (veroboard is a large manufacturer of strip-board). If you want to use perf-board then you will have to adopt the design accordingly. Below are three diagrams (click to enlarge) of the the same board (click to make full size). I’ve labeled the rows and columns with numbers to make it easier to transfer to you own board. We are going to build and test this in stages to hopefully minimise any errors. The first shows the track side of the board and where you need to make cuts. The second and third are the component (none track/solder side), with the middle showing just the wiring (solder them underneath where they go through the board).

Cutting the tracks
First job is to cut the tracks where indicated by the white circles. Turn you board so that you are looking at the copper tracks facing you. See this picture of the board I’m using (click to enlarge);

Cut the board to 30 holes across and 21 down. Orientate the board so the tracks are running vertically downwards as shown in the left most picture above (and in the photo just above). Cut the tracks where shown, being careful to double check you are doing it in the correct place. A track cutter is a good tool purpose built for this job but you can get by with a craft knife if required. After you’ve finished check every cut track to ensure there is NO continuity across the cuts (sometimes tiny bits of copper can remain). Here’s mine after completion.

Adding the jumper wires
Next we add the jumper wires on the reverse side to the one where you’ve just cut the tracks in the copper, this is called the component side. Look at the middle picture which shows where to place them. Again, care should be taken over their placement and double checked as errors here could result in the system not working or even the breaking of parts in the system. Here’s my board after adding the tracks;

Adding the components – Arduino Nano
Solder in the Arduino Nano taking care on the placement – see the right most image above. You need not solder every pin, only the ones being used, so for this it would be GND, 5V (Vcc), VIN, D8, A0, A4, A5. But by all means solder them all if you wish. Once the Nano has been added you should upload a test sketch to blink the on-board LED to ensure all is currently working. Here’s the blink test for a Arduino Nano, upload and test.

Adding the OLED screen
Position and solder in the OLED screen. Upload your pulse sensor code and you should see the display you had earlier when you built it onto breadboard. Obviously as there is no sensor attached it should be a basically the letters “BPM”.

Adding the Sensor
You could just solder the three wires connected to your sensor directly onto your board at the points indicated or you may want to add a pin header/connector, it’s up to you. I’ve gone for a pin header turned at 90° (see the video if it’s available yet). Connect up to power again and it should now work as it did before.

Adding battery power and the on/off switch
Solder in the switch at the position shown, I’ve used a slider switch. If you have something different then the important thing to ensure is that when your switch is on it connects tracks 28 and 29 together to allow battery power from track 29 to connect to track 28 an ultimately to the Arduino’s VIN pin. You choice of battery power is up to you but as mentioned I’ve used a 5 x 1.5V cell battery holder to supply 7.5 volts to the Arduino’s VIN pin. I’ve then mounted this to the track side with to small self tapping screws, ensuring the screws did not foul any of the components of connections in the circuit.

The End?
And that’s it your project is complete. In the possible future (but no immediate plans) I may produce a printed circuit board for this popular project which could be purchased through this site. A may also add an audio amplifier to give that beep and bit of “umph”!!

15 Comments

    • Yes you can in theory, but connections would need changing and the driver libraries may need altering – I’ve not tried so not sure what changes – if any- would be required. Sorry for late reply but there is a problem with me not receiving notification emails for posts. Best thing is to comment on a video as I get them and reply to them all.

  1. Hello, is there a way to output to a LED wall or strip instead of the OLED panel. Like I would want it to just flash light every time there is a pulse. But on a LED panel instead or strip instead, maybe like WS2812B led. No graphical interface required.

    • As usual I start with an apology for a late reply, despite having everything set to send me emails when people post I still don’t get a notification. Best thing is to comment on the video and those notifications get through. Anyhow, yes to answer this, you could use the LED strips to pulse all on or go up and down etc. that would look kinda cool. However I don’t have any in and at the moment I’m backed up with several projects. It’s something I would consider doing for sure but not for immediate future.
      The next release on the heart rate front is using the MAX30100 series of chips which perform better than these pulse monitors, a video working with them is out this week.

  2. Thanks, no problem! I think I was able to figure it out. Now I’m just trying to do an analog version too. It seems though that the sensor seems to be sensitive so it will pick up signals even if no one is touching it.

    • It dose usually fluctuate a little around a value of 512 but not usually excessive. If you’ve getting a big enough increase above the 512 mark then could you ignore the small fluctuations?

  3. Good afternoon, I have a problem with my sensor, in the code the range it uses is 560 and 530, but my sensor gives between 450 and 430, by changing the values in the code just do not mark the line and do not know what to do
    If you could help me I would be grateful, it’s for a project that I have,

    • Hi, I’ve had a few people report similar issues over the last 2 years and it’s been frustrating trying to get to the bottom of it. However a few weeks ago I think I did and uploaded this video showing the problem : https://youtu.be/yhRL_W1WhV0
      Unfortunately in the video it shows two identical sensors (bought a different times) where one performs perfectly and the other under identical circumstances doesn’t. It would seem that some sensors are faulty as they do not report a good range of values, 450-430 is too low to make any sense of. So there is no fix, I can only suggest trying a different supplier for the sensor and hope they have a different batch or look at the more reliable pulse and oxygen sensor – See this video : https://youtu.be/17im1J1EdZA

  4. Sir i am not getting the output in the oled screen, can you tell me what is cause and i am using arduino uno.

    • Having looked at this driver it does not appear to work well with the Adafruit graphics library (or at least not fully). I’ve no experience of it and suspect it would need many changes and perhaps even adding functions to the driver itself. It would be best to switch to a ssd1306 chipset from what I can see.

Comments are closed.