Hi guys. Im doing a project with the pulse sensor. I used the available code found online. The code works very well with arduino uno, where it print the heartbeat in serial monitor when i placed my finger to the sensor and stop when my finger is not there. However, when i switched it to arduino pro mini 3V, the sensor somehow kept detecting heartbeat even when there is none and print it in serial monitor (100++ heart rate). Anyone has clue on this ? There are not much different between arduino uno and pro mini 3V besides the speed of 16Mhz and 8Mhz right ? I tried with several arduino Unos and they all works fine, and I also tried with several Arduino Pro minis, they all having the same problem. Is the programming problem or hardware problem ?
Please help me guys, thanks in advance. I have attached the code here.
// Sensor and pins variables
int pulsePin = 0;
int blinkPin = 13;
// Pulse rate variable
volatile int BPM;
// Raw signal
volatile int Signal;
// Interval between beats
volatile int IBI = 600;
// Becomes true when the pulse is high
volatile boolean Pulse = false;
// Becomes true when Arduino finds a pulse
volatile boolean QS = false;
void setup(){
// Start Serial
Serial.begin(115200);
// Sets up to read Pulse Sensor signal every 2mS
interruptSetup();
}
void loop(){
// If heart beat is found
if (QS == true) {
// Print heart rate
Serial.print("Heart rate: ");
Serial.println(BPM);
// Reset the Quantified Self flag for next time
QS = false;
}
// Wait 20 ms
delay(20);
}
Seems to me this code uses serial and is using pin 0 (serial Rx).
That's asking for trouble.
Don't know why it is working with 1 and not with the other.
Did you check the sensor you use (and we have no clue to what it is), if that also works correctly with 3 volts ?
Perhaps you need to take some measures in that case, or it might not work at all.
The pulse sensor that i used is a normal pulse sensor. it works with 5v or 3.3v even with the uno, both supply doesn't not affect it. It works fine with Uno, it don't print anything at the serial monitor when it does not detect heartbeat, unlike the pro mini, it just randomly print heartbeat even when there is none, but it correct heartbeat when the finger is applied to the sensor.
DaveEvans:
I have no idea why it isn't working, but regarding this:
The sensor is supposed to be connected to analog pin 0.
The wiring_analog.c in the Arduino core will accept either '0' or 'A0'. the 'A0' constant is defined by the pins_arduino.h depending on which variant you selected.
diontan524:
The pulse sensor that i used is a normal pulse sensor. it works with 5v or 3.3v even with the uno, both supply doesn't not affect it. It works fine with Uno, it don't print anything at the serial monitor when it does not detect heartbeat, unlike the pro mini, it just randomly print heartbeat even when there is none, but it correct heartbeat when the finger is applied to the sensor.
Are you sure your ISR() code can execute 500 times a second? the 8/16MHz processor clock may be the difference.
At 8MHZ you have 16,000 clock cycles (instructions almost)?
The analogRead() call can take over 100us (0.0001 seconds). So the rest of the ISR() code only has 1900us (15200 clock cycles), plus what about the foreground task? and the Other ISR()'s
Did you recalculate the Prescaler value for the 8MHz Clock?
the CLI(), SEI() statements are not needed in the ISR. Unless you Enabled interrupts inside your ISR, (a bad IDEA), interrupts are disable by the by the interrupt and re-enabled by the return. (part of the ISR macro).
I would time your ISR(), set a pin on entry, clear it on exit. verify it with a 'scope.
chucktodd:
The wiring_analog.c in the Arduino core will accept either '0' or 'A0'. the 'A0' constant is defined by the pins_arduino.h depending on which variant you selected.
Right. Not to beat a dead horse, but my point (apparently poorly made) was that MAS3's supposition, that the code might be "using pin 0 (serial Rx)...that's asking for trouble," was not correct: the code uses analog pin 0, not digital pin 0 (serial Rx). So that can't be the source of the problem....