Face Tracking Desk Fan




Have you ever wished your fan would follow you around to cool you off on those hot summer days!? Well I decided to do something about it! Welcome FanBot, the personal desktop fan that follows your face and keeps you cool when things are getting a little too spicy!

This is more of a proof of concept than a finished beautified product. It is for a intermediate developer. However, I wouldn't write yourself off if you're a beginner, it'll just be a little more difficult. That being said, This project will get you a working version of openCV 3.0.0 on the raspberry pi2 (RPi). It will teach you a little about pulse width modulation (PWM) and how to control a servo with the general purpose input/output (GPIO) pins on the RPi. Let me know if you have problems. I'll do my best to fix anything. It should be noted that this is not going to be a completely optimized solution in code or execution. The purpose of this project is to get a simple working version of openCV, play around with it by means of face detection, and move a servo so that a small fan can cool you off!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Get Your Stuff.


  • Raspberry Pi2 (however, I'm sure other Pis will work too).
  • Breadboard.
  • 5 connecting wires.
    • 2 wires with male and female ends.
    • 5 wires with male-male ends.
  • A box or something to mount a servo on.
  • Servo 5V (I used the Tower pro Micro servo 9g sg90).
  • USB webcam (I used a cheap Logitech I had laying around).
  • Small dc cpu fan (I used a EFC0812DB from delta electronics).
  • One 5V power source for fan and servo (they can use the same source).
  • Power source for your RPi.
  • superglue

Step 2: Optional: Make a Box

I made my box out of some plastic I picked up at the local hardware store (ACE). Then I cut it with a ban saw and sanded down the edges. This was a very laborious way of making a box. I'd suggest just buying something or finding something around the house.

Nevertheless, here are the schematics for it. The plastic is .5 cm. (5 mm.) thick. I used some gorilla glue to hold it all together. Just apply it to the edges and then hold it for a few seconds. I cut the edge off of one side just as an access port to put all the wires through. The box is not drawn to scale. Use the measurements.

Step 3: Setup Stuff

There are many ways to wire this however I chose a straightforward route that was safe for the RPi. I didn't want to risk wiring the servo directly because it kept making the RPi crash. I superglued everything together. Here's the order in which i did it. Superglue the webcam-->fan-->servo-->box.

Step 4: Wiring

I made this schematic for clarity not for elegance. The power source that I used was a modified 5v 700mA power adapter. Be careful not to burn up anything with too strong of a power source. You should check to make sure you're not going to damage any of your electronics. I'm not liable for anything you might do!

Step 5: Software

For this project I was running python 2.7.9, openCV 3.0.0 and Raspbian Jessie.

For the servo I could explain it, however there is a much more clear concise servo tutorial here. I would suggest using that. It is what I used when I was first learning about servos.

Likewise, I'm going to pass off the openCV lesson to this tutorial right here. Again, it is an entire tutorial on getting openCV up and running. Which can be a beast sometimes. However, this is the tutorial I used and it worked perfectly the first time. Just read it carefully.

Step 6: More Software!

This is the script I used for getting the project up and running. The openCV code is optimized for my lighting environment. The servo code is also optimized for my lighting environment. Any image detection API/program/device is very susceptible to changes in lighting. You might have to play with some of the variables to get it working correctly for your needs.

There are a few explanations that should be made. First off, this code is ad-hoc. It is simply a script to get the project working. It doesn't demonstrate best coding practices at all (I'm sorry to any of my professors that might stumble upon it, I should have known better:).

The variables that might need adjustment are:

  • currentPos = the starting point for where the servo points and after that it is its current position while running.
  • minPos = the minimum position you want the servo to point. If its to low you can burn up the servo.
  • maxPos = the maximum position you want the servo to point. If its to high you can burn up the servo.
  • rangeRight = Think of a cone. The tip of the cone is where the servo is with the webcam. The further out you go with the cone the wider it gets. The rangeRight and rangeLeft make that cone. You can adjust them as you like. The servo will move more or less depending on how big of a range you give it.
  • rangeLeft.

I tried my best to comment the heck out of the code. If you have questions/problems let me know!

Step 7: Running It

In order to run fanBot you need to download the 2 files. Start up your RPi and open the terminal. Then type

  • virtualenv cv --system-site-packages
  • cd cv
  • source bin/activate
  • cd ..
  • python runFanBot.py haarcascade_frontalface_default.xml

If the line above this doesn't work make sure you are in the directory of the files you downloaded for this project and then try re-entering that line. Also, if its still not working and you are in the right directory check the permissions on the files and make sure they are executable.

Then if you need to stop the program just use the keyboard interrupt Ctrl+c and then deactivate the virtual environment by typing:

  • deactivate cv

If you know how you can always just clone the git repo for the project too.


Have fun and let me know if you run into problems. I'll do my best to help!

Maker Olympics Contest 2016

Participated in the
Maker Olympics Contest 2016

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    18 Discussions


    Question 1 year ago

    How can the code be adapted to use a Raspberry Pi Camera?


    1 year ago

    Great instruction and write up, follow up and I'm impressed.

    I've been researching Face Detection & Tracking resourcrs for last couple of years and I was focusing on PC & Arduino based method only and I'm stuck on issues that couldn't be resolved due to lack of support, continuing support or responses and ended up halfway or unfinished project. (Changes in Python, Modules, OpenCV, Visual Basic Version and Arduino made me impossible to debug coding error to duplicate successful project completion)

    And I'm curios, is there anyway to add or controlling 3rd axe, automatic zoom function in your software (I'll be using DSLR camera with servo controlling zoom in & out for accurate object focus for future and additional facial recognition process accuracy(offline from web-based server such as Microsoft Azure API).

    And, is it viable to recognize a face and track that face from local (within Raspberry PI3 Model B and focus (Auto Zoom) on that particular subject face? and further running Windows IOT -Facial Recognition API in the background?

    I'm not familiar with Raspberry PI at all, and I don't have programming skills other than the fact that I just ordered Raspberry Pi3 B today to follow your instruction.




    2 years ago

    please help me......i have this problem:

    Traceback (most recent call last):
    File "/home/pi/Desktop/deskph/runFanBot.py", line 31, in <module>
    cascPath = sys.argv[1]
    IndexError: list index out of range

    2 replies

    Reply 2 years ago

    This is just a guess. However, when you run the python script to start-up and whole fan you need to give it the haar_cascade file as a command line argument. See the 5th bullet point of step 7.


    2 years ago

    Can i change servo with A 12V Fan ?
    I want to control Fan speed Using PWM
    are this possible ?


    3 years ago

    Hey, great project. I was wondering if you could send me an email with a video that shows the steps and the programming.

    2 replies

    2 years ago

    Hey, great project. I was wondering if you could send me an email with a video that shows the steps and the programming.

    i'm electrical engineer student and i have project in raspberry and i want to learn more about raspberry..



    3 years ago

    Hello I'm Rev and I live and go to school in Belgium. I wanted to ask you if you could sent an email to me with a video that shows the steps and the programming.

    I do Engineering but I have never worked with a raspberry Pi and the programming, so I am asking you if could you help me with it? Kind regards Rev Griffey

    1 reply

    3 years ago

    Really great information and references. I will be using this instructable as a starting point for an animatronic-ish head and eyes project. Thanks.

    1 reply