print("Welcome to Smart Room System!")
print('By: Rahimi')
#Import all necessery library
from machine import Pin, ADC
from utime import sleep
import dht
import lib_servo
#Pin Declaration
dht_22 = Pin(2)
Servo1 = Pin(33, Pin.OUT)
LDR_Pin = ADC(Pin(34, Pin.IN))
Led_lamp = Pin(13, Pin.OUT)
Led_Game = Pin(12, Pin.OUT)
#Create the object name for sensor with library --> LIBRARYNAME.CLASSNAME
mod_servo = lib_servo.Servo(pin=Servo1)
dht_sensor = dht.DHT22(pin=dht_22)
#Main Program
while True:
#Lamp Part
light_intensity = LDR_Pin.read()
voltage = light_intensity / 4096*5.0
print('The voltage detected is: ', voltage, 'V')
if 0 < voltage < 0.83:
Led_lamp.off()
Led_Game.off()
elif 2.5 > voltage < 4.17:
Led_Game.on()
Led_lamp.off()
else:
Led_lamp.on()
Led_Game.off()
while True:
#Fan Part
dht_sensor.measure()
temperature = dht_sensor.temperature()
humidity = dht_sensor.humidity()
print('The temperature detected id: ', temperature, 'C')
if temperature < 27:
mod_servo.move(0)
else:
mod_servo.move(0)
sleep(0.3)
mod_servo.move(90)
sleep(0.3)
mod_servo.move(180)
sleep(0.3)
mod_servo.move(90)
sleep(0.3)
mod_servo.move(0)
sleep(0.3)
break