Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
| × | 1 | ||||
![]() |
| × | 1 | |||
![]() |
| × | 2 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 7 | |||
| × | 8 | ||||
Software apps and online services | ||||||
![]() |
| |||||
| ||||||
|
This project is about a circuit designed to measure the temperature and humidity in the room. It supports the maintenance of a lifestyle in normal conditions. The results can be read by e-mail and browser, so that the owner is notified of the status of the indices.
OperatingStages
1. The temperature and humidity in the room are in the normal conditions, more exactly 28° Celsius, respectively 55%, the red led is on.
2. The temperature is higher than 28° Celsius, but the humidity is still in normal conditions, then red led is off and green led is on.
3. The humidity is higher than 55% and the temperature is not higher than 28° Celsius, then red led is off and blue led is on.
4. Humidity and temperature are higher than normal limits, then red led is off, blue and green leds are on.
5. When indicators are higher than normal and the page in the browser is refreshed, then the owner receives an email with information about the indicators.
import RPi.GPIO as GPIO
import Adafruit_DHT
import time
import threading
import smtplib
from email.mime.text import MIMEText
from flask import Flask, render_template
dht11 = 17
redLed = 3
greenLed = 5
blueLed = 7
refreshTimer = 30 # 3600 - for 1h
constTemperature = 28
constHumidity = 55
email = 'smartRoom1306B@gmail.com'
password = '13smartRoom06B'
receiver = 'butnarumariana26@gmail.com'
mutex = threading.Lock()
GPIO.setmode(GPIO.BOARD)
GPIO.setup(redLed,GPIO.OUT)
GPIO.setup(greenLed,GPIO.OUT)
GPIO.setup(blueLed,GPIO.OUT)
app = Flask(__name__)
humidity = 0
temperature = 0
@app.route('/')
def index():
return render_template('index.html', recHumidity = str(humidity), recTemperature = str(temperature))
@app.route('/', methods=['POST'])
def readDataFromSensor():
global humidity
global temperature
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, dht11)
message = ''
messageEmail = ''
if humidity is not None and temperature is not None:
message = 'Temperature = ' + str(temperature) + '*C Humidity = ' + str(humidity) + '%\n'
if humidity <= constHumidity and temperature <= constTemperature:
messageEmail = message + 'Temperature and humidity are normal'
print(messageEmail)
GPIO.output(redLed, 1)
GPIO.output(blueLed, 0)
GPIO.output(greenLed, 0)
elif humidity > constHumidity and temperature <= constTemperature:
messageEmail = message + 'The humidity is too high, the dehumidifier starts!'
print(messageEmail)
GPIO.output(redLed, 0)
GPIO.output(blueLed, 1)
GPIO.output(greenLed, 0)
sendEmail(messageEmail)
elif humidity <= constHumidity and temperature > constTemperature:
messageEmail = message + 'The temperature is too high, the AC starts!'
print(messageEmail)
GPIO.output(redLed, 0)
GPIO.output(blueLed, 0)
GPIO.output(greenLed, 1)
sendEmail(messageEmail)
elif humidity > constHumidity and temperature > constTemperature:
messageEmail = message + 'The temperature and humidity are too high, the AC and the dehumidifier are turned on!'
print(messageEmail)
GPIO.output(redLed, 0)
GPIO.output(blueLed, 1)
GPIO.output(greenLed, 1)
sendEmail(messageEmail)
else:
message = 'Failed to get reading. Try again!'
print(message)
return render_template('index.html', recHumidity = str(humidity), recTemperature = str(temperature))
def sendEmail(message):
global mutex
mutex.acquire()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email, password)
emailMessage = MIMEText(message, 'plain')
emailMessage['Subject'] = 'Temperature and humidity ratio.'
server.sendmail(email, receiver, emailMessage.as_string())
server.quit()
print('Email sent successfully!')
mutex.release()
if __name__ == '__main__':
GPIO.output(redLed, 1)
app.run(host = '0.0.0.0')
readDataFromSensor()
GPIO.output(redLed, 0)
GPIO.cleanup()
<html>
<head>
<title> Smart Room </title>
<style>
* {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
h1{
padding-top:30px;
text-align: center;
color: white;
padding-bottom: 100px
}
p {
font-size: 20px;
text-align: center;
color: white;
}
header, body {
background-color: #282d32;
}
.footer-dark {
padding:20px 0;
color:#f0f9ff;
background-color:#282d32;
}
.footer-dark .copyright {
text-align:center;
opacity:0.8;
font-size:16px;
margin-bottom:0;
padding-top:300px;
}
.button {
background-color: #04AA6D;
color: white;
padding: 14px 20px;
margin: 0 auto;
display: block;
border: none;
cursor: pointer;
width: 10%;
font-size: 17px;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
</head>
<body>
<h1>
Smart Room Project
</h1>
<p id='Temperature'>
<b>Temperatura:</b> {{recTemperature}} *C
</p>
<br>
<p id='Humidity'>
<b>Umiditate:</b> {{recHumidity}} %
</p>
<br><br>
<form action="/" method="POST">
<button type="submit" class="button">Refresh</button>
</form>
</body>
<footer>
<footer class="footer-dark">
<p class="copyright">
Made by: <br>
<b>
Butnaru Silviu - 1306B<br>
Paraschiv Vlad - 1306B<br>
Buliga Diana - 1306B<br>
Iluca Alexandru - 1306B<br>
</b>
</p>
</footer>
</footer>
</html>
Comments
Please log in or sign up to comment.