Programming Examples

Arduino program to interface a temperature monitoring system in a public environment which will display information


Write down an Arduino program to interface a temperature monitoring system in a public environment which will display information on 16*2 LCD “Fever” if temp is greater than 99.6 degrees and “No fever” if the temp.is below 99.6 degrees. (Use of DHT11, Ultrasonic motion sensor is permissible).

i) AQI-in the range of 0 to 50-Excellent 

ii) AQI-in the range

Solution

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
DHT dht(2, DHT11);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change 0x27 to your LCD's I2C address if necessary

void setup() {
  lcd.begin();
  lcd.backlight();
  dht.begin();
  
  pinMode(9, OUTPUT);
  pinMode(10, INPUT);

  Serial.begin(9600);
}

void loop() {
  float temperature = dht.readTemperature(true); // Read temperature in Fahrenheit
  float humidity = dht.readHumidity(); // Read humidity
  int distance = getDistance(); // Get distance from ultrasonic sensor

  if (isnan(temperature) || isnan(humidity)) {
    lcd.setCursor(0, 0);
    lcd.print("Sensor error");
    return;
  }

  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(temperature);
  lcd.print(" F");

  lcd.setCursor(0, 1);
  if (temperature > 99.6) {
    lcd.print("Fever");
  } else {
    lcd.print("No fever");
  }

  delay(2000); // Update every 2 seconds

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Humidity: ");
  lcd.print(humidity);
  lcd.print("%");

  lcd.setCursor(0, 1);
  if (distance < 100) { // If motion is detected within 100 cm
    int aqi = random(0, 500); // Simulating AQI value, replace with actual AQI sensor if available
    if (aqi <= 50) {
      lcd.print("AQI: Excellent");
    } else if (aqi <= 100) {
      lcd.print("AQI: Good");
    } else if (aqi <= 150) {
      lcd.print("AQI: Moderate");
    } else if (aqi <= 200) {
      lcd.print("AQI: Poor");
    } else {
      lcd.print("AQI: Very Poor");
    }
  } else {
    lcd.print("No motion");
  }

  delay(2000); // Update every 2 seconds
}

int getDistance() {
  digitalWrite(9, LOW);
  delayMicroseconds(2);
  digitalWrite(9, HIGH);
  delayMicroseconds(10);
  digitalWrite(9, LOW);
  long duration = pulseIn(10, HIGH);
  int distance = duration * 0.034 / 2;
  return distance;
}
▶ RUN

Output/ Explanation:

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad