مستشعر كشف ضربات القلب مع أردوينو | Arduino UNO | KY-039 | Project | Heartbeat Sensor - DIY Channel3

DIY Channel3

Arduino│ESP8266│ESP32│Drone│Robot

مستشعر كشف ضربات القلب مع أردوينو | Arduino UNO | KY-039 | Project | Heartbeat Sensor

مشاركة هذا

 


في المجموعة المكونة من 37 مستشعرًا لـ Arduino ، يوجد مستشعر ضربات القلب. الاسم يعد بالكثير. يميل الناس إلى الاعتقاد بأنه يوفر رقمًا رقميًا من خلال I2C أو شيء مشابه ، وهو رقم يمثل معدل ضربات القلب. ما يوفره المستشعر هو مجرد قيمة "تناظرية" من 0 إلى 1023 ، تخبرنا عن مقدار الضوء بالأشعة تحت الحمراء الذي يستقبله مستشعر الضوء ، أو مقدار تظليل شيء ما في مستشعر الضوء. كلما زادت القيمة ، قل الضوء الأحمر بالأشعة تحت الحمراء.


باختصار: ضع إصبعك بين مصباح الأشعة تحت الحمراء والترانزستور الضوئي لجهاز الاستشعار. تعمل ضربات قلبك على توسيع الأوعية الدموية في إصبعك ، مما يؤدي إلى تصفية الأشعة تحت الحمراء. هذا يخلق إشارة نابضة.




في هذا المشروع ، أصف كيف يتم تحويل هذه الإشارة إلى معدل ضربات قلب مثل 66 نبضة في الدقيقة (نبضة في الدقيقة).


الخطوات البسيطة

إذا قرأت للتو ورسمت القيم من مستشعر KY-039 ، فستحصل على شيء مثل هذا:

القيم هي قيم عدد صحيح. ليست دقيقة للغاية. بدلاً من ذلك ، احسب متوسط مجموعة منهم وارسم المتوسط. يمكنك الحصول على هذه:


هنا يمكنك بالفعل رؤية نبض القلب. احصل على فارق التوقيت بين كل ارتفاع ملحوظ في النبض. من ذلك يمكنك حساب معدل ضربات القلب في BPM.


(النمط المتعرج الصغير في الصورة أعلاه يرجع إلى الضوء الاصطناعي ، 50 هرتز ، شيء آخر يجب على المرء التعامل معه.)



المكونات الاساسية :


- Arduino UNO R3

- KY-039 heartbeat sensor

- Jumper wires


++ مخطط الرسم البياني :

++ الكود البرمجي هنا :

#define samp_siz 4
#define rise_threshold 5
// Pulse Monitor Test Script
int sensorPin = 0;
void setup() {
   Serial.begin(9600);
}
void loop ()
{
   float reads[samp_siz], sum;
   long int now, ptr;
   float last, reader, start;
   float first, second, third, before, print_value;
   bool rising;
   int rise_count;
   int n;
   long int last_beat;
   for (int i = 0; i < samp_siz; i++)
     reads[i] = 0;
   sum = 0;
   ptr = 0;
   while(1)
   {
     // calculate an average of the sensor
     // during a 20 ms period (this will eliminate
     // the 50 Hz noise caused by electric light
     n = 0;
     start = millis();
     reader = 0.;
     do
     {
       reader += analogRead (sensorPin);
       n++;
       now = millis();
     }
     while (now < start + 20);  
     reader /= n;  // we got an average
     // Add the newest measurement to an array
     // and subtract the oldest measurement from the array
     // to maintain a sum of last measurements
     sum -= reads[ptr];
     sum += reader;
     reads[ptr] = reader;
     last = sum / samp_siz;
     // now last holds the average of the values in the array
     // check for a rising curve (= a heart beat)
     if (last > before)
     {
       rise_count++;
       if (!rising && rise_count > rise_threshold)
       {
         // Ok, we have detected a rising curve, which implies a heartbeat.
         // Record the time since last beat, keep track of the two previous
         // times (first, second, third) to get a weighed average.
         // The rising flag prevents us from detecting the same rise 
         // more than once.
         rising = true;
         first = millis() - last_beat;
         last_beat = millis();
         // Calculate the weighed average of heartbeat rate
         // according to the three last beats
         print_value = 60000. / (0.4 * first + 0.3 * second + 0.3 * third);
         Serial.print(print_value);
         Serial.print('\n');
         third = second;
         second = first;
       }
     }
     else
     {
       // Ok, the curve is falling
       rising = false;
       rise_count = 0;
     }
     before = last;
     ptr++;
     ptr %= samp_siz;
   }
} 
#arduino #raspberrypi #electronics #arduinoproject #robotics #technology #engineering #arduinouno #robot #iot #diy #electrical #maker #programming #electronic #microcontroller #arduinoprojects #tech #esp #pcb #arduinomega #d #electricalengineering #robotica #diyelectronics #project #coding #arduinofun #sensor



No comments:

Post a Comment