From now I’m gonna refer to my final project as Warm Robot, just a temporary name but it makes it easy to track the project’s progress.
After purchasing the pulse sensor, I tried to do a test with it with LED light as an output. It reads my heartbeat pretty well, especially when I hooked it up on my ear.
(it came with an ear clip!)
I wrote the code for analog serial reader and added an LED for an output (and additional LED to test out multiple output), here’s the code:
int Threshold = 520; //the turning point when the heart beats int LED1 = 13; //first LED, to indicate each beat int LED2 = 5; //another output in correspondence to the first LED void setup() { Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { int Pulse = analogRead(A0); //where I plugged in my pulse sensor // print out the value you read: Serial.println(Pulse); if (Pulse > Threshold){ digitalWrite(LED1,HIGH); } else { digitalWrite(LED1,LOW); } delay(10); if (LED1, HIGH){ digitalWrite(LED2,HIGH); delay(2); digitalWrite(LED2,LOW); delay(2); digitalWrite(LED2,HIGH); delay(2); digitalWrite(LED2,LOW); delay(4); /* i made sure the total of delay is less than or the same number as the LED1 delay */ } else { digitalWrite(LED2,LOW); } }
Then I opened the serial plotter to see the graph of the value from the pulse sensor. I googled and looked around codes people have written to find a best way to count each heartbeat and so far putting a threshold seems like the simplest one that worked for me. I wonder if there’s a way to count it for each +apex and -apex? is that even possible? I think? I’ll need to consult someone for this.
mmmm yaA i’m alive
it seems to be working with LED lights, I tried piezo for a sound output but it doesn’t seem to be working.. I thought it would work if I just change it from digital to analog. Regardless, it’s a step forward!! let’s see what else I can do before class on Wednesday!