Arduino Controlled Personal Fan With Ping Sensor / ATtiny2313

by WWC in Circuits > Sensors

8512 Views, 16 Favorites, 0 Comments

Arduino Controlled Personal Fan With Ping Sensor / ATtiny2313

Screenshot_1.png.jpg
DSC01694.JPG
DSC01676.JPG
                                                      What does this do?

This is a fan that will automatically come on when i sit at my workbench and off when i leave.
It uses an Ultrasonic Distance Sensor, or commonly called a  "Ping " sensor for detection.
An ATtiny2313 to handle the processing.
A power supply from a router. ( Wall wort )
A relay to switch the AC power.

The ping sensor works by sending out radio waves and times how long it takes for the radio waves to bounce off of an object then return. From this time we can calculate distance. I know it is more complicated than this but this is the simplified version 

Video Link

BOM

Parts.jpg
  • ATtiny2313
  • 6v relay
  • 20 pin socket
  •  Ping sensor
  • Fan
  • 2n2222 transistor
  • 1N4004 Diode (2)
  • 10K resistor
  • 330R Resistor
  • 8.2v power supply
  • Perf board
  • Switch
Wire Glue

Circuit

FAN.png
Screenshot_13333.png
Screenshot_4.png
 Not much to say here it is pretty straight forward.

The one thing that needs explaining is the power supply.
It is a 5v ( wall wort ) that puts out 6.08v whether under a load or not.  Just rite for a 6v relay, but not a micro-controller
Scenes the ATtiny2313 needs 5v i put a 1N4004 diode in the VCC line to reduce the voltage by .6v. That is the standard voltage drop for a rectifier diode.  

 6.08v - .6v = 5.48v.

Maximum allowable operating voltage is 5.5v in the data sheet. Yes it is pushing to run piratically at max volts. But it is an experiment to see how it works out. So far it has been running for 3 months and all is well.  

Data Sheet

Power Supply

01.bmp
02.bmp
03.bmp
04.bmp.jpg
06.bmp.jpg
05.bmp.jpg
10.bmp
11.bmp
12.bmp
I could of just plugged the wall wart directly into the wall outlet then powered the circuit with a power jack but that means i would use 2 plugins. With taking the wall wart apart and using only the circuit i could make this all on one board and one plugin.

Main Board

07.bmp
08.bmp.jpg
09.bmp
18.bmp
15.bmp
19.bmp.jpg
FAN.png
Screenshot_13333.png
Arrange the components for best fit and clearance. Solder everything down and run traces as per the circuit diagram. 

Fan Motor

20.bmp
21.bmp
23.bmp
This was of those little 6" all plastic fans. After it had dropped for the umpthteen time the glue just couldn't hold it together any longer. After it sat in my junk box for a year or so i decided i found a good place i could make use of it. I stripped it down and glued the motor in the corner of a shelf that sits on top of my workbench. 

Ping Sensor

16.bmp
14.bmp
16.bmp.jpg
This a 5 pin sensor. It could be called a 4 pin i suppose scene 2 of the pins are grounds.
  1. Ground
  2. Trigger
  3. Echo
  4. VCC
 
 
While this sketch is for a 4 pin sensor, i have successfully ran this 4 pin sensor on a 3 pin sketch also. Tie the Trigger and Echo pins together on the same output pin of the Arduino. It works just as well either way.

Programing

03.bmp.jpg
For programming i used the methods found in this Instructable as well as this Instructable. 

Code

ArduinoLogo.gif
 #include "Ultrasonic.h"
 
int RELAY = 9;  // RELAY Pin.  
int TRIG = 11; // Trigger Pin
int ECHO = 10; // Echo Pin
int Range; // The range of the object from Ping Sensor
int Dist; // The Distance value

Ultrasonic ultrasonic(TRIG,ECHO); // Create and initialize the Ultrasonic object.

void setup() {
  pinMode(RELAY, OUTPUT); //To the relay via the transistor
  Dist = 32; //The distance in inches. Change this for increasted or dicreasted range.
}

void loop() {
  //Range = ultrasonic.Ranging(CM); // Range is calculated in Centimeters.
  Range = ultrasonic.Ranging(INC); // Range is calculated in Inches.
  
  if (Range < Dist) {
    digitalWrite(RELAY, HIGH);   
  } else if (Range > Dist) {
    digitalWrite(RELAY, LOW);
     delay(9000);
  }

}



Don't forget to make sure you have the "Ultrasonic.h" library installed or this sketch wont work.
Here is a link to the "Ultrasonic.h code if needed.

There is a delay on the end so that if something passing quickly by the sensors range it will not trigger it. Only if an object has been in the sensor range for more that the delay time will the fan come on.

Thank You

Thank-you-sign1.jpg
Thanks for looking!

If there is any questions i can answer i am happy to.