Medical Electronics is also going to advance with the application of the Internet of Things. Internet of Things is the fastest growing technology, finding applications everywhere and in everything. In this project, a simple patient health monitoring device is developed as an IoT application. The device could read pulse rate, measure surrounding temperature, and continuously monitors the pulse rate and surrounding temperature and updates them to an IoT platform. The IoT platform used in this project is ThingSpeak.
The IoT project developed here is built on Arduino UNO. The Arduino is one of the earliest and most popular prototyping boards. So It is assumed that the reader has gone through the project how to get started with the arduino and Interface LCD with arduino . The Arduino is interfaced with ESP8266 Wi-Fi modem to connect with an internet router and access the cloud server. The Arduino is interfaced with LM-35 temperature sensor to sense the surrounding temperature and a pulse sensor to read pulse rate. The measured pulse rate and temperature are displayed on a character LCD interfaced to the Arduino and are passed to the cloud platform by transmitting data to a Wi-Fi access point. With this simple yet effective device, the health status of a critically ill patient can be constantly monitored. It can be used to keep track of the health of aged people who frequently have heart or blood pressure issues.
The health-related data i.e. pulse rate and temperature are periodically updated and logged to the ThingSpeak platform. That data can be further utilized to keep the medical history of the patient. The Freeboard.io is used as Dashboard to graphically represent the recorded data.
The Arduino Sketch running over the device implements the various functionalities of the project like reading sensor data, converting them into strings, passing them to the IoT platform, and displaying measured pulse rate and temperature on character LCD. The Sketch is written, compiled, and loaded using the Arduino IDE. The IoT platform used is ThingSpeak and Freeboard.io is used to build the IoT Dashboard.
Fig. 1: Prototype of Arduino based Heartbeat and Body Temperature Monitoring IoT Device
Components Required
Fig. 2: List of Components required for Arduino based Heartbeat and Body Temperature Monitoring IoT Device
Block Diagram
Fig. 3: Block Diagram of Arduino based Heartbeat and Body Temperature Monitoring IoT Device
Circuit Connections
The health monitoring equipment designed here is an IoT device. It is built on Arduino UNO. The Arduino UNO is one of the most popular prototyping board that is commonly used even in the IoT projects. The pulse reader, LM-35 temperature sensor, character LCD and ESP8266 Wi-Fi modem are interfaced to the Arduino to make this medical IoT device.
Fig. 4: Image showing circuit connections of Arduino based Heartbeat and Body Temperature Monitoring IoT Device
The Arduino based IoT device has the following circuit connections
Arduino UNO – The Arduino UNO is ATmega328 based microcontroller board. It is one of the most popular prototyping boards. The board comes with built-in arduino boot loader. It has 14 GPIO pins, 6 PWM pins, 6 Analog inputs and on board UART, SPI and TWI interfaces, an on-board resonator, a reset button, and holes for mounting pin headers. While programming the board, it can be connected to the PC using USB port and the board can runs on USB power. The Arduino UNO has 32 Kb Flash memory, 1 Kb EEPROM and 2 Kb SRAM. The board can be connected to different Arduino Shields for connectivity with Ethernet, Bluetooth, Wi-Fi, Zigbee or Cellular network and it can be connected to most of the IoT platforms. The ATmega328 controller has the following pin configuration –
Fig. 5: Table listing pin configuration of Arduino Uno
Fig. 6: Table listing pin configuration of Arduino Uno
In this project, the two Analog Input pins of the board are used to interface the Pulse sensor and LM-35 temperature sensor, two GPIO are used to interface ESP8266 module where pins are configured UART transmitter and receiver pins using software serial and 6 GPIO pins are used to interface the 16X2 character LCD.
LM-35 Temperature Sensor – LM-35 is a precision IC temperature sensor with its output proportional to the temperature (in oF). The sensor circuitry is sealed and therefore it is not subjected to oxidation and other processes. With LM-35, the temperature can be measured more accurately than with a Thermistor. It also possesses low self-heating and does not cause more than 0.1 oC temperature rise in still air. The LM-35 has three pins – VCC (Pin 1), Out (Pin 2), and Ground (Pin 3). The VCC and Ground pin are connected to VCC and ground respectively. The LM-35 can be supplied a voltage between 4V and 20V, so a 5V supply is used on it same which is powering the Arduino board. The out pin of the LM-35 is connected to the A1 pin of the Arduino since the output from the LM-35 is analog in nature. The value read is converted to Fahrenheit using the standard formulas.
Pulse Sensor – The Pulse Sensor Amped is a plug-and-play heart-rate sensor for microcontrollers like PIC, AVR, Arduino, etc. It can be used to easily incorporate live heart-rate data into a project. It essentially combines a simple optical heart rate sensor with amplification and noise cancellation circuitry making it fast and easy to get reliable pulse readings. It simply needs to be clipped to the earlobe or fingertip and plug into 3.3 V or 5 V supply from Arduino or battery. The pulse sensor module has three terminals – VCC, Ground, and Out. The output pin of the pulse sensor module is connected to analog pin A0 of the Arduino. The VCC is connected to 5V DC output of Arduino and Ground is connected to the common ground.
ESP8266 Wi-Fi Modem – The ESP8266 Wi-Fi Module is used to connect the Arduino board with a Wi-Fi router so that it can access the cloud. It is a self-contained SOC with an integrated TCP/IP protocol stack that can access to a Wi-Fi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor. Each ESP8266 module comes pre-programmed with an AT command set firmware. The module comes available in two models – ESP-01 and ESP-12. ESP-12 has 16 pins available for interfacing while ESP-01 has only 8 pins available for use. The ESP-12 has the following pin configuration –
Fig. 7: Table listing pin configuration of ESP8266 ESP-12 Modem
The ESP-01 model is used in the project. The ESP-01 model has the following pin configuration –
Fig. 8: Table listing pin configuration of ESP8266 ESP-01 Modem
The RESET and VCC pins of the module are connected to the 3.3 V DC from Arduino while the Ground pin is connected to the common ground. The Tx and Rx pins of the module are connected to the 9 and 10 pins of the Arduino UNO.
16X2 LCD – A character LCD is used to display the pulse rate and surrounding temperature. The 16X2 LCD display is connected to the Arduino board by connecting its data pins to pins 3 to 6 of the Arduino board. The RS and E pins of the LCD are connected to pins 13 and 12 of the Arduino board respectively. The RW pin of the LCD is grounded. The VCC pin of the LCD module is connected to 5V DC from the Arduino. For adjusting the brightness of the LCD module, a variable resistor is connected at the VEE pin and the other two terminals of the variable resistor are connected between VCC and ground.
Fig. 9: Table listing circuit connections of Arduino Uno and LCD
The standard open-source library for interfacing LCD with Arduino board is used in the project. The library works as expected and needs no changes or modifications.
Power Supply – All the components in the circuit require 5V DC. The circuit is initially powered by a 12V battery. The power from the battery is regulated to 5V DC using a 7805 voltage regulator IC. Pin 1 of the voltage regulator IC is connected to the anode of the battery and pin 2 of it is connected to the ground. The voltage output is drawn from pin 3 of the IC. An LED along with a 10K Ω pull-up resistor is also connected between common ground and output pin to get a visual hint of supply continuity. The character LCD, pulse sensor, and LM-35 temperature sensor are provided 5V DC from the 5V DC power output of the Arduino while the ESP module is provided 3.3 V DC from 3.3 V DC power output of the Arduino.
How the circuit works –
This is a prototype model for IoT based pulse rate monitor. It can be designed as a wearable watch or earplug. In a wearable design, the character LCD could be removed and the entire circuit can be shifted to a small controller board or SOC.
When the circuit is powered by the battery, the Arduino starts reading the pulse rate from the pulse sensor and the ambient temperature from the LM-35 temperature sensor. The pulse sensor has an infrared LED and a phototransistor which help detect the pulse at the tip of the finger or earlobe. Whenever it detects a pulse, its IR LED flashes. The flash of the IR LED is detected by the phototransistor and its resistance changes when the pulse is changed. The heartbeat of a normal adult ranges from 60 to 100 per minute. For detecting beats per minute (BPM), first, an interrupt is set which triggers in every 2 Milliseconds. So, the sampling rate by the Arduino to detect pulse is 500 Hz. This sampling rate is sufficient to detect any pulse rate.
So, at every 2 Milliseconds, the Arduino reads analog voltage output from the pulse sensor. The analog output from the pulse sensor is converted to a digital value using in-built ADC channel. The Arduino has 10-bit long ADC channel, so the digitized value can range from 0 to 1024. The middle value for this range is 512. Initially, the first beat is set to true and the second beat is counted when the condition that analog output from the pulse sensor is greater than the middle point i.e. 512 is satisfied. Then, onwards, every next beat is counted when the analog output from the pulse sensor is greater than the middle point i.e. 512 and 3/5 of the time between the beats recorded in previous cycle has passed. Every time, the beat is detected, a variable representing BPM is updated. This value in this variable is pushed to an array in every minute and is used to represent the actual Beats Per Minute or Heart Rate. The Arduino code also uses a function to provide an LED fading effect on every beat.
The pulse sensor can also detect body temperature. The LM-35 is used to detect the surrounding temperature here. The operating temperature range of LM-35 is from -55 °C to 150 °C. The output voltage varies by 10 mV in response to every oC rise/fall in ambient temperature, i.e., its scale factor is 0.01 V/ oC. The LM-35 IC does not require any external calibration or trimming to provide typical accuracies of ±0.25 °C at room temperature and ±0.75 °C over the temperature range from −55 °C to 150 °C. Under normal conditions, the temperature measured by the sensor won’t exceed or recede the operational range of the sensor. Typically in the temperature range from −55 °C to 150 °C, the voltage output of the sensor increases by 10 mV per degree Celsius. The voltage output of the sensor is given by the following formulae –
Vout = 10 mV/°C*T
where,
Vout = Voltage output of the sensor
T = Temperature in degree Celsius
So, T (in °C) = Vout/10 mV
T (in °C) = Vout(in V)*100
If VCC is assumed to be 5 V, the analog reading is related to the sensed voltage over 10-bit range by the following formulae –
Vout = (5/1024)*Analog-Reading
So, the temperature in degree Celsius can be given by the following formulae –
T (in °C) = Vout(in V)*100
T (in °C) = (5/1024)*Analog-Reading *100
So, the temperature can be measured directly by sensing the analog voltage output from the sensor. The analogRead() function is used to read analog voltage at the controller pin.
The Arduino collects data from both the sensors and converts the values to strings. The heartbeat is graphically represented on the character LCD along with the measured pulse rate and time between pulses as text. The temperature is also displayed on the LCD module.
The ESP8266 Wi-Fi module connected to the Arduino uploads the same data to ThingSpeak Server as it finds the Wi-Fi Access Point. For displaying and monitoring data uploaded to the ThingSpeak server, either a digital dashboard or a data broker is needed. In this project, a digital dashboard called Freeboard.io is used to monitor the sensor data visually online. The Freeboard.io use the JASON file to visualize ThingSpeak data. It offers three elements to build a dashboard –
1) Data Sources – The data sources get the data from external sources. These external sources can be data broker services, JavaScript applications or JSON files receiving content from an HTTP server. In this project, the data source is a JSON file that receives data from the ThingSpeak server.
2) Widgets – The Widgets help to display data in textual or graphical form. There are many widgets available in Freeboard.io like text, graph, gauge etc.
3) Panes – These are used to organize widgets.
Freeboard.io requires sign up and after sign widgets can be created.
Fig. 10: Screenshot of Freeboard Sign Up Page
Freeboard.io Sign Up
There are two gauge type widgets created to monitor temperature and heartbeat.
Fig. 11: Screenshot of Gauge Type Widgets on Freeboard API
Freeboard.io Widgets
The dashboard on Freeboard.io can be created as follow –
1. Go to freeboard.io website and sign up with a new account.
2. Enter the name and click on the create button, after entering into the new window, click on the create data source and select type as JASON.
Fig. 12: Screenshot of creating data source on Freeboard API
Freeboard.io Data Source Selection
3. After that fill the fields as shown in below image. In the URL tab shown in the image, change the number 392797 with the respective channel id.
Fig. 13: Screenshot of making data source selection on Freeboard API
Setting Data Source on Freeboard.io to ThingSpeak Platform
4. After creating the data source, click on add pane and select as Gauge.
Fig. 14: Screenshot of Setting Data Source on Freeboard.io to ThingSpeak Platform
Freeboard.io Widget Creation
5. At the pane, after selecting the Gauge select the following as shown below and create the widgets.
Fig. 15: Screenshot of Widget Creation on Freeboard.io
Freeboard.io Gauge Widget Creation
This way the sensor data can be uploaded on ThingSpeak server and viewed online at Freeboard.io dashboard. The dashboard can be accessed from any device like Smart Phone, Laptop or PC having an Internet connectivity.
The Arduino board needs to connect with a Wi-Fi access point in order to connect with the internet. The name and password of the Wi-Fi access point are hard-coded in the Arduino sketch. The initialization of the Wi-Fi connection is done within the setup() function of the Arduino Sketch which runs once the board is powered on.
The setup of Wi-Fi connection is run by passing AT commands to the ESP8266 Wi-Fi modem. The modem is connected to GPIO pins of the Arduino which are configured as UART transmitter and receiver pins by using software serial library. The Wi-Fi is initialized by passing the following AT commands to ESP module –
AT : This command is passed to check if modem is functioning properly.
AT+GMR: This command is passed to print the firmware version.
AT+CWMODE=3 : This command is passed to set the Wi-Fi mode to both AP as well as Station mode.
AT+RST: This command is passed to reset the modem.
After reset, the modem check IP addresses of the available access points. The ESP modem can connect with the access point whose SSID and Password are hard-coded in the Arduino Sketch. The following AT command is passed to connect with the Access Point –
AT+CWJAP
Once the modem is connected to an access point, it obtains IP address by executing the following command –
AT+CIFSR: This command is used to obtain IP address of ESP module as an client.
The IP address is stored in a string and acknowledged to the Arduino board. Once the sensor data is collected, the following AT commands are passed to the ESP module for sending it to the cloud-
AT+CIPSTART=4,”TCP”,”184.106.153.149″,80: This command is passed to start a TCP connection with the given IP address at the specified port (80).
AT+CIPSEND=4, String(getStr.length()): This command is passed to send data at the previously mentioned IP address with the number of transmit connections set to 4 and length of data (which can be maximum 2048 bytes) specified.
So, the Arduino connects with the server via ESP modem and the sent data can be graphically observed on Freeboard.io.
Programming Guide –
The Arduino sketch running on the device manages to read pulse rate from the pulse sensor, read temperature from LM-35 sensor, convert read analog data to useful physical quantities i.e. Heartbeat and Temperature, display data on character LCD, manage connection with the Wi-Fi Access Point and send data to the ThingSpeak server. The sketch begins with importing required standard libraries for LCD interfacing and software serial for serial communication with the Wi-Fi modem. The variables representing pin connections with the sensors and LCD are declared. Some variables are declared to record heartbeat and temperature.
Fig. 16: Screenshot of Arduino code used for Initialization of Pulse Rate and Body Temperature Monitoring IoT Device
Initialization in Arduino Sketch for Pulse Rate and Body Temperature Monitoring IoT Device
The setup() function is called in which baud rate for the serial communication for communication with the Wi-Fi modem is set to 9600. The Wi-Fi mode and network connectivity is established using the AT commands with some delays. The delay should be given according to time it takes to connect with the network.
Fig. 17: Screenshot of Arduino Code used in Setup Function for Pulse Rate and Body Temperature Monitoring IoT Device
Setup Function in Arduino Sketch for Pulse Rate and Body Temperature Monitoring IoT Device
The loop() function is called in which the sensor data is fetched and stored in the initialized variables. The functions having open source code for reading heartbeat (working of which is already explained in the working of the circuit) are called along with the function to read temperature from the LM-35 sensor. The sensor data is displayed on the character LCD. The esp8266() function is called for transmitting data to the cloud.
Fig. 18: Screenshot of Arduino Code used in Loop Function for Pulse Rate and Body Temperature Monitoring IoT Device
Loop Function in Arduino Sketch for Pulse Rate and Body Temperature Monitoring IoT Device
At the esp8266() function, the AT commands for establishing TCP connection are passed, and then API key of the ThingSpeak is given to transmit a data to the registered channel. At every 16 seconds, the data gets updated to the ThingSpeak channel.
Fig. 19: Screenshot of Function Managing IoT communication in Arduino Sketch for Pulse Rate and Body Temperature Monitoring IoT Device
Function Managing IoT communication in Arduino Sketch for Pulse Rate and Body Temperature Monitoring IoT Device
This completes the Arduino sketch for IOT Based Heartbeat monitoring System. Check out the Arduino Sketch from the code section to try it out.
This project is developed as a prototype model. It can be easily realized to any other controller or SOC to meet the size constraint and power requirement as a wearable. The wearable model can be LCD module removed.
Project Source Code
### //Program to #include
#include float pulse = 0; float temp = 0; SoftwareSerial ser(9,10); String apiKey = "U5AGYVQT5JRJPSDR"; // Variables int pulsePin = A0; // Pulse Sensor purple wire connected to analog pin 0 int blinkPin = 7 ; // pin to blink led at each beat int fadePin = 8; // pin to do fancy classy fading blink at each beat int fadeRate = 0; // used to fade LED on with PWM on fadePin LiquidCrystal lcd(13, 12, 6, 5, 4, 3); // Volatile Variables, used in the interrupt service routine! volatile int BPM; // int that holds raw Analog in 0. updated every 2mS volatile int Signal; // holds the incoming raw data volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded! volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when not a "live beat". volatile boolean QS = false; // becomes true when Arduoino finds a beat. // Regards Serial OutPut -- Set This Up to your needs static boolean serialVisual = true; // Set to 'false' by Default. Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse volatile int rate[10]; // array to hold last ten IBI values volatile unsigned long sampleCounter = 0; // used to determine pulse timing volatile unsigned long lastBeatTime = 0; // used to find IBI volatile int P = 512; // used to find peak in pulse wave, seeded volatile int T = 512; // used to find trough in pulse wave, seeded volatile int thresh = 525; // used to find instant moment of heart beat, seeded volatile int amp = 100; // used to hold amplitude of pulse waveform, seeded volatile boolean firstBeat = true; // used to seed rate array so we startup with reasonable BPM volatile boolean secondBeat = false; // used to seed rate array so we startup with reasonable BPM void setup() { lcd.begin(16, 2); pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat! pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat! Serial.begin(115200); // we agree to talk fast! interruptSetup(); // sets up to read Pulse Sensor signal every 2mS // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE, // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN // analogReference(EXTERNAL); lcd.clear(); lcd.setCursor(0,0); lcd.print("Engineers Garage"); ser.begin(9600); ser.println("AT"); delay(1000); ser.println("AT+GMR"); delay(1000); ser.println("AT+CWMODE=3"); delay(1000); ser.println("AT+RST"); delay(5000); ser.println("AT+CIPMUX=1"); delay(1000); String cmd="AT+CWJAP="EngineersGarage","egP@$$w0rd?""; ser.println(cmd); delay(1000); ser.println("AT+CIFSR"); delay(1000); } // Where the Magic Happens void loop() { serialOutput(); if (QS == true) // A Heartbeat Was Found { // BPM and IBI have been Determined // Quantified Self "QS" true when arduino finds a heartbeat fadeRate = 255; // Makes the LED Fade Effect Happen, Set 'fadeRate' Variable to 255 to fade LED with pulse serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial. QS = false; // reset the Quantified Self flag for next time } ledFadeToBeat(); // Makes the LED Fade Effect Happen delay(20); // take a break read_temp(); esp_8266(); } void ledFadeToBeat() { fadeRate -= 15; // set LED fade value fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers! analogWrite(fadePin,fadeRate); // fade LED } void interruptSetup() { // Initializes Timer2 to throw an interrupt every 2mS. TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED } void serialOutput() { // Decide How To Output Serial. if (serialVisual == true) { arduinoSerialMonitorVisual('-', Signal); // goes to function that makes Serial Monitor Visualizer } else { sendDataToSerial('S', Signal); // goes to sendDataToSerial function } } void serialOutputWhenBeatHappens() { if (serialVisual == true) // Code to Make the Serial Monitor Visualizer Work { Serial.print("*** Heart-Beat Happened *** "); //ASCII Art Madness Serial.print("BPM: "); Serial.println(BPM); lcd.clear(); lcd.print("BPM: "); lcd.print(BPM); } else { sendDataToSerial('B',BPM); // send heart rate with a 'B' prefix sendDataToSerial('Q',IBI); // send time between beats with a 'Q' prefix } } void arduinoSerialMonitorVisual(char symbol, int data ) { const int sensorMin = 0; // sensor minimum, discovered through experiment const int sensorMax = 1024; // sensor maximum, discovered through experiment int sensorReading = data; // map the sensor range to a range of 12 options: int range = map(sensorReading, sensorMin, sensorMax, 0, 11); // do something different depending on the // range value: switch (range) { case 0: Serial.println(""); /////ASCII Art Madness break; case 1: Serial.println("---"); break; case 2: Serial.println("------"); break; case 3: Serial.println("---------"); break; case 4: Serial.println("------------"); break; case 5: Serial.println("--------------|-"); break; case 6: Serial.println("--------------|---"); break; case 7: Serial.println("--------------|-------"); break; case 8: Serial.println("--------------|----------"); break; case 9: Serial.println("--------------|----------------"); break; case 10: Serial.println("--------------|-------------------"); break; case 11: Serial.println("--------------|-----------------------"); break; } } void sendDataToSerial(char symbol, int data ) { Serial.print(symbol); Serial.println(data); } ISR(TIMER2_COMPA_vect) //triggered when Timer2 counts to 124 { cli(); // disable interrupts while we do this Signal = analogRead(pulsePin); // read the Pulse Sensor sampleCounter += 2; // keep track of the time in mS with this variable int N = sampleCounter - lastBeatTime; // monitor the time since the last beat to avoid noise // find the peak and trough of the pulse wave if(Signal < thresh && N > (IBI/5)*3) // avoid dichrotic noise by waiting 3/5 of last IBI { if (Signal < T) // T is the trough { T = Signal; // keep track of lowest point in pulse wave } } if(Signal > thresh && Signal > P) { // thresh condition helps avoid noise P = Signal; // P is the peak } // keep track of highest point in pulse wave // NOW IT'S TIME TO LOOK FOR THE HEART BEAT // signal surges up in value every time there is a pulse if (N > 250) { // avoid high frequency noise if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) ) { Pulse = true; // set the Pulse flag when we think there is a pulse digitalWrite(blinkPin,HIGH); // turn on pin 13 LED IBI = sampleCounter - lastBeatTime; // measure time between beats in mS lastBeatTime = sampleCounter; // keep track of time for next pulse if(secondBeat) { // if this is the second beat, if secondBeat == TRUE secondBeat = false; // clear secondBeat flag for(int i=0; i<=9; i++) // seed the running total to get a realisitic BPM at startup { rate[i] = IBI; } } if(firstBeat) // if it's the first time we found a beat, if firstBeat == TRUE { firstBeat = false; // clear firstBeat flag secondBeat = true; // set the second beat flag sei(); // enable interrupts again return; // IBI value is unreliable so discard it } // keep a running total of the last 10 IBI values word runningTotal = 0; // clear the runningTotal variable for(int i=0; i<=8; i++) { // shift data in the rate array rate[i] = rate[i+1]; // and drop the oldest IBI value runningTotal += rate[i]; // add up the 9 oldest IBI values } rate[9] = IBI; // add the latest IBI to the rate array runningTotal += rate[9]; // add the latest IBI to runningTotal runningTotal /= 10; // average the last 10 IBI values BPM = 60000/runningTotal; // how many beats can fit into a minute? that's BPM! QS = true; // set Quantified Self flag // QS FLAG IS NOT CLEARED INSIDE THIS ISR pulse = BPM; } } if (Signal < thresh && Pulse == true) { // when the values are going down, the beat is over digitalWrite(blinkPin,LOW); // turn off pin 13 LED Pulse = false; // reset the Pulse flag so we can do it again amp = P - T; // get amplitude of the pulse wave thresh = amp/2 + T; // set thresh at 50% of the amplitude P = thresh; // reset these for next time T = thresh; } if (N > 2500) { // if 2.5 seconds go by without a beat thresh = 512; // set thresh default P = 512; // set P default T = 512; // set T default lastBeatTime = sampleCounter; // bring the lastBeatTime up to date firstBeat = true; // set these to avoid noise secondBeat = false; // when we get the heartbeat back } sei(); // enable interrupts when youre done! }// end isr void esp_8266() { // TCP connection AT+CIPSTART=4,"TCP","184.106.153.149",80 String cmd = "AT+CIPSTART=4,"TCP",""; cmd += "184.106.153.149"; // api.thingspeak.com cmd += "",80"; ser.println(cmd); Serial.println(cmd); if(ser.find("Error")) { Serial.println("AT+CIPSTART error"); return; } // prepare GET string GET https://api.thingspeak.com/update?api_key=LHAG4NSIYJ5UWS6U&field1=0rnrn String getStr = "GET /update?api_key="; getStr += apiKey; getStr +="&field1="; getStr +=String(temp); getStr +="&field2="; getStr +=String(pulse); getStr += "rnrn"; // send data length cmd = "AT+CIPSEND=4,"; cmd += String(getStr.length()); ser.println(cmd); Serial.println(cmd); delay(1000); ser.print(getStr); Serial.println(getStr); //thingspeak needs 15 sec delay between updates delay(3000); } void read_temp() { int temp_val = analogRead(A1); float mv = (temp_val/1024.0)*5000; float cel = mv/10; temp = (cel*9)/5 + 32; } ###
Circuit Diagrams
Project Video
Filed Under: Electronic Projects, IoT
Filed Under: Electronic Projects, IoT
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.