BLOG# 4 - Beats Per Minute Nano
A Heart Rate Monitor using the Arduino Nano 33 IoT Board
System Implementation and Testing
This is my 4th blog post in a series of blog post for the Design Challenge: Design for A Cause 2021
Updated
version 1.4
<<< PREVIOUS BLOG | NEXT BLOG >>> |
---|---|
Blog# 3 Beats Per Minute Nano - System Design | Blog#5 Beats Per Minute Nano - Conclusions and Future Enhancements |
INTRODUCTION
- This blog will describe the implementation and testing phase of my idea. My original idea was to port the software from a project that I developed for the Azure Sphere MT3620 Evaluation Kit. I had used the C code examples from the Raspberry Pi for the PulseSensor and was able to get the software to run to complete the project. I describe this project at the beginning of BLOG# 1 - Beats Per Minute Nano - INTRODUCTION and the code is on my GitHub repo at MyBPM
- After doing research on implementing the PulseSensor on the Arduino described in Blog# 2 Beats Per Minute Nano - Research & Experimentation , I found that it would be so much easier to use the code from there Arduino library. They have implemented all the Timing and BPM calculation logic into there library, that I had to implement in my other project. This made it so much easier to implement my idea.
- I took pieces of the example code that worked The "GettingStartedProject" and created a TEST sketch Pulsesensor_test.ino
- For the OLED logic, I took pieces of the code from Blog#2 An OLED Example Project and created a test sketch OLED_Test.ino
- Then I combined the code from the 2 test sketches and created the Final Sketch BPM_NANO.ino
- For the breadboard wiring I combined the connections from Blog#2 PulseSensor and OLED examples to be used for the above 2 TEST Sketches and the final Sketch
- These sketch's will be listed and described below.
Electronics build
- For wiring my idea, I approached it as follows:
- As mentioned, for the breadboard wiring I combined the connections from Blog#2 PulseSensor and OLED examples.
- The wiring diagram is pictured in the design section Breadboard Wiring from Blog#3
- I used the examples from my research to test the final breadboard wiring and they both worked the first time.
- I then went on the implement 2 test and 1 final Sketch, to complete my idea.
Software Programming
- My approach for implementing the software was to take the code that I had been experimenting with in blog#2 and create test sketches for the Pulsesensor and the OLED components. then I would combine the test sketch's to create the finial sketch.
- Test Sketch's:
- Pulsesensor_test.ino
- OLED_Test.ino
- Final Sketch
- BPM_NANO.ino
- List each code block
- Video of the execution of each code block
- Describe the routines used.
- Conclusions and/or Problem encountered.
Testing
PulseSensor test
Pulsesensor_test.ino
- I used the following sketch to test the wiring and the code for the PulseSensor. You can paste it into the Arduino IDE and try it out, If you have wired the breadboard as specified in my Design Blog#3.
- The Beats Per Minute value is printed out to the Arduino IDE Serial Monitor. I created the sketch from the The "GettingStartedProject" example on the pulseSensor.com website.
- I added the code that follows to get the current BPM after every 50 samples are taken.
int myBPM = pulseSensor.getBeatsPerMinute();
Returns the latest beats-per-minute. Type = int.
- Then the BPM value is sent to the Serial Monitor in the beginning of every heart beat if the sawStartOfBeat() funtion returns TRUE.
- Another task that this function does , is to Blink the Arduino Nano LED, to indicate the heartbeat.
if (pulseSensor.sawStartOfBeat()) { Serial.println("♥ A HeartBeat Happened ! "); Serial.print("BPM: "); Serial.println(myBPM); }
CODE -- PulseSensor.ino
PulseSensor Library Function Descriptions
- The following list contains the PulseSensor Library functions with a short description, that I used in the code
TEST RUN Video
- Here is a Video of the test run. It shows my fit2 watch displaying the BPM and then the code and the monitor, showing the BPM reading.
- The Pulsesensor seems to run at a different BPM then my Fit2 watch.
Electrical Conclusions and Findings
- The test worked the first time. Which one would expect after the help of the experiment in my Research blog.
- The new wiring with the WaginTop jumper wires worked great and cleans up the breadboard jumper wire clutter nicely.
Software Conclusions and Findings
- The software library for the Arduino IDE is so much easier to use then the one that I used for the Rasberry PI and Azure Sphere projects.
- The Timing is handled in the sawNewSample() function. which makes the code is tighter and more readable, This was very complicated to analyze and Debug in the other library.
- The getBeatsPerMinute() function made it easier to work with and streamlined my implementation. For the other projects, the BPM logic had to be coded in the example. The folks at PulseSensor.com, did give examples, but this function is a black-box and just returns what I really nee, the BPM. They also have functions for other readings within the samples, but all I really need is the BPM.
- In addition, this function also sends a blink signal to a defined Pin on every Heartbeat. Such a nice feature that the programmer does not need to worry about.
- all in all, I found this library extremely easy to use.
OLED test
OLED_test.ino
- I used the following sketch to test the wiring and the code for the OLED. You can paste it into the Arduino IDE and try it out, If you have wired the breadboard as specified in my Design Blog#3.
- I took pieces of the code from Blog#2 An OLED Example Project and created this test sketch
- This is a very basic TEST, that will display a counter value that is incremented in the main loop of the sketch .
CODE -- OLED_test.ino
- TEST RUN Video
- Here is a video of the OLED test run. It is displaying an incremental counter.
Electrical Conclusions and Findings
- Just as the previous test, this worked the first time.
- At least I know that my wiring in working.
Software Conclusions and Findings
- I learned some interesting use of the Adafruit OLED library,
- Very similar to the library I used for the other projects.
- This knowledge will be used for the main program to display the Beats Per Minutes.
Run Application
BPM_NANO.ino
- This is the implementation of my design.
- As designed, it displays the Beats per Minute on an OLED screen generated from a Pulse sensor connected to the Arduino Nano 22 IOT.
CODE -- BPM_NANO.ino
Run the application
- Here is the video of the final sketch running.
- It is displaying the Beats Per Minutes on the OLED screen.
- I'm also displaying the BPM's on the IDE Serial Monitor.
- I'm also displaying my BPM on my Fit2 Watch.
- Conclusions
- This was a very successful implementation of my design. There were no problems with running this sketch.
- Conclusions
- There seems to be a slight difference in the BPM's when compared to my Samsung Fit2 watch which displays a BPM. I'm not sure whay but I might play with the Threshold values of the sketch to bring the value closer to the watch.
- Now on to final blog.
<<< PREVIOUS BLOG | NEXT BLOG >>> |
---|---|
Blog# 3 Beats Per Minute Nano - System Design | Blog#5 Beats Per Minute Nano - Conclusions and Future Enhancements |
Top Comments