This project is based on a low voltage relay (model SRD-05VDC-SL-C) and on a 2-pin low-consumption fan powered at 5 volts. We will manage the relay via software in order to turn the fan on/off. For ease we are going to connect these components to the FTDI FT232H device, of which there is a dedicated page on this site - refer to the above page for installation.
This sensor must be connected to the FTDI FT232H development board. The connection connectors are listed below:
Image | Board FT232H | Relay | Fan |
---|---|---|---|
AD0 | IN | ------ | |
+5V | VCC | ------ | |
GND | GND | ------ | |
+5V | NO | ------ | |
------ | COM | +5V | |
GND | ------ | GND |
To manage these components, the presence of the "PyFTDI" library is required. The Python code is the following:
from os import environ from pyftdi.gpio import GpioAsyncController import time try: device = GpioAsyncController() url = environ.get('FTDI_DEVICE', 'ftdi:///1') device.configure(url) gpio = device.get_gpio() direction = gpio.direction gpio.set_direction(0b1, 0b1) gpio.write(0b0) print("FAN IS OFF") time.sleep(2) gpio.write(0b1) print("FAN IS ON") time.sleep(10) gpio.write(0b0) print("FAN IS OFF") gpio.set_direction(0b1, 0b0) gpio.write(0b0) except KeyboardInterrupt: # Capture keyboard ^C to exit the program print('\nYou terminated the program. The program ends!')