0% found this document useful (0 votes)
5 views3 pages

Include Built - WPS Officehy

Hhh

Uploaded by

h210595v
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Include Built - WPS Officehy

Hhh

Uploaded by

h210595v
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <built_in.

h>

#include "DHT11.h" // Include your DHT library for humidity/temperature

#include "LCD.h" // Include your LCD library

// Define pins

sbit HEATER_PIN at RA0_bit; // Heater control pin

sbit FAN_PIN at RA1_bit; // Fan control pin

sbit BUZZER_PIN at RA2_bit; // Buzzer control pin

// Initialize variables

unsigned int temperature;

unsigned int humidity;

void main() {

// Initialize LCD

Lcd_Init();

Lcd_Cmd(_LCD_CLEAR);

Lcd_Cmd(_LCD_CURSOR_OFF);

// Initialize pins

TRISA = 0b00000000; // Set PORTA as output

HEATER_PIN = 0; // Turn off heater initially

FAN_PIN = 0; // Turn off fan initially

BUZZER_PIN = 0; // Turn off buzzer initially


while(1) {

// Read temperature and humidity from DHT11

if (DHT11_Read(&humidity, &temperature) == 0) {

// Display values on LCD

Lcd_Out(1, 1, "Temp: ");

Lcd_Chr(1, 7, temperature / 10 + '0'); // Tens place

Lcd_Chr(1, 8, temperature % 10 + '0'); // Units place

Lcd_Chr(1, 9, 223); // Degree symbol

Lcd_Chr(1, 10, 'C');

Lcd_Out(2, 1, "Humidity: ");

Lcd_Chr(2, 10, humidity / 10 + '0'); // Tens place

Lcd_Chr(2, 11, humidity % 10 + '0'); // Units place

Lcd_Chr(2, 12, '%');

// Control logic for heater and fan

if (temperature < 32) {

HEATER_PIN = 1; // Turn on heater

FAN_PIN = 0; // Ensure fan is off

} else if (temperature > 37) {

HEATER_PIN = 0; // Ensure heater is off

FAN_PIN = 1; // Turn on fan

} else {

HEATER_PIN = 0; // Turn off heater

FAN_PIN = 0; // Turn off fan


}

// Control logic for buzzer

if (temperature < 30 || temperature > 38 || humidity < 30 || humidity > 70) {

BUZZER_PIN = 1; // Activate buzzer

} else {

BUZZER_PIN = 0; // Deactivate buzzer

} else {

Lcd_Out(1, 1, "Sensor Error");

Delay_ms(1000); // Delay before the next reading

You might also like