The Smart Fan (Student Version)

Description

The smart fan is a device that runs on Raspberry Pi. It consists of a rotating piece that revolves on a motor axis and changes speed based on the distance from the objects facing it. This will reduce the amount of air current given by the fan as the person comes closer and increases it as the person in front of it goes farther. The fan will stop rotating if the person in front of it comes very close for safety reasons.

Materials Needed:

  • Raspberry Pi with micro SD card and Raspbian
  • One ultrasonic sensor
  • One 6V simple DC motors
  • Diode
  • Transistor
  • Jumper wires
  • Resistors 300Ω or similar
  • Breadboard
  • Glue gun and glue sticks
  • Cutter blades or scissors
  • Thin sturdy cardboard (poster or portfolio cardboard)

Setup and Functionality:

The Smart Fan runs on Raspberry Pi and uses a simple DC motor and an ultrasonic sensor. The speed of the rotation of the fan is controlled by the ultrasonic sensor. It is programmed to slow down as the distance between any object and the sensor decreases and vice versa. The fan will fully stop rotating if an object comes very close to the sensor.

Circuitry and Electronics:

The diagram below shows all the wiring and connections of all the components used in the Smart Fan:

_images/image35.png

Figure 1: shows the wiring and connections of all the components to the Raspberry Pi.

The function of L293D is to connect the fan motor to an external power supply. The DC motor will not function properly if connected directly to the Raspberry Pi power supply as it cannot provide the required electrical current. In order to provide required current, an external power supply is connected to the circuit with the integrated circuit motor drive (IC) L293D.

Warning

Proper attention should be given to the wiring of the IC L293D. Make sure to follow the diagram above. In addition, changing the polarity of the battery will cause the current to reverse. This will lead to the overheating and damage of the IC. If this happens, the battery needs to be disconnected. Avoid touching the IC as it might cause skin burn.

The figure below shows the smart fan and the major components used:

_images/image42.png

Figure 2: Shows the setup of the fan with the ultrasonic sensor

Programming

The Smart Fan has been programmed using Python language:

Code of the smart fan

import RPi.GPIO as GPIO
import time


def reading(trig, ech):
    GPIO.output(trig, False)
    time.sleep(0.3)
    GPIO.output(trig, True)
    time.sleep(0.001)
    GPIO.output(trig, False)
    signalOff = time.time()
    while GPIO.input(ech) == 0:
        signalOff = time.time()
    while GPIO.input(ech) == 1:
        signalOn = time.time()
    timePassed = signalOn - signalOff
    distance = timePassed * 17000
    return distance


trigger = 3
echo = 8
motor = 10
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

GPIO.setup(motor, GPIO.OUT)
GPIO.setup(echo, GPIO.IN)
GPIO.setup(trigger, GPIO.OUT)

pwm = GPIO.PWM(motor, 500)
pwm.start(100)

try:
    while True:
        distance = reading(trigger, echo)
        print distance
        if distance < 10:
            pwm.ChangeDutyCycle(0)
        elif distance < 20:
            pwm.ChangeDutyCycle(20)
        elif distance < 40:
            pwm.ChangeDutyCycle(40)
        elif distance < 60:
            pwm.ChangeDutyCycle(60)
        elif distance < 80:
            pwm.ChangeDutyCycle(80)
        else:
            pwm.ChangeDutyCycle(100)

except KeyboardInterrupt:
    pwm.stop()
    GPIO.cleanup()