[ASK] Issue with reading speed of Motion Sensor with LCD+Temperature sensor

Hi everyone I want to seek a solution or suggestion on how to rectify my issue, so what I wanted to do was:

  1. The LCD ( 20 x 4 Characters ) keeps showing the reading of temperature and humidity every time (Using the DHT22 Temperature Sensor Module)
  2. When the motion is detected, the result is shown in LCD with the string “Motion Detected” and when the motion is ended the result is also shown in LCD with the string “Motion ended” ( Using the HC - SR501 Motion Sensor)
  3. I’m using Arduino Mega as my main microcontroller
  4. I used the motion sensor in the H mode ( Hold/Repeat/Retriggering In this position the HC-SR501 will continue to output a HIGH signal as long as it continues to detect movement.)
  5. I put the potentiometer for the time delay in the smallest position and the distance potentiometer also in the smallest position

but I was facing this problem:

  1. The reading of the motion is not instantaneous when I wave my hand in front of the lens of motion Sensor then after few seconds( it takes sometimes 1 second, sometimes 3 seconds, and sometimes can be longer than 5 seconds) the result then will be displayed on the LCD and an LED will turn on

The following code is the code that currently I used right now:

#include <LiquidCrystal.h> // Library for LCD
#include <dht.h>  // Library for DHT22 for Arduino Mega
#define dataPin 13 // Defines DHT22 pin number to which the sensor is connected
dht DHT; // Creats a DHT object
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int LED1 = 22;                // choose the pin for the LED
int inputPin = 8;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

void setup() {
pinMode(LED1, OUTPUT);      // declare LED as output
pinMode(inputPin, INPUT);     // declare sensor as input
// set up the LCD's number of columns and rows:
lcd.begin(20,4);
// Print a message to the LCD.
lcd.print("Smart Home system");
delay(500);
}
void loop() {
val = digitalRead(inputPin);  // read input value
int readData = DHT.read22(dataPin); // DHT22/AM2302
float t = DHT.temperature; // Gets the values of the temperature
float h = DHT.humidity; // Gets the values of the humidity
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
lcd.print("Temp = ");
lcd.print(t);
lcd.print((char)223);
lcd.print(" C ");
lcd.setCursor(0, 2);
lcd.print("Humid = ");
lcd.print(h);
lcd.print(" % ");
//delay(500); // Delays 2 secods
 if (val == HIGH)  // check if the input is HIGH
{   if (pirState == LOW) 
{   digitalWrite(LED1, HIGH);  // turn LED ON 
   lcd.setCursor(0,3);
   lcd.print("Motion detected!"); // print on output change
   pirState = HIGH;
 }
} 
else 
{
 if (pirState == HIGH)
{  digitalWrite(LED1, LOW); // turn LED OFF
 lcd.setCursor(0,3);
 lcd.print("                    "); 
 lcd.setCursor(0,3);
  lcd.print("Motion ended!");  // print on output change
  pirState = LOW;
 }
}

}

In the attachment below also I put my current arrangement of the motion sensor and LCD please do have a look

  1. Surround your code with "code tags" so it can be easily readable

  2. there's a pot to set the ON time after motion detected, set it to the minimum

  3. wait some seconds (30 to 60) after power up so PIR can settle

  4. move away from sensor ant test movement, maybe you are too close

geologic:

  1. Surround your code with "code tags" so it can be easily readable

  2. there's a pot to set the ON time after motion detected, set it to the minimum

  3. wait some seconds (30 to 60) after power-up so PIR can settle

  4. move away from sensor ant test movement, maybe you are too close

  1. Yes I have done it

  2. I did put the time potentiometer in the smallest time and the distance potentiometer in the smallest position

  3. Now I tried again and I observed that every time that after the motion sensor detected the movement and the LED turned on ( because the output of the motion sensor become high), it takes sometimes (shortest is around 10 seconds) for the motion sensor to be able to read the next movement. Is it this condition is a normal condition? as you mentioned that it has the power up time around 30 seconds to 60 seconds.

  4. yes I just test my motion sensor with my hand movement ( I waved my hand in front of the sensor) and now it's almost working but I have a new problem that I mentioned in the number 3 above