Use heart rate sensor to control the flow rate of water

Hi!! I’m trying to use heart rate sensor to detect heart rate and then change the flow rate of water based on different heart rate. I use a water pump, and here is my circuit:



It does work, but I found that the flow rate is not changing. I think there may be some problems with my code.

  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
}

void loop(){
  if (analogRead(A0) > 700) {
    analogWrite(3, (random(100, 200)));
    digitalWrite(2,LOW);
    analogWrite(5, (random(100, 200)));
    digitalWrite(4,LOW);

  } else {
    analogWrite(3, 0);
    digitalWrite(2,LOW);
    analogWrite(5, 0);
    digitalWrite(4,LOW);

  }

}

This is my code. And I found the serial plotter is blank.

Could you please help me to find the problem? Thank you so much!!!


Here is my circuit in tinkercad

But not all of it

Please post your complete sketch showing where you output data to Serial, for instance

Using D1 on an UNO doesn't look good. D1 is allso connected to thr USB interface.
How is the UNO powered?
What voltage do You measure at Vin?

The heart rate sensor measures the amount of absorbed infrared. Water doesn't absorb infrared. Won't work.

I think that @d901ia has a human hanging off the heartrate sensor and is trying to control the pump flow by controlling or monitoring the human's pulse.

Some sort of biofeedback.

Tom... :grinning: :+1: :coffee: :australia:

That's not correct. Here is the absorbance spectrum.

https://webbook.nist.gov/cgi/cbook.cgi?ID=C7732185&Type=IR-SPEC&Index=1

What loop() is doing:

When A0 is reading 700 or above, PWM signal on pins 3 and 5 (which I guess are your motor drivers - I can't be bothered to try and figure out that spaghetti image) is changed randomly to between 100 and 200 about 9,000 times per second. The PWM rate will average out at 150.

When A0 is below 700, pins 3 and 5 are set to 0, i.e. LOW, i.e. motors off. This is also done about 9,000 times a second.

In both cases pins 2 and 4 are set LOW - again this happens about 9,000 times a second.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.