Alan Hilliard
Published © GPL3+

Temperature Controlled Fan and Data Recorder

This project uses a Raspberry Pi and BMP 180 sensor to record temperature, altitude, atmospheric pressure, and control a fan to manage heat.

IntermediateProtip5 hours5,028
Temperature Controlled Fan and Data Recorder

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
BMP 180
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
DC motor (generic)
×1

Story

Read more

Schematics

Circuit Diagram

this diagram shows the circuit layout for this project

Code

turn fan on test code

Python
this python code allows you to test to see if your fan will turn on properly. the pin used was 23, so please change pin numbers from 23 if you choose another pin.
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(23, GPIO.OUT)
GPIO.output(23,True)

turn fan off

Python
This code allows you to test you circuit to see if your fan will turn off when requested. Pin 23 was used.
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(23, GPIO.OUT)
GPIO.output(23, False)

Temperature Control and Display code

Python
This code allows you to set the amount of run time for the program, period between pulsing the sensor, temperature at which the fan will turn on and what temperature it will turn off at. It will display and record the temperature, atmospheric pressure, and altitude based on barometric pressure on the Python command terminal every 10 seconds.
#import needed files/references, sorcery, to read sensors

import sys
import time
import datetime

import Adafruit_BMP.BMP085 as BMP085

sensor = BMP085.BMP085()

# How long to wait (in seconds) between measurements.
FREQUENCY_SECONDS      = 10

# Create sensor instance with default I2C bus (On Raspberry Pi either 0 or
# 1 based on the revision, on Beaglebone Black default to 1).
bmp = BMP085.BMP085()

#Run time of program in seconds
Timesup = 3600
#initial time
times=0
#temperature fan turns on at (celsius)
Tfan_on= 27

#start program
print 'Logging sensor measurements.'
print 'Press Ctrl-C to quit.\n'

while True:
    # Login if necessary.
    if times < Timesup:

    # Attempt to get sensor readings.
            temp = bmp.read_temperature()
            pressure = bmp.read_pressure()
            altitude = bmp.read_altitude()

            print 'Temperature: {0:0.1f} C'.format(temp)
            print 'Pressure:    {0:0.1f} Pa'.format(pressure)
            print 'Altitude:    {0:0.1f} m\n'.format(altitude)
 
#count time allotted
    times=times+10
#turn fan on if hot
    if Tfan_on < temp:
        import RPi.GPIO as GPIO
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.OUT)
        GPIO.output(23,True)
# turn fan off if acceptable
    else:
        import RPi.GPIO as GPIO
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.OUT)
        GPIO.output(23,False)        


    # Wait 10 seconds before continuing
    time.sleep(FREQUENCY_SECONDS)
    #kill job if its done
    if times == Timesup:    
        print 'Simulation has ended, time is up!'
        break

Credits

Alan Hilliard

Alan Hilliard

1 project • 3 followers
Mechanical Engineer-Motorsports concentration Interested in Aerospace and mechanical technologies.

Comments