Translate

Monitor BPM Wireless NRF24L01 Multiple Transmitter Receiver MAX30100 Server Thingspeak

Monitor BPM Wireless NRF24L01 Multiple Transmitter Receiver MAX30100 Server Thingspeak


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat yang dapat berfungsi sebagai penghitung Bpm pada 2 alat yang berbeda, alat ini menggunakan sistem wireless dengan 2 transmitter dan 1 receiver. untuk komunikasi wireless ini dengan menggunakan modul NRF24L01 pada 3 buah device tersebut. untuk sensor Bpmnya menggunakan MAX30100. untuk lebih jelasnya berikut adalah koding skemanya.



a. Skema Transmitter - Receiver



2. Program Arduino TRANSMITTER 1

#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

LiquidCrystal_I2C lcd(0x27,16,2); //library lcd

MAX30100* pulseOxymeter;   //library

float sensorValue;
float tegangan;
int bpmku;
int counter;
float spo;
float bpm;
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
int cacah;
 
PulseOximeter pox;

uint32_t tsLastReport = 0;
String hrData = "";

void onBeatDetected()
{
//    Serial.println("Beat!");
}

RF24 radio(9, 10); // CE, CSN

const uint64_t pipe = 0xE8E8F0F0E1LL;
float dataku[4];
float b;

void setup(void) {
lcd.begin();
lcd.clear();
lcd.noCursor();

Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);

pulseOxymeter = new MAX30100();
 
if (!pox.begin()) {
 //Serial.println("FAILED");
  for(;;);
 } else {
 //Serial.println("SUCCESS");
}
 
  pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
  pox.setOnBeatDetectedCallback(onBeatDetected);

}

void loop(void){

pox.update();    
b = pox.getHeartRate();
//s = pox.getSpO2();

lcd.setCursor(0,0);
lcd.print("BPM1:");
lcd.print(b,1);
lcd.print("   ");

dataku[0] = 231;  // code to identify the transmitter. 
dataku[1] = b; 
radio.write( dataku, sizeof(dataku) );
 
}



3. Program Arduino TRANSMITTER 2

#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

LiquidCrystal_I2C lcd(0x27,16,2); //library lcd

MAX30100* pulseOxymeter;   //library

float sensorValue;
float tegangan;
int bpmku;
int counter;
float spo;
float bpm;
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
int cacah;
float b,s,t;
float dataku[4];
 
PulseOximeter pox;

uint32_t tsLastReport = 0;
String hrData = "";

void onBeatDetected()
{
//    Serial.println("Beat!");
}

RF24 radio(9, 10); // CE, CSN

const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void) {
lcd.begin();
lcd.clear();
lcd.noCursor();

Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);

pulseOxymeter = new MAX30100();
 
if (!pox.begin()) {
 //Serial.println("FAILED");
  for(;;);
 } else {
 //Serial.println("SUCCESS");
}
 
  pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
  pox.setOnBeatDetectedCallback(onBeatDetected);

}

void loop(void){

pox.update();    
s = pox.getHeartRate();

lcd.setCursor(0,0);
lcd.print("BPM2:");
lcd.print(s,1);
lcd.print("   ");

dataku[0] = 434;  // code to identify the transmitter. 
dataku[1] = s; 
radio.write( dataku, sizeof(dataku) );
 
}



4. Program Arduino Receiver

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2); //library lcd

//Replace your wifi credentials here
const char* ssid     = "HOTSPOTHPKU";
const char* password = "123456789";

String apiKey = "UYT689JHVVNMI9UV";     //  Enter your Write API key from ThingSpeak
const char* resource = "/update?api_key=";
const char* server = "api.thingspeak.com";

int msg[1];
float b,s,t;
float data1; 
float data2; 
float dataku[4];
int cacah;

unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;
 
RF24 radio(D4,D3);

const uint64_t pipe = 0xE8E8F0F0E1LL;

WiFiClient  client;

void setup(){
 
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();

// Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

lcd.begin();
lcd.clear();
lcd.noCursor();
lcd.setCursor(0,0);
lcd.print("BPM1:");

}

void loop(){

if (radio.available()) { 
  
radio.read(dataku, sizeof(dataku));  
Serial.print(dataku[0]);
Serial.print(" : ");
Serial.println(dataku[1]);

if(dataku[0] == 231.0) // header
{
  data1 = dataku[1]; 
  lcd.setCursor(0,0);
  lcd.print("BPM1:");
  lcd.print(data1,1);
  lcd.print("   ");
}

if(dataku[0] == 434.0) // header
{
  data2 = dataku[1]; 
  lcd.setCursor(0,1);
  lcd.print("BPM2:");
  lcd.print(data2,1);
  lcd.print("   ");
}
 
}

if(cacah > 500){
cacah = 0;  
kirim();  
}

cacah++;
delay(10);      
}

void kirim(){
  
if (client.connect(server,80))   //   "184.106.153.149" or api.thingspeak.com
{
                            
                             String postStr = apiKey;
                             postStr +="&field1=";
                             postStr += String(data1);
                             postStr += "\r\n\r\n";

                             client.print(String("GET ") + resource + apiKey + "&field1=" + data1 + "&field2=" + data2 + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
                                       
                             client.print("Host: api.thingspeak.com\n");
                             client.print("Connection: close\n");
                             client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
                             client.print("Content-Type: application/x-www-form-urlencoded\n");
                             client.print("Content-Length: ");
                             client.print(postStr.length());
                             client.print("\n\n");
                             client.print(postStr);
                             
                             Serial.println(". Send to Thingspeak.");
                        }
                        
          client.stop();

          Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
  delay(5000);
  
}



5. VIDEO HASILNYA




No comments:

Post a Comment