Heart Beat Monitoring over Internet using Arduino and ThingSpeak - Internet of Things

Heart Beat Monitoring over Internet using Arduino and ThingSpeak

Heart Beat Monitoring over Internet using Arduino and ThingSpeak
In this project we are going to make a Heart Beat Detection and Monitoring System using Arduinothat will detect the heart beat using the Pulse Sensor and will show the readings in BPM (Beats Per Minute) on the LCD connected to it. It will also send the readings to ThingSpeak server using the Wi-Fi module ESP8266, so that Heart Beats can be monitored from anywhere in the world over the internet. ThingSpeak is a great source for displaying the data online and you can access the data from ThingSpeak at any time and at any place.
We have previously built a simple Heart Beat Monitor without showing data on Internet. This time we have used ThingSpeak to monitor the system over internet, and this will put this project into IOT category.

Components Required:
·         Pulse sensor
·         Wi-Fi module ESP8266
·         Arduino Uno
·         LCD
·         Bread Board
·         10k potentiometer
·         1k resistors
·         220 ohm resistors
·         LED
·         Connecting wires

Circuit Diagram and Explanation:
First of all we will connect the ESP8266 with the Arduino. ESP8266 runs on 3.3V and if you will give it 5V from the Arduino then it wont work properly and it may get damage. Connect the VCC and the CH_PD to the 3.3V pin of Arduino. The RX pin of ESP8266 works on 3.3V and it will not communicate with the Arduino when we will connect it directly to the Arduino. So, we will have to make a voltage divider for it which will convert the 5V into 3.3V. This can be done by connecting three resistors in series like we did in the circuit. Connect the TX pin of the ESP8266 to the pin 9 of the Arduino and the RX pin of the ESP8266 to the pin 10 of Arduino through the resistors.
ESP8266 Wi-Fi module gives your projects access to Wi-Fi or internet. It is a very cheap device and make your projects very powerful. It can communicate with any microcontroller and it is the most leading devices in the IOT platform. Learn more about using ESP8266 with Arduino here.

Then connect the Pulse Sensor with the Arduino. The connections of the pulse sensor are very easy. Pulse sensor has three pins. Connect 5V and the ground pin of the pulse sensor to the 5V and the ground of the Arduino and the signal pin to the A0 of Arduino.
Then connect the LED to pin 13 of Arduino. You do not have to connect a resistor with because the Arduino has built in resistor at pin 13.
In last, we will connect LCD with the Arduino. The connections of the LCD are as follows
·         Connect pin 1 (VEE) to the ground.
·         Connect pin 2 (VDD or VCC) to the 5V.
·         Connect pin 3 (V0) to the middle pin of the 10K potentiometer and connect the other two ends of the potentiometer to the VCC and the GND. The potentiometer is used to control the screen contrast of the LCD. Potentiometer of values other than 10K will work too.
·         Connect pin 4 (RS) to the pin 12 of the Arduino.
·         Connect pin 5 (Read/Write) to the ground of Arduino. This pin is not often used so we will connect it to the ground.
·         Connect pin 6 (E) to the pin 11 of the Arduino. The RS and E pin are the control pins which are used to send data and characters.
·         The following four pins are data pins which are used to communicate with the Arduino.
Connect pin 11 (D4) to pin 5 of Arduino.
Connect pin 12 (D5) to pin 4 of Arduino.
Connect pin 13 (D6) to pin 3 of Arduino.
Connect pin 14 (D7) to pin 2 of Arduino.
·         Connect pin 15 to the VCC through the 220 ohm resistor. The resistor will be used to set the back light brightness. Larger values will make the back light much more darker.
·         Connect pin 16 to the Ground.

ThingSpeak Setup:
ThingSpeak provides very good tool for IoT based projects. By using ThingSpeak site, we can monitor our data and control our system over the Internet, using the Channels and webpages provided by ThingSpeak. ThingSpeak Collects the data from the sensors, Analyze and Visualize the data and Acts by triggering a reaction. We have previously used ThingSpeak in Weather station project using Raspberry Pi and using Arduino, check them to learn more about ThingSpeak. Here we are briefly explaining to use ThingSpeak for this IoT Heart Beat Monitoring Project.
First of all, user needs to Create a Account on ThingSpeak.com, then Sign In and click on Get Started.
After creating an account, go to channels and create a new channel. Now write the name of the Channel and name of the Fields. Also tick the check box for Make Publicoption below in the form and finally Save the Channel. Now your new channel has been created.

After this go to API keys and copy your Write API key. You will need this in the code. Check the Full Code at the end.

Working Explanation:
First we need to attach the Pulse Sensor to any organ of body where it can detect the pulse easily like finger, check the video below. Then the Pulse Sensor will measure the change in volume of blood, which occurs when every time heart pumps blood in the body. This change in volume of blood causes a change in the light intensity through that organ. The Arduino will then convert this change into the heart beat per minute (BPM). The LED connected at pin 13 will also blink according the Heart Beat.
The ESP8266 will then communicate with the Arduino and will send the data to ThingSpeak. The ESP8266 will connect the network of your router that you will provide in the code and will send the data of the sensor online. This data on the ThingSpeak will be shown in a Graph form showing the past readings too and can be accessed from anywhere over internet. The LCD connected will also show you the BPM.
 

Code Explanation:
First of all, add the libraries. Software serial library is for enabling the RX and TX at pin 9 and pin 10. The default RX and TX pins of Arduino are pin 0 and 1 but if you want to enable it at other pins that you will have to use the software serial library. Then initialize the liquid crystal library (LiquidCrystal.h)and declare the pins at which you have connected the LCD.
#include <SoftwareSerial.h>
#define DEBUG true
SoftwareSerial esp8266(9,10);
#include <LiquidCrystal.h>
#include <stdlib.h>
LiquidCrystal lcd(12,11,5,4,3,2);

Enter the Wi-Fi name, password and IP address of ESP8266. Then enter the API key from ThingSpeak that you saved earlier.
#define SSID "Your Wifi Name"
#define PASS "Your Wifi Password"
#define IP "184.106.153.149"
String msg = "GET /update?key=9YS21NU0HY5YS1IKU";

The following code will start the LCD and will set the baud rate. Enter the baud rate according to your ESP8266. Every ESP8266 has its own baud rate. Some have baud rate of 9600, some have 115200 or other.
void setup()
{
  lcd.begin(16, 2);
  lcd.print("circuitdigest.com");
  delay(100);
  lcd.setCursor(0,1);
  lcd.print("Connecting...");
  Serial.begin(9600); //or use default 115200.
  esp8266.begin(9600);
  Serial.println("AT");
  esp8266.println("AT");
  delay(5000);
  if(esp8266.find("OK")){
    connectWiFi();
  }
  interruptSetup();
}

Following function void updatebeat() will send the data at the IP address that we have entered and also will set the data in the field we set for heart beat.
void updatebeat(){
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += IP;
  cmd += "\",80";
  Serial.println(cmd);
  esp8266.println(cmd);
  delay(2000);
  if(esp8266.find("Error")){
    return;
  }
  cmd = msg ;
  cmd += "&field1=";  
  cmd += BPM;
  ..... .....
  ...... .....

The following code will connect the ESP8266 with the Wi-Fi network that you entered earlier and then it will use this network to send the data to the ThingSpeak.
boolean connectWiFi(){
  Serial.println("AT+CWMODE=1");
  esp8266.println("AT+CWMODE=1");
  delay(2000);
  String cmd="AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  .... .....
  ..... .....

The following code will read the sensor and will convert the output of the sensor into heart beat per minute (BPM). It will also blink the LED connected at the pin 13 according to the BPM.
ISR(TIMER2_COMPA_vect){
  cli();
  Signal = analogRead(pulsePin);
  sampleCounter += 2;
  int N = sampleCounter - lastBeatTime;
  if(Signal < thresh && N > (IBI/5)*3){
    if (Signal < T){
      T = Signal;
      ... ....
       ...... ..


  Demo & Code


Heart Beat Monitoring over Internet using Arduino and ThingSpeak Heart Beat Monitoring over Internet using Arduino and ThingSpeak Reviewed by XXX on สิงหาคม 27, 2560 Rating: 5

ไม่มีความคิดเห็น