Back to engineering archive

Record 015 / Sensing and instrumentation

Environmental alarm and LCD controller

DHT22 temperature monitoring with an adjustable alarm threshold and a local I2C LCD.

Firmware development
Environmental sensingLCDAlarm logicI2C

Firmware flow

Compare the temperature and update local feedback

Selected firmware fragment: alarm output and conditional LCD refresh.

The output follows the current temperature-versus-limit comparison. The sketch then reports the output and refreshes the LCD only when its update flag is set.

Failed reads leave the stored temperature unchanged. The source does not establish sensor accuracy or hardware alarm testing.

Read the implementation

Selected firmware excerpt. The diagram explains the code; it is not a hardware test.

Selected source excerpt

  // --- Set Trigger Output Pin Based on Alarm Condition ---
  if (currentTemp >= triggerLimit) {
    digitalWrite(triggerPin, HIGH);
  } else {
    digitalWrite(triggerPin, LOW);
  }
  
  // Debug: Print the state of triggerPin to Serial Monitor
  Serial.print("Trigger Pin state: ");
  Serial.println(digitalRead(triggerPin));
  
  // --- Update LCD Display Only When Needed ---
  if (updateLCDFlag) {
    updateLCD();
    updateLCDFlag = false;
  }
}
CheckTemperature at or above the limit?
ActionSet alarm output high
ActionSet alarm output low
ActionReport output state over Serial
ActionRefresh LCD and clear update flag
ResultContinue the main loop

Technical notes

Temperature and threshold

The sketch reads temperature every two seconds. Two debounced buttons raise or lower the alarm limit by one degree, and the output is high when the stored temperature reaches or exceeds that limit.

Display updates

The I2C LCD shows the temperature, limit and alarm indicator. A flag requests refreshes after valid readings or limit changes; Serial reports diagnostic information.

Reading failures

Failed reads leave the stored temperature unchanged. The sketch reports the failure over Serial but has no separate sensor-failure alarm; measurement accuracy and hardware alarm operation were not tested.

Engineering archiveArchive record

Project enquiries

Discuss your project.

Tell us what you’re developing and where you need engineering support.

Discuss your project