Introduction: Let It Beat
Let it beat is a project that measures one's heartbeat and displays it on a LCD whilst blinking the LED's and playing the sounds at the interval of the BPM.
For this project you will need the following:
- Arduino UNO
- Breadboard (testing purposes)
- Jump wires/ cable
- Power Supply
- LED's x 5 (20mA tops per LED, standard LED is 20mA)
- LCD (with I2C)
- Button x 2
- Pulse sensor
- Speaker
- 100Ω resistor x 2
- 10kΩ resistor x2
- Foamboard / wood (your choice)
- Crepe paper
Step 1: Schematic
In the schematic above you can see the components and how to connect them.
Do make it first like the schematic to make sure all your components work and are not faulty.
Step 2: Coding
Link to my github (source code and libraries): https://github.com/Karin1996/LetItBeat
<p>#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most accurate BPM math.<br>#include <Wire.h> #include <LiquidCrystal_I2C.h> #include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library. #include "pitches.h"</p><p><br></p><p>// Vars<br>const int ledset1 = 13; const int ledset2 = 12; const int startBtn = 2; const int resetBtn = 4; const int speaker = 11; const int sensor = 1; // PulseSensor connected to A1 const int reset = 7; //A wire from pin 7 connected to LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //0x3F should be replaced with your own LCD address</p><p>int btnStateStart = 0; <br>int btnStateReset = 0; </p><p>bool start = false; // If we can start measuring. Will be true when start button has been pressed int endTime = 0; // When to end the measuring in the loop() int BPM = 0; / /Beats Per Minute const int threshold = 526; // Determine which Signal to "count as a beat" and which to ignore. PulseSensorPlayground pulseSensor; //Creates an instance of the PulseSensorPlayground object called "pulseSensor"</p><p>bool soundAndLed = false; //Make the speaker en LED's do their thing</p><p>int soundDelay = 0; // Interval between two beats</p><p>int melody[] ={<br> NOTE_G4, END };</p><p>int noteDurations[] = { 4 };</p><p>int speed = 0; //place soundDelay value in here when calculated</p><p>void setup(){<br> digitalWrite(reset, HIGH); //for the reset pin delay(200); //Best practice so you can't spam the reset button lcd.clear(); lcd.begin(16,2); //Set screen "height" lcd.setCursor(0,0); //first lcd line lcd.print("Finger/earlobe"); lcd.setCursor(0,1); //second lcd line lcd.print("and press start"); pinMode(ledset1, OUTPUT); pinMode(ledset2, OUTPUT); pinMode(startBtn, INPUT); pinMode(resetBtn, INPUT); pinMode(reset, OUTPUT); </p><p> Serial.begin(9600);</p><p> // Configure the PulseSensor object, by assigning our variables to it. pulseSensor.analogInput(sensor); pulseSensor.setThreshold(threshold); </p><p> if (pulseSensor.begin()) { Serial.println("pulseSensor Object created"); //This prints one time at Arduino power-up }</p><p> //Make sure the LED's and speaker are off digitalWrite(ledset1, LOW); digitalWrite(ledset2, LOW); noTone(speaker); }</p><p>void loop() {<br> btnStateStart = digitalRead(startBtn); //Start monitoring start btn if(btnStateStart == HIGH){ //startbtn pressed start = true; //we can now start the code for measuring/searching for a heartbeat endTime = millis() + (1000 * 15); //15 seconds printLCD("Measuring..."); }</p><p> btnStateReset = digitalRead(resetBtn); //Start monitoring start btn if(btnStateReset == HIGH){ //resetbtn pressed printLCD("Resetting..."); digitalWrite(reset, LOW); }</p><p> if(start == true){ if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened". Serial.print("BPM: "); Serial.println(BPM); BPM = pulseSensor.getBeatsPerMinute(); } }</p><p> if (millis() >= endTime && start == true){ //15 seconds passed lcd.clear(); lcd.print("BPM: "); lcd.print(String(BPM)); soundDelay = 60000/BPM; //Milliseconds between two beats. Depends on the BPM speed = soundDelay; start = false; soundAndLed = BPM == 0 ? false : true; //if BPM is 0 soundAndLed will be false otherwise true } if(soundAndLed == true){ //Loop the LED's and sound on the BPM until reset</p><p> int noteDuration = speed*noteDurations[0]; tone(speaker, melody[0],noteDuration*.95); digitalWrite(ledset1, HIGH); digitalWrite(ledset2, HIGH); delay(soundDelay); noTone(speaker); digitalWrite(ledset1, LOW); digitalWrite(ledset2, LOW); delay(soundDelay); } }</p>
Step 3: Soldering
Step 4: Build the Case
For the casing you can choose what material you would like and how you would like the case to look. But above is the case that I made.
Step 5: Final Product
Place the hardware and the arduino in your case. I used a powerbank as power supply, but you can use whatever power supply you want (if it compatible with your arduino). Make some final touched and you are done.