problem stability of reading sensors

Hello …
an introduction :
I am doing a small project using many sensors, the sound sensor that acts as a noise detector and a heartbeat. Ky039 is a sensor that measures the heart rate, PIR snsor sensor, temperature sensor LM35, and using Arduino, all input readings are displayed through the I2C LCD , Each sensor has a condition, if the condition is met; PIN11 is high, so the person close to it can be warned.
the problem :
When I try each sensor alone and display it on the lcd i2c screen, the sensors work fine, but when I combine these sensors together and divide them into the lcd i2c display using the cursor; the sensor is disturbing the readings and does not react quickly with the change in readings, In the response of PIN 11, especially here the sound sensor that acts as a db meter, which is delayed in the display while the screen is running at about 4 sec from the rest of the sensors (lm35 & ky039 )and displays its readings oscillately and displays 0.00 and 49.00 and this imbalance would not happen if that The sensor alone is connected to the Arduino, but when connected to the project I encounter this The whole … I do not know why? I have tried it a lot, please help to modify the code and what do you recommend thank you …
You will find the video and code below

CODE:

/* NOTE : That the x = PIR sensor =(12,INPUT); …*/

[
#include<Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C addressint sensorPin = A2;

int sirenPin = 11;
int tempPin = A1;
int sensorPin = A2;
double alpha=0.75;
int period=20;
double refresh=0.0;
double change = 0.0;
double minval = 0.0;
int beat;
int rate=((beat/10)-4);
const int samplewindow = 50 ;
unsigned int sample ;

boolean x ;
float db ;

void setup() {

// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd. setCursor (4, 0);
lcd.print(" Hello ! “);
lcd.setCursor (2, 1);
lcd.print(” World , :slight_smile: “);
delay (5000);
lcd.clear () ;
lcd.setCursor (3, 0);
lcd.print (” Graduate “);
lcd.setCursor (3, 1);
lcd.print (” Project. ");
delay (5000);
lcd.clear();
pinMode (db , INPUT );
pinMode (12 , INPUT );
pinMode (sirenPin , OUTPUT );

}

void loop() {
// put your main code here, to run repeatedly:

Serial.println(db);
delay (500);
float reading= analogRead (A1);
float temp = reading * (5/1023.0)100; / درجة سيليســـيوســيـــــة*/

delay (1000);

static double oldValue=0;
static double oldrefresh=0;

beat=analogRead(A2);

double value=alpha*oldValue+(0-alpha)*beat;
refresh=value-oldValue;

rate=((beat/10)-4);
oldValue=value;
oldrefresh=refresh;
lcd.setCursor (0, 0);
lcd.print (“Temp”);
lcd.setCursor (0, 1);
lcd.print(temp);
lcd.setCursor (4, 1);
lcd.print(“c”);
lcd.setCursor (6, 0);
lcd.print (“Hbpm”);
lcd.setCursor (7, 1);
lcd.print(rate);
delay (period * 100);
lcd.setCursor (11, 0);
lcd.print (“S.am”);
lcd.setCursor (10, 1);
lcd.print(db);
delay (100);

unsigned long startMillis = millis ();
float peaktopeak = 0;

unsigned int signalMax = 0 ;
unsigned int signalMin = 1024 ;

while (millis ()- startMillis < samplewindow )
{
sample= analogRead(A0);
if (sample<1024)
{
if (sample>signalMax)
{
signalMax = sample ;
}
else if (sample < signalMin )
{
signalMin = sample ;
}
}
}
peaktopeak = signalMax - signalMin ;
float db = map (peaktopeak,20,900,49.5,90);
lcd.setCursor ( 0,0);
lcd.print (db);
delay (100);

if (db > 52){
digitalWrite (11,HIGH);
delay (2000) ;
}
else {(db<52);
digitalWrite(11,LOW);
lcd.clear();
lcd.setCursor (0, 0);
lcd.print (“Temp”);
lcd.setCursor (0, 1);
lcd.print(temp);
lcd.setCursor (4, 1);
lcd.print(“c”);
lcd.setCursor (6, 0);
lcd.print (“Hbpm”);
lcd.setCursor (7, 1);
lcd.print(rate);
delay (period * 100);
lcd.setCursor (11, 0);
lcd.print (“S.am”);
lcd.setCursor (10, 1);
lcd.print(db);
delay (100);

}

x=digitalRead (12);

if (x==1) {
lcd.clear();
digitalWrite(11,HIGH);
lcd.setCursor(4,0);
lcd.print("There is ");
lcd.setCursor(4,1);
lcd.print(“Motion”);
delay (3000);

}
else
(x==0);
{
digitalWrite(11,LOW);
lcd.clear();
lcd.setCursor (0, 0);
lcd.print (“Temp”);
lcd.setCursor (0, 1);
lcd.print(temp);
lcd.setCursor (4, 1);
lcd.print(“c”);
lcd.setCursor (6, 0);
lcd.print (“Hbpm”);
lcd.setCursor (7, 1);
lcd.print(rate);
delay (period * 100);
lcd.setCursor (11, 0);
lcd.print (“S.am”);
lcd.setCursor (10, 1);
lcd.print(db);
delay (100);
}
if (temp >= 38.5){
digitalWrite(11,HIGH);
lcd.clear();
lcd.setCursor(4,0);
lcd.print(" Warning!!! ");
lcd.setCursor(2,1);
lcd.print("temp = " );
lcd.setCursor(8,1);
lcd.print(temp );

delay (1000);
}
else {
(temp < 38.5);

digitalWrite(11,LOW);
lcd.clear();
lcd.setCursor (0, 0);
lcd.print (“Temp”);
lcd.setCursor (0, 1);
lcd.print(temp);
lcd.setCursor (4, 1);
lcd.print(“c”);
lcd.setCursor (6, 0);
lcd.print (“Hbpm”);
lcd.setCursor (7, 1);
lcd.print(rate);
delay (period * 100);
lcd.setCursor (11, 0);
lcd.print (“S.am”);
lcd.setCursor (10, 1);
lcd.print(db);
delay (100);

}

if (rate <=68){
digitalWrite(11,HIGH);
lcd.clear();
lcd.setCursor(4,0);
lcd.print(" Warning ");
delay (1000);
}
else {
(rate > 68);
digitalWrite(11,LOW);

lcd.clear();
lcd.setCursor (0, 0);
lcd.print (“Temp”);
lcd.setCursor (0, 1);
lcd.print(temp);
lcd.setCursor (4, 1);
lcd.print(“c”);
lcd.setCursor (6, 0);
lcd.print (“Hbpm”);
lcd.setCursor (7, 1);
lcd.print(rate);
delay (period * 100);
lcd.setCursor (11, 0);
lcd.print (“S.am”);
lcd.setCursor (10, 1);
lcd.print(db);
delay (100);

}
}

]
… …

VIDEO :
vedio :

Next time, use [ code ] tags. The forum software eats some of your code if you don't.

pinMode (db , INPUT );
pinMode (12 , INPUT );
pinMode (sirenPin , OUTPUT );

You gave several pins names. Why doesn't 12 get a name? I think it needs a name so that it can feel good about itself.

delay (500);

That's going to slow things down.

float reading= analogRead (A1);

You gave this pin a name earlier. Don't forget that. Always use the name you gave it.

delay (1000);

That's going to make it even slower.

delay (100);

Still slow.

delay (2000) ;

Getting slower

delay (3000);

We have a winner!

For the Arduino, a millisecond is a long time. It can do thousands of different things in a millisecond. Delays like this are like asking you to take a 10-year break before you graduate.