Sanyam Chugh
Published

Mechanics Lab

If the temperature in alaboratory goes ,higher than a specified limit,it willblow the buzzer .

BeginnerProtip30 minutes3
Mechanics Lab

Code

Science Laboratory

Arduino
//Lab project
float temp;
int temppin=0;
int ledG=5;
int ledR=3;
const int trigpin=9;
const int echopin=10;
long duration;
int distance;

int sensor=8;//the output of PIR sensor connected to pin 8
int sensor_value;//variable to hold read sensor value

void setup() {
  // put your setup code here, to run once:
pinMode(sensor,INPUT);
pinMode(ledG,OUTPUT);
pinMode(ledR,OUTPUT);
pinMode(13,OUTPUT);

pinMode(trigpin,OUTPUT);//sets the trigpin as an output;
pinMode(echopin,INPUT);//sets the echopin as an input;
//initialize the serial commuication;
Serial.begin(9600);
}

void loop() {
//clear the trig pin
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
//sets the trig pin on HIGH state for 10microseconds
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
//reads the echopin ,returns the sound wave travel time in microseconds 
duration=pulseIn(echopin,HIGH);
//calculatin the distance;
distance =duration*0.034/2;
//prints the distance on the serial monitor

temp =analogRead(temppin);
temp=temp*0.48828125;

sensor_value=digitalRead(sensor);
if(temp>50)
{ 
  digitalWrite(ledR,HIGH);
  digitalWrite(ledG,LOW);
  Serial.println("High Temperature Keep the distance");
  Serial.print("temperature=");
  Serial.print(temp);
  Serial.print("*C");
  Serial.println();
  delay(1000);
  Serial.println(sensor_value);
  Serial.println(distance);
  if(distance<100&&sensor_value==1)
  {
    Serial.println("Obstacle keep moving towards the lab ");
    Serial.println(distance);
    digitalWrite(13,HIGH);
   
    
  }
  else
  {
    if(sensor_value==0&&distance<100)
    {
      Serial.println("Obstacle is near to the lab but In rest");  
      digitalWrite(ledR,HIGH);
      delay(1000);
      digitalWrite(13,LOW);
    }
  
  }
}
else
  {
  if(sensor_value==1||distance>100)
  {
    Serial.println("Element is moving But still away from danzer area");
    digitalWrite(13,LOW); 
    digitalWrite(ledG,HIGH);
   
    digitalWrite(ledR,LOW);
  Serial.println(distance);
  Serial.print("All going Smoothly");
  Serial.print("temperature=");
  Serial.print(temp);
  Serial.print("*C");
  Serial.println();
  Serial.println(sensor_value);
  delay(1000);
  }
  else{
    digitalWrite(ledR,HIGH);
    digitalWrite(ledG,LOW);
    digitalWrite(13,HIGH);
  }

  }
}

Credits

Sanyam Chugh
13 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.