print("This program will show temperature, humidity and alarm in server room")
print("By: Izzat Haziq Bin Hazrin")
print("Date: 30/4/2024")
#import libraries
from utime import sleep
from machine import Pin, PWM
from machine import Pin, SoftI2C
import OLED_lib
import time
import dht
#pin declaration
sensor = dht.DHT22(Pin(14))
Red_led = Pin(12,Pin.OUT)
Green_led = Pin(27,Pin.OUT)
Yellow_led = Pin(26,Pin.OUT)
Buzzer = PWM(Pin(18,Pin.OUT))
oled_pin = SoftI2C(scl=Pin(22), sda=Pin(21))
#create an object name for sensor with library
#Object name = library_name.class_name(.......)
display = OLED_lib.SSD1306_I2C(width=128, height=64, i2c=oled_pin, external_vcc=False)
#parameter declaration
#main pprogram
while True:
Green_led.on()
Red_led.off()
Buzzer.init(freq=500 , duty=0)
sensor.measure()
t = sensor.temperature()
h = sensor.humidity()
if t > 30 and h < 20:
for m in range (20):
Red_led.on()
Buzzer.init(freq=1000 , duty=50)
sleep(0.08)
Red_led.off()
Buzzer.init(freq=500 , duty=0)
sleep(0.08)
Green_led.off()
display.fill(1)
display.text('A/C MALFUNCTION', x=2 , y=10 , col=0)
display.text('Temp: %3.1f C' %t, x=2 , y=30 , col=0)
display.text('Humid: %3.1f %%' %h, x=2 , y=40 , col=0)
display.show()
if h > 50 and t < 10:
for m in range (10):
Yellow_led.on()
Buzzer.init(freq=1000 , duty=50)
sleep(0.08)
Yellow_led.off()
Buzzer.init(freq=500 , duty=0)
sleep(0.08)
Green_led.off()
Red_led.off()
display.fill(1)
display.text('ROOM TOO COLD', x=2 , y=10 , col=0)
display.text('Temp: %3.1f C' %t, x=2 , y=30 , col=0)
display.text('Humid: %3.1f %%' %h, x=2 , y=40 , col=0)
display.show()
else:
Red_led.off()
Green_led.on()
Yellow_led.off()
display.fill(1)
display.text('ROOM IS OPTIMUM', x=5 , y=10 , col=0)
display.text('Temp: %3.1f C' %t, x=2 , y=30 , col=0)
display.show()
sleep(1)