Rahul Bhatiarishi arora
Published © GPL3+

motion, distance and temperature detector

in this project, when motion will detected ultrasonic sensor will be activated and if motion is not detected temperature will be detected.

IntermediateProtip2,899
motion, distance and temperature detector

Things used in this project

Schematics

motion, ultrasonic and temperature detector

Code

motion, ultrasonic and temperature detector code

Java
int sensor=13;
int sensor_value;
int trigPin=12;
int echoPin=11;
long duration;
int distance;
float temp;
float ftemp;
int tempPin=0;
void setup() {
  // put your setup code here, to run once:
pinMode(sensor,INPUT);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(10,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
sensor_value=digitalRead(sensor);
Serial.println(sensor_value);
if(sensor_value==0)
{
  digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration= pulseIn(echoPin,HIGH);
distance=duration*(0.034/2);
Serial.print("Distance:");
Serial.println(distance);
digitalWrite(10,HIGH);
delay(1000);
  }
  else 
  { 
    temp=analogRead(tempPin);
temp=temp*0.48828125;
ftemp=temp+32;
Serial.print("temperature:");
Serial.print(temp);
Serial.print("*c");
Serial.println();
Serial.print("temperature:");
Serial.print(ftemp);
Serial.print("*f");
Serial.println();
digitalWrite(10,LOW);
if(temp>=24&&temp<25)
{ digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(2,HIGH);
delay(1000);
}
else if(temp>=25&&temp<26)
{
  digitalWrite(2,LOW);
  digitalWrite(4,LOW);
 digitalWrite(3,HIGH);
 delay(1000);
 }
 else if(temp>=23&&temp<24)
 {
  digitalWrite(2,LOW);
  digitalWrite(3,LOW);
 digitalWrite(4,HIGH);
 delay(1000);
  }
    }
}

Credits

Rahul Bhatia

Rahul Bhatia

8 projects • 0 followers
Btech student 3rd year
rishi arora

rishi arora

11 projects • 4 followers

Comments