can you guys help me how to combine those sensor by using only one arduino uno for my final year project as i have tried it many times but still did not get any output
this is the code that i have tried before
////////////
#include <NewPing.h>
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
int echoPin = 10; // Echo Pin of the ultrasonic sensor
int trigPin = 9; // Trigger pin ofthe ultrasonic sensor
int pir = 3; // PIR sensor Pin
int led = 7;
int distance = 0; // Default distance measured by ultrasonic sensor
// the time when the sensor outputs a low impulse
long unsigned int lowIn;
// the amount of milliseconds the sensor has to be low
// before we assume all motion has stopped
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int calibrationTime = 30;
// Instance creation for the New ping Library
NewPing sonar(trigPin, echoPin, MAX_DISTANCE);
void setup() {
Serial.begin(9600);
pinMode(pir, INPUT);
pinMode(led, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// activation of the pull up resistor for the PIR pin
digitalWrite(pir, HIGH);
// give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for (int i = 0; i < calibrationTime; i++) {
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}
////////////////////////////
//LOOP
void loop() {
if(digitalRead(pir) == HIGH){
digitalWrite(led, HIGH); //the led visualizes the sensors output pin state
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(10);
}
takeLowTime = true;
}
if(digitalRead(pir) == LOW){
digitalWrite(led, LOW); //the led visualizes the sensors output pin state
if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
Serial.print("motion ended at "); //output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(10);
}
}
if(digitalRead(trigPin) == HIGH){
long duration, distance;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration=pulseIn(echoPin, HIGH);
distance =(duration/2)/29.1;
Serial.print(distance);
Serial.println("CM");
delay(10);
if((distance<=5))
{
digitalWrite(led, HIGH);
}
else if(distance>2)
{
digitalWrite(led, LOW);
}
}
}