Introduction: 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!

Step 1: Get Your Stuff.

Supplies:

  • 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.

https://github.com/thepinkturtle/fanBotSimplified....

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