Phil Speed
Published

Use Temperature to Control an AC Device

A simple project that demonstrates the use of both high and low temperature modules to control a 120VAC device.

Use Temperature to Control an AC Device

Things used in this project

Hardware components

Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Adafruit Thermocouple Amplifier MAX31855
×1
HiLetgo DHT11 Temperature Humidity Sensor
×1
Adafruit Raspberry Pi Zero W with Header
×1
AC/DC Power Adapter 1 amp
×1
Photo Coupler (opto-isolator) PC817
×1
Resistor 4.7K ohm
×1
Resistor 100 ohm
×1
Extension Cord 3 ft.
×1
Adafruit Pi T-Cobbler plus GPIO Breakout
×1
Adafruit K-Type Thermocoupler Wire
×1
2-Pole 5mm Screw Terminal
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Use Temperature to Control an AC Device

This allows the user to plug an AC device into the extension cord and control it using either high and low temperature probes or any script loaded into the Raspberry PI Zero W

Use Temperature to Control an AC Device

This allows the user to plug an AC device into the extension cord and control it using either high and low temperature probes or any script loaded into the Raspberry PI Zero W

Code

Simple Temperature Controller Using either the MAX31855 or DHT11 and solid state relay.

Python
The code included here is meant to simply demonstrate a few of the possible uses of this project board. Included are the necessary software imports to read the MAX31855 and DHT11 temperature sensor. Also included is how to turn on and off a solid state relay based on the output of the sensors.
#!/usr/bin/env python


import sys
print"You are using Python version"
print sys.version
print"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
import time
# the next 3 imports carry the following Copyright notice
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MAX31855.MAX31855 as MAX31855
import Adafruit_DHT
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
global sensorMAX
global sensorDHT
global delay_printing
delay_printing = 5              #limits the interval of checking and printing the sensor
                                # readings to at least every 5 seconds                   
relayPin = 12                   # 12 BCM  pin 32
GPIO.setup(relayPin, GPIO.OUT)  #set pin 12 as output
pinDht = 23                     # Data out pin of DHT11 sensor
CLK = 25                        # Next 3 pins for rpi software SPI configuration.
CS  = 24
DO  = 18

sensorDHT = Adafruit_DHT.DHT11
sensorMAX = MAX31855.MAX31855(CLK, CS, DO)


def readSensors():
	global probe_temperature
	global chip_temperature
	global room_humidity
	global room_temp
	probe_temperature = sensorMAX.readTempC() * 9.0 / 5.0 + 32.0 #converted to Fahrenheit
	chip_temperature = sensorMAX.readInternalC() * 9.0 / 5.0 + 32.0 #converted to Fahrenheit
	room_humidity, room_temp = Adafruit_DHT.read_retry(sensorDHT, pinDht)
	room_temp = room_temp * 9.0 / 5.0 + 32.0 # converted to Fahrenheit
	return
def relayON():
	GPIO.output(relayPin, GPIO.HIGH)
	print"The relay has been turned ON"
	return
def relayOFF():
	GPIO.output(relayPin, GPIO.LOW)
	print"The relay has been turned OFF"
	return
def printSensors():
	readSensors()
	print"The probe temperature is ...: ",probe_temperature
	print"The  room temperature is....: ",room_temp
	print"The  room    humidity is....: ",room_humidity
	print"The  chip temperature is....: ",chip_temperature
	time.sleep(delay_printing)
	return
#----------------------------------------------------------------------------------	

print('Press Ctrl-C to quit.')
print"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
global user_input
print'Please select one of the following'	
print'1. Maintain a temperature between low and high limits using the MAX31855'
print'2. Maintain a constant temperature with the DHT11'
print'3. Monitor the temperature and humidity with the DHT11'
print'4. Sound an alarm if the MAX31855 internal chip temperature gets too high'
user_input = raw_input('Select program 1, 2, 3, or 4: ')
user_input = int(user_input)
if user_input == 1:
	low_temp_limit = raw_input('Enter the probe low temperature limit: ')
	low_temp_limit = int(low_temp_limit)
	high_temp_limit = raw_input('Enter the probe high temperature limit: ')
	high_temp_limit = int(high_temp_limit)
	while user_input == 1:
		readSensors()
		print"Probe temperature is: ", probe_temperature
		if probe_temperature < low_temp_limit: #and probe_temperature < high_temp_limit:
			relayON()
			print"Probe temperature is too low: ", probe_temperature
			print"Low temperature limit is set at: ", low_temp_limit
		if probe_temperature > high_temp_limit:
			relayOFF()
			print"Probe temperature is too high: ", probe_temperature
			print"High temperature limit is set at: ", high_temp_limit
		
if user_input == 2:
	maintain_room_temp = raw_input('Enter the room temperature to maintain: ')
	maintain_room_temp = int(maintain_room_temp)
	while user_input == 2:
		readSensors()
		if room_temp < maintain_room_temp:
			relayON()
			print"Room temperature is less than; ", maintain_room_temp
		if room_temp > maintain_room_temp:
			relayOFF()
			print"Room temperature is greater than; ", maintain_room_temp

while user_input == 3:
	printSensors()
	
if user_input == 4:
	alarm_temp = raw_input('Enter chip temperature to sound alarm at: ')
	alarm_temp = int(alarm_temp)
	while user_input == 4:
		readSensors()
		if chip_temperature >= alarm_temp:
			print"Chip Temperature is exceeding limit of: ",alarm_temp
			print"The MAX31855 temperature is....:",chip_temperature
			

Credits

Phil Speed

Phil Speed

4 projects • 1 follower
Repaired anything in a computer room back in the late 60s and 70s. Also, did some assembly and machine language programming.

Comments