Skip to main content

Práctica 1.3 Medimos nuestras pulsaciones

TIEMPO ESTIMADO: 150 minutos

Como ya sabes, una librería de Arduino es una colección de código y ejemplos sobre un tema o dispositivo específico. Por ejemplo, para controlar el sensor que vamos a utlizar en esta práctica, un pulsómetro, vamos a usar biblioteca PulseSensor Playground es una colección de código y proyectos hechos sólo para este sensor y Arduino.

 

La librería Pulse Sensor Playground

Lo primero que haremos será instalar esta librería. Para ello, iremos a Programa > Incluir Librería > Administrar Bibliotecas... :

image-1665231393395.14.58.png

Una vez ahí, haremos click y nos aparecerá una ventana emergente en la que podremos buscar la librería, que en este caso se llama Pulse Sensor Playground, cuando aparezca, pondremos el ratón sobre ella y nos aparecerá el botón Instalar. La instalaremos:

image-1665231801613.15.50.png

Cerraremos la ventana emergente y veremos que si vamos a Archivo > Ejemplos nos aparecerán los ejemplos de la librería Pulse Sensor Playground:image-1665232108397.27.14 copia.png

Una vez la hayamos instalado, abriremos el ejemplo GettingStartedProject. Y pasaré a explicarte lo que hace cada línea de código.

¡Pulsación detectada ♥!

Lo primero que voy a hacer es poner aquí el código, aunque imagino que ya lo tienes abierto en tu IDE de Arduino:


/*  PulseSensor Starter Project and Signal Tester
 *  The Best Way to Get Started  With, or See the Raw Signal of, your PulseSensor.com™ & Arduino.
 *
 *  Here is a link to the tutorial
 *  https://pulsesensor.com/pages/code-and-guide
 *
 *  WATCH ME (Tutorial Video):
 *  https://www.youtube.com/watch?v=RbB8NSRa5X4
 *
 *
-------------------------------------------------------------
1) This shows a live human Heartbeat Pulse.
2) Live visualization in Arduino's Cool "Serial Plotter".
3) Blink an LED on each Heartbeat.
4) This is the direct Pulse Sensor's Signal.
5) A great first-step in troubleshooting your circuit and connections.
6) "Human-readable" code that is newbie friendly."

*/


//  Variables
int PulseSensorPurplePin = 0;        // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED13 = 13;   //  The on-board Arduion LED


int Signal;                // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550;            // Determine which Signal to "count as a beat", and which to ingore.


// The SetUp Function:
void setup() {
  pinMode(LED13,OUTPUT);         // pin that will blink to your heartbeat!
   Serial.begin(9600);         // Set's up Serial Communication at certain speed.

}

// The Main Loop Function
void loop() {

  Signal = analogRead(PulseSensorPurplePin);  // Read the PulseSensor's value.
                                              // Assign this value to the "Signal" variable.

   Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


   if(Signal > Threshold){                          // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
     digitalWrite(LED13,HIGH);
   } else {
     digitalWrite(LED13,LOW);                //  Else, the sigal must be below "550", so "turn-off" this LED.
   }


delay(10);


}

Ahora, vamos a ir desmenuzando qué es lo que hace.

FUENTES:

Librería de Pulse Sensor: https://pulsesensor.com/pages/installing-our-playground-for-pulsesensor-arduino
Sobre Pulse Sensor: https://pulsesensor.com/pages/code-and-guide