BLYNK
HOME       πŸ“² GETTING STARTED       πŸ“— DOCS       ❓HELP CENTER       πŸ‘‰ SKETCH BUILDER

Problem with PIR sensor (multiple sensors)

Hi,
I have problem with my project. My project is for home automation and I have 3 sensors PIR, LDR (photoresistor) and MAX30100. Everything works almost flawlessly, but problem is that, when I try MAX30100 first it works, also it works when LDR is on. But when I try PIR sensor, MAX30100 is not working anymore. I am beginner with arduino. Can someone help me? Thanks in advance.

Specification:

  • Arduino UNO R3(clone)
  • USB connection
/***************** Librarys *******************/
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(0, 1); //RX, TX
#include <BlynkSimpleStream.h>

/**************** Connection ******************/
#define BLYNK_SERIAL DebugSerial
#define ldrPin A0
/****************** Auth *************/
char auth[] = "xxxxxxxxxxxxxxxx";

/********* waiting period ***********************/ 
#define REPORTING_PERIOD_MS     1000
#define REPORTING_PERIOD_LS     5000


/**********************/
PulseOximeter pox;
uint32_t tsLastReport1 = 0;
uint32_t tsLastReport2 = 0;
int pirPin = 8;
int ledB =6;
int ledY =7;
int ledG =5;
int button1;
int button2;

WidgetLCD lcd(V1); 
BLYNK_WRITE(V0) {button1 = param.asInt();}
BLYNK_WRITE(V3) {button2 = param.asInt();}



void setup()
{
  DebugSerial.begin(9600);
  Serial.begin(9600);
  Blynk.begin(Serial,auth); //Session begins here
  pinMode(ledG, OUTPUT);
  pinMode(pirPin,INPUT);
  pox.setIRLedCurrent(MAX30100_LED_CURR_24MA);
  pox.begin();
}

      
void loop()
{
      
    Blynk.run(); 
    pox.update();
/***************************MAX30100***********************/
  if (millis() - tsLastReport1 > REPORTING_PERIOD_MS)
  {
    Blynk.virtualWrite(V4,pox.getHeartRate());
    Blynk.virtualWrite(V5,pox.getSpO2());
    tsLastReport1 = millis();
  }


  /***********************LDR******************/
   if (button1 == 1){
   if (millis() - tsLastReport2 > REPORTING_PERIOD_LS) {
   int ldrStatus = analogRead(ldrPin);
   if (ldrStatus <=300) {
    digitalWrite(ledB, HIGH);
    digitalWrite(ledY, HIGH);    
   } else {
    digitalWrite(ledB, LOW);
    digitalWrite(ledY, LOW);         
   }
   tsLastReport2 = millis();}}
   
/****************************PIR sensor*******************/
   if(button2 == 1){
    int pirValue = digitalRead(pirPin);
    if (pirValue){
      lcd.print(0,0,"POHYB");
      digitalWrite(ledG, HIGH);
    }else {
      lcd.print(0,0,"BEZ POHYBU");
      digitalWrite(ledG,LOW);
    }}
  }

You should read this:

Pete.

1 Like

Everything works as it should, thanks for advice.