Hi there!
I am brand new to this whole coding thing and just got my pulse sensor up and running, I was wondering if anyone had a small code I could add into (I'm guessing the arduino file, not the processing) to have an buzzer go off if it drops below a certain number, say 58 bpm. Also, would I have to add a small two pin buzzer to the arduino itself? If so, how?
Thanks so much!
You haven't provided much detail, so I'll give a generic reply.
I assume your pulse sensor provides an electrical pulse which goes from logic low ( approx. 0 v.) to logic high (approx. 5 v.), or that you can condition the pulse sensor output to get logic levels.
So, if you are on an UNO, either pin 2 or 3 will service external interrupts. Use the "attachInterrupt()" function to set up an interrupt (It's really very easy to set up).) This interrupt will be used to record the moments at which the last 58 pulse beats occurred. To record these, set up an array of unsigned long integers which is long enough to store 58 values. Every time the interrupt occurs, use the interrupt service routine to store the current system time (the millis() function) in the last position in this array, and bump all of the other values down, with the 0-th element being pushed out the bottom.
So at the arrival of each new pulse, the time of the 58th pulse back (the one you just bumped out) is obtainable from your array, and compare it to the current millis() time. If that time is more than one minute, the last 58 pulse beats took more than a minute.
This gives you an immediate response to a slow pulse.
Hope this helps.
Good luck.
John Doner
Very bad idea, based on two misunderstandings.
One is that the events you are detecting are "urgent", when in fact they occur thousands - or in this case, many millions - of processor clock cycles apart and accuracy in the microsecond range is neither necessary nor desirable. Depending on the pulse sensor, it may require "de-bouncing" which while it can be performed in interrupts, becomes unnecessarily complicated.
The second misunderstanding, is that interrupts are used to alter the "flow" of the main (loop) program whereas in fact, interrupts are deliberately engineered not to do so. If your main task is to time events, then you "poll" or check for those events in your main loop, alternately with checking for whether a certain time has expired and if necessary, displaying a result.
I posted some suggestions a little time back as to how best to do the pulse measurement.