1
0

Compare commits

...

9 Commits

Author SHA1 Message Date
floristhebeast
a4d6f69450 voeg LED toe 2025-06-30 20:47:39 +02:00
floristhebeast
5de9255526 voeg een else toe voor als de contitions niet kloppen 2025-06-30 20:43:00 +02:00
floristhebeast
27aaf239c7 update dht11.py 2025-06-30 20:07:30 +02:00
floristhebeast
af035f0358 voeg 5 minuten ventilator toe 2025-06-30 20:05:30 +02:00
b9c2c6054a Update README.md 2025-06-30 14:21:01 +00:00
ce27e252a5 update pins 2025-06-29 22:38:17 +00:00
floristhebeast
cc1170a4d1 heb comments toegevoegd 2025-06-29 02:55:16 +02:00
floristhebeast
806aaab8bd had humid en humidity omgedraaid 2025-06-29 02:51:49 +02:00
floristhebeast
501186efa3 had <title> niet gesloten 2025-06-29 02:47:36 +02:00
2 changed files with 39 additions and 11 deletions

View File

@@ -1,3 +1,3 @@
# school-DHT11-sensor
a simple python file that reads data from a DHT11 sensor and uses it in multiple ways
a simple python file that reads data from a DHT11 sensor and uses it to decide if a fan and LED should turn on

View File

@@ -6,14 +6,16 @@ import http.server
import threading
import json
sensor = adafruit_dht.DHT11(board.D6)
LED_PIN = 21
FAN_PIN = 22
sensor = adafruit_dht.DHT11(board.D31)
LED_PIN = 40
FAN_PIN = 15
#stel GPIO in (ik hoop dat het werkt. ik kan het niet testen)
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.setup(FAN_PIN, GPIO.OUT)
#array voor sensor data
sensor_data = {
'tempc': 0.0,
'tempf': 0.0,
@@ -22,7 +24,11 @@ sensor_data = {
'fan': False
}
fan_timer_start = 0
fan_timer_actief = False
def check_data():
global fan_timer_actief, fan_timer_start
while True:
try:
temperatuur_C = sensor.temperature
@@ -33,29 +39,50 @@ def check_data():
sensor_data['humidity'] = humidity
except RuntimeError as err:
print(err.args[0])
# zet fan en led aan als temperatuur hoger is dan 20 C
if temperatuur_C > 20:
GPIO.output(LED_PIN, GPIO.HIGH)
GPIO.output(FAN_PIN, GPIO.HIGH)
sensor_data['led'] = True
sensor_data['fan'] = True
fan_timer_actief = False
fan_timer_start = 0
else:
GPIO.output(LED_PIN, GPIO.LOW)
GPIO.output(FAN_PIN, GPIO.LOW)
sensor_data['led'] = False
sensor_data['fan'] = False
if sensor_data['fan'] == True and fan_timer_actief == False:
fan_timer_actief = True
fan_timer_start = time.time()
sensor_data['fan'] = True
sensor_data['led'] = False
GPIO.output(FAN_PIN, GPIO.HIGH)
GPIO.output(LED_PIN, GPIO.LOW)
elif sensor_data['fan'] == True and fan_timer_actief == True and time.time() - fan_timer_start > 300: # 5 minuten
fan_timer_actief = False
fan_timer_start = 0
sensor_data['fan'] = False
sensor_data['led'] = False
GPIO.output(FAN_PIN, GPIO.LOW)
GPIO.output(LED_PIN, GPIO.LOW)
else:
fan_timer_actief = False
fan_timer_start = 0
sensor_data['fan'] = False
sensor_data['led'] = False
GPIO.output(FAN_PIN, GPIO.LOW)
GPIO.output(LED_PIN, GPIO.LOW)
class handler_class(http.server.BaseHTTPRequestHandler):
def do_GET (self):
if self.path == '/':
#headers
self.send_response(200)
self.send_header('Content-type', 'text/html; charset=utf-8')
self.end_headers()
#html website
website = """
<!DOCTYPE html>
<html>
<head>
<title>IOT DHT11 sensor status<title>
<title>IOT DHT11 sensor status</title>
<meta charset="UTF-8">
</head>
<body>
@@ -72,7 +99,7 @@ class handler_class(http.server.BaseHTTPRequestHandler):
.then(data => {
document.getElementById('tempc').textContent = data.tempc.toFixed(1);
document.getElementById('tempf').textContent = data.tempf.toFixed(1);
document.getElementById('humidity').textContent = data.humid.toFixed(1);
document.getElementById('humid').textContent = data.humidity.toFixed(1);
document.getElementById('led').textContent = data.led ? 'AAN' : 'UIT';
document.getElementById('fan').textContent = data.fan ? 'AAN' : 'UIT';
});
@@ -89,6 +116,7 @@ class handler_class(http.server.BaseHTTPRequestHandler):
self.wfile.write(json.dumps(sensor_data).encode())
def web_server():
#web server port en IP binding
web_binding = ('', 8000)
server = http.server.HTTPServer(web_binding, handler_class)
print ("server draait op port 8000")