Somethea Siek
Published © MIT

Smart Heater with Wep Interface

A heater system that adjusts to reach any temperature. All details, statuses, and controls are available through a web app.

ExpertWork in progressOver 2 days240
Smart Heater with Wep Interface

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Fan Heater, 1.5 kW
Fan Heater, 1.5 kW
×1
WI-FI Enabled Smart Plug
×1

Software apps and online services

IFTTT Webhooks
IFTTT Smart Life
Smart Life App
JavaScript React
Python Flask

Story

Read more

Schematics

Setup DHT11 Temperature Sensor

Setup PIR Motion Sensor

Code

Test Motion Sensor Python Code

Python
import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)

motion_pin = 16
led_pin = 21

GPIO.setup(motion_pin, GPIO.IN)
GPIO.setup(led_pin, GPIO.OUT)

print("Sensor initializing . . .")
sleep(2)

try:
    no_motion_count = 0

    while True:
        if GPIO.input(motion_pin) == True:
            print("Motion Detected!")
            GPIO.output(led_pin, True)
            sleep(4)
            GPIO.output(led_pin, False)
            no_motion_count = 0
        else:
            no_motion_count += 1

        print(f"No Motion Count: {no_motion_count}")

        sleep(1)

except KeyboardInterrupt:
    pass
finally:
    GPIO.output(led_pin, False)
    GPIO.cleanup()

Test Temperature Sensor Code

Python
import Adafruit_DHT
from time import sleep

temperature_humidity_sensor = Adafruit_DHT.DHT11
gpio_pin = 4

try:
    while True:
        humidity, temperature = Adafruit_DHT.read_retry(
            temperature_humidity_sensor, gpio_pin)
        if humidity is not None and temperature is not None:
            print(
                'Temp={0:0.1f}*C  Humidity={1:0.1f}%'.format(temperature, humidity))
        else:
            print('Failed to get reading. Try again!')
        sleep(0.5)
except KeyboardInterrupt:
    pass

Test All Sensor Python Code

Python
import RPi.GPIO as GPIO
import Adafruit_DHT
from time import sleep

GPIO.setmode(GPIO.BCM)

# Motion

motion_pin = 16
led_pin = 21
no_motion_count = 0

GPIO.setup(motion_pin, GPIO.IN)
GPIO.setup(led_pin, GPIO.OUT)


def handle_motion(no_motion_count):
    if GPIO.input(motion_pin) == True:
        print("Motion Detected!")
        GPIO.output(led_pin, True)
        sleep(4)
        GPIO.output(led_pin, False)
        no_motion_count = 0
        return 0
    else:
        return no_motion_count + 1


# Temperature + Humidity
temperature_humidity_sensor = Adafruit_DHT.DHT11
gpio_pin = 4


def handle_temperature():
    humidity, temperature = Adafruit_DHT.read_retry(
        temperature_humidity_sensor, gpio_pin)
    if humidity is not None and temperature is not None:
        print(
            'Temperature = {0:0.1f}*C  Humidity = {1:0.1f}%'.format(temperature, humidity))
        return temperature
    else:
        print('Failed to read Temperature/Humidity')

# Run Program


print("Sensor initializing . . .")
sleep(5)


try:
    no_motion_count = 0
    desired_temperature = 28
    desired_temperature_margin = 2

    while True:
        temperature = handle_temperature()
        no_motion_count = handle_motion(no_motion_count)

        if no_motion_count >= 20:
            print(f"No Human Detected.")
        elif temperature > desired_temperature + desired_temperature_margin:
            print(f"Temperature Too High")
        elif temperature < desired_temperature - desired_temperature_margin:
            print(f"Temperature Too Low")
        else:
            print(f"Temperature Just Right")

        print(f"No Motion Count: {no_motion_count}")

        sleep(0.25)
except KeyboardInterrupt:
    pass
finally:
    GPIO.output(led_pin, False)
    GPIO.cleanup()

Frontend React

API Flask

Credits

Somethea Siek
1 project • 2 followers

Comments