Can any one help me? I'm new to Arduino ,my project is rfid (RC522) based SpO2 checking using MAX30100 for employees in this covid19.I am facing issue in my code.when I put rfid in loop and then max30100 code ,rfid works good,but oximeter reads only 0.when I put oximeter code first in void loop,it works well but rfid not read.please help to solve the issueIm new to Arduino
#include <SPI.h>
#include <MFRC522.h>
#include <MAX30100_PulseOximeter.h>
#define SS_PIN 10 //RX slave select
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define Sec 1000
int level;
PulseOximeter pox;
uint32_t tsLastReport = 0;
byte card_ID[4]; //card UID size 4byte
byte Name1[4]={0x47,0x08,0x15,0x4F};//first UID card
byte Name2[4]={0x7A,0x9F,0x69,0x7F};//second UID card
int NumbCard[2];//this array content the number of cards. in my case i have just two cards.
int j=0;
int const RedLed=6;
int const GreenLed=5;
int const Buzzer=8;
const int trigPin = 5;
const int echoPin = 6;
long duration;
int distance;
String Name;//user name
long Number;//user number
int n ;//The number of card you want to detect (optional) void onBeat()
void setup() {
Serial.begin(9600);
pox.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
display.setTextColor(WHITE); // or BLACK);
display.setTextSize(2);
display.setCursor(10,0);
display.print(" NO LOVE ");
display.display(); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("CLEARSHEET"); // clears starting at row 1
Serial.println("LABEL,Date,Time,Name,Number");// make four columns (Date,Time,[Name:"user name"]line 48 & 52,[Number:"user number"]line 49 & 53)
pinMode(RedLed,OUTPUT);
pinMode(GreenLed,OUTPUT);
pinMode(Buzzer,OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0340 / 2;
// Serial.println("Distance");
//Serial.println(distance);
if (distance <= 15)
digitalWrite(Buzzer,HIGH);
delay(30);
digitalWrite(Buzzer,LOW);
//look for new card
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;//got to start of loop if there is no card present
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;//if read card serial(0) returns 1, the uid struct contians the ID of the read card.
}
for (byte i = 0; i < mfrc522.uid.size; i++) {
card_ID[i]=mfrc522.uid.uidByte[i];
if(card_ID[i]==Name1[i]){
Name=" SRINATH ";//user name
Number=18106096;
display.clearDisplay();
display.setTextColor(WHITE); // or BLACK);
display.setTextSize(2);
display.setCursor(0,0);
display.print(Name);
display.display();
j=0;//first number in the NumbCard array : NumbCard[j]
}
else if(card_ID[i]==Name2[i]){
Name=" UDHAYA ";
onBeat();//user name
delay(10000);
Number=87654496;
display.clearDisplay(); display.setTextColor(WHITE); // or BLACK);
display.setTextSize(2);
display.setCursor(0,0);
display.print(Name);
display.display();//user number
j=1;//Second number in the NumbCard array : NumbCard[j]
}
else{
digitalWrite(GreenLed,LOW);
digitalWrite(RedLed,HIGH);
goto cont;//go directly to line 85
}
}
if(NumbCard[j] == 1){//to check if the card already detect
//if you want to use LCD
// Serial.println("Already Exist");
}
else{
NumbCard[j] = 1;//put 1 in the NumbCard array : NumbCard[j]={1,1} to let the arduino know if the card was detecting
n++;//(optional)
Serial.print("DATA,DATE,TIME," + Name);//send the Name to excel
Serial.print(",");
Serial.println(Number); //send the Number to excel
digitalWrite(GreenLed,HIGH);
digitalWrite(RedLed,LOW);
digitalWrite(Buzzer,HIGH);
delay(30);
digitalWrite(Buzzer,LOW);
Serial.println("SAVEWORKBOOKAS,Names/WorkNames");
}
delay(1000);
cont:
delay(2000);
digitalWrite(GreenLed,LOW);
digitalWrite(RedLed,LOW);
//if you want to close the Excel when all card had detected and save Excel file in Names Folder. in my case i have just 2 card (optional)
//if(n==2){
// Serial.println("FORCEEXCELQUIT");
// }
}
void onBeat()
{
if (!pox.begin()) {
Serial.println("FAILED");
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(1);
display.setCursor(0, 0);
display.println("FAILED");
display.display();
for(;;);
}
else {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(1);
display.setCursor(0, 0);
display.println("SUCCESS");
display.display();
Serial.println("SUCCESS");
}
onlevel();
}
void onlevel()
{
Serial.println("Beat!");
display.display();
pox.update();
if (millis() - tsLastReport > Sec){}
Serial.print("Oxygen Percent:");
Serial.print(pox.getSpO2());
Serial.println("\n");
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(1);
display.setCursor(0, 0);
display.println("Spo2");
[color=#ffffff]display[/color][color=#ffffff].[/color][color=#ffffff]setTextSize[/color][color=#ffffff]([/color][color=#d8b100]1[/color][color=#ffffff])[/color][color=#ffffff];[/color]
[color=#ffffff]display[/color][color=#ffffff].[/color][color=#ffffff]setTextColor[/color][color=#ffffff]([/color][color=#d8b100]1[/color][color=#ffffff])[/color][color=#ffffff];[/color]
[color=#ffffff]display[/color][color=#ffffff].[/color][color=#ffffff]setCursor[/color][color=#ffffff]([/color][color=#d8b100]0[/color][color=#ffffff],[/color][color=#d8b100]30[/color][color=#ffffff])[/color][color=#ffffff];[/color]
[color=#ffffff]display[/color][color=#ffffff].[/color][color=#ffffff]println[/color][color=#ffffff]([/color][color=#ffffff]pox[/color][color=#ffffff].[/color][color=#ffffff]getSpO2[/color][color=#ffffff]([/color][color=#ffffff])[/color][color=#ffffff])[/color][color=#ffffff];[/color]
[color=#ffffff]display[/color][color=#ffffff].[/color][color=#ffffff]display[/color][color=#ffffff]([/color][color=#ffffff])[/color][color=#ffffff];[/color]
[color=#ffffff]tsLastReport[/color] [color=#2dbda4]=[/color] [color=#ffffff]millis[/color][color=#ffffff]([/color][color=#ffffff])[/color][color=#ffffff];[/color]
[color=#ffffff]}[/color]