Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
gaurishsingla10sumitbranfigo
Published © GPL3+

Automatic temperature detecting system

Automatic temperature detecting system that can be quite helpful to the offices at this time of the pandemic

IntermediateFull instructions provided3,834
Automatic temperature detecting system

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
PIR Sensor, 7 m
PIR Sensor, 7 m
×1
Temperature Sensor
Temperature Sensor
×1
DC Motor, 12 V
DC Motor, 12 V
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
5 mm LED: Red
5 mm LED: Red
×1
Resistor 220 ohm
Resistor 220 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE
Tinkercad
Autodesk Tinkercad

Story

Read more

Schematics

Automatic temperature detecting system

Working image of the project

Automatic temperature detecting system

The video of working project

Code

Automatic temperature detecting system

C/C++
The code of Automatic temperature detecting system
#include<LiquidCrystal.h>  // Include LiquidCrystal library

float temperature;    // Variable for storing the input value of temperature sensor
float voltage;       // Variable for storing the given voltage of teperature sensor
float temp_in_celsius; // Variable for storing the value in celsius
float temp_in_fahernheit; // Variable for storing the value in fahernheit

const int trigPin = 9;   // Trigger pin of ultrasonic sensor 
const int echoPin = 10;  // Echo pin of ultrasonic sensor 
long duration;           // Variable for storing the input value of ultrasonic sensor
int distance_in_cm;      // Variable for storing the distance in centimeters
int distance_in_inches; // Variable for storing the distance in Inches

int pir_sensor = 8;     // Pin connected to output pin of PIR sensor
int Motor = 1;          // Pin connected to motor
int Buzzer = 11;        // Pin connected to Buzzer
int Led = 12;           // Pin connected to LED
int tmp_36 = A0;       // Pin connected to output pin of temperature sensor
int i = 0;             // Variable for 'if' condiotion
int s = 0;             // Variable for 'while loop'


int wait = 500;       // delay time

int pir_sensor_value;  // Variable for storing the input value of PIR sensor value

LiquidCrystal LCD1(13,A1,A2,A3,A4,A5);  // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7) for first LCD
LiquidCrystal LCD2(2,3,4,5,6,7);        // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7) for second LCD
  
void setup()
{
  
  
 LCD1.begin(16,2);  // Initialize first LiquidCrystal display
 LCD2.begin(16,2);   // Initialize second LiquidCrystal display
  
 pinMode(tmp_36, INPUT);         // Set Temperature sensor pin as an INPUT pin
 pinMode(trigPin, OUTPUT);      // Set Trigger pin of ultrasonic sensor as an OUTPUT pin
 pinMode(echoPin, INPUT);      // Set Echo pin of ultrasonic sensor as an INPUT pin
 pinMode(pir_sensor, INPUT);  // Set PIR sensor pin as an INPUT pin
 pinMode(Buzzer, OUTPUT);   // Set Buzzer pin as an OUTPUT pin
 pinMode(Motor, OUTPUT);     // Set Electric Motor pin as an OUTPUT pin
 pinMode(Led, OUTPUT);       // Set LED pin as an OUTPUT pin
  

}

void loop()
{
  pir_sensor_value = digitalRead(pir_sensor);      // // See if PIR sensor senses or not
  
  if (pir_sensor_value == HIGH || i == 1)
  {
       while(s<1)
    {
    LCD2.print("Alert");      // Print the text .Alert' on second LCD
    delay(wait); 
    LCD2.clear(); 
    s=1; 
    }

  digitalWrite(trigPin, LOW);  // Clears the trigPin condition
  delayMicroseconds(2);        
  digitalWrite(trigPin, HIGH);  // Sets the trigPin HIGH (ACTIVE) for 10 microseconds
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);     // Reads the echoPin, returns the sound wave travel time in microseconds
  distance_in_cm = duration*0.0343;
  distance_in_cm = distance_in_cm/2;    // Calculating the distance in centimeters     
  distance_in_inches = distance_in_cm * 0.3937;  // Calculating the distance in inches
  

  temperature = analogRead(tmp_36);   //getting the voltage reading from the temperature sensor
  voltage = temperature * 0.0048828125;  // converting that reading to voltage
  temp_in_celsius = (voltage - 0.5) * 100;   //converting from 10 mv per degree with 500 mV offset
                                              //to degrees ((voltage - 500mV) times 100)
  temp_in_fahernheit = (temp_in_celsius * 9.0 / 5.0) + 32.0;   // now convert to Fahrenheit
  

  if (distance_in_cm < 30)             // when the ultrasonic distance is less than 30 
  {
  LCD1.print("Temp.C :");        
  LCD1.print(temp_in_celsius);         // Print the temperature value in Celsius
  LCD1.setCursor(0,1);
  LCD1.print("Temp.F :");
  LCD1.print(temp_in_fahernheit);     // Print the temperature value in Celsius
    
  LCD2.print("Distance: ");
  LCD2 .print(distance_in_cm);      // Print the distance of ultrasonic sensor in Centimeters
  LCD2.print("cm");  
  LCD2.setCursor(0,1);  
  LCD2.print("Distance: ");
  LCD2 .print(distance_in_inches);   // Print the distance of ultrasonic sensor in Inches
  LCD2.print("in");
  delay(wait);
  LCD2.clear();   
  LCD1.clear();
  
  if (  temp_in_celsius > 37.5)   // When temperature is greater than 37.5 degree celsius
  {
    digitalWrite(Buzzer, HIGH);  // Buzzer will be turned on
    digitalWrite(Led, HIGH);      // LED will be turned on
    digitalWrite(Motor, LOW);     // Motor will stay off
  }
    
 else
  {
    digitalWrite(Buzzer, LOW);  // Buzzer will stay off
    digitalWrite(Led, LOW);     // LED will stay off
    digitalWrite(Motor, HIGH);  // Motor willbe turned on
  }
  }
  else
  {
 
    
  LCD1.print("");
  LCD1.setCursor(0,1);
  LCD1.print("");

  LCD2.print("Distance: ");
  LCD2 .print(distance_in_cm);  // Print the distance of ultrasonic sensor in Centimeters
  LCD2.print("cm");  
  LCD2.setCursor(0,1);  
  LCD2.print("Distance: ");
  LCD2 .print(distance_in_inches);  // Print the distance of ultrasonic sensor in Inches
  LCD2.print("in");
  delay(wait);
  LCD1.clear();
  LCD2.clear();   
  } 
  i=1;    
 }  

  else
  {
    i=0;
  }
  }

Credits

gaurishsingla10
1 project • 3 followers
sumitbranfigo
7 projects • 6 followers

Comments