ULTRASONIC FAN

34

Made by KCIS Grade 9 Brian Hou J05438

"Smart fan"

Supplies:

  1. Arduino Leonardo
  2. breadboard
  3. jumper wires
  4. ultrasonic sensor
  5. servo motor
  6. DC motor
  7. plastic fan
  8. container
  9. cork

Step 1: INTRO

Instead of blowing with no purpose, this fan blows when it senses something or someone before blowing

Step 2: STEPS:

  1. gather the materials
  2. servo motor to Dpin #3
  3. ultrasonic sensor: Trig to Apin #5, Echo to Apin #4
  4. connect L298n to Arduino Board
  5. connect DC motor to L298n
  6. reset the servo motor to 0 degrees
  7. glue the cork to the servo motor
  8. glue the ultrasonic to the cork facing 0 degrees
  9. glue the DC motor on to the cork, also pointing at 0 degrees
  10. put the following code in:
  11. //to use servo motor
    #include <Servo.h>
    //ultrasonic pins
    int Echo = A4;
    int Trig = A5;
    //setup servo motor to "Servo1"
    Servo Servo1;
    //servo to number 3
    int servoPin = 3;
    //sensor to number 2
    int Sensor_pin = 2;
    //set angle to 0 degrees
    int angle = 0;
    int angle_step = 6;
    int Distance_test()//set up the ultrasonic sensor
    {
      digitalWrite(Trig, LOW);
      delayMicroseconds(2);
      digitalWrite(Trig, HIGH);
      delayMicroseconds(20);
      digitalWrite(Trig, LOW);
      float Fdistance = pulseIn(Echo, HIGH);
      Fdistance = Fdistance / 29 / 2;
      return (int)Fdistance;
    }
    void setup() {
      pinMode(Sensor_pin, INPUT);//set up servo motor
      Servo1.attach(servoPin);
      Servo1.write(0);
      delay(2000);
      pinMode(Echo, INPUT);
      pinMode(Trig, OUTPUT);
      Serial.begin(9600);
      pinMode(8, OUTPUT);
      pinMode(7, OUTPUT);
      pinMode(6, OUTPUT);
      Serial.begin(9600);
      angle = 0;
      Servo1.write(angle);
    }
    void loop()//non stop loop
    {
      Servo1.write(0);//reset servo
      Servo1.write(10);//servo to 10 degrees
      delay(200);//delay(wait) 200 millisecends
      Servo1.write(0);//reset servo
      delay(500);//delay(wait) 500 millisecends
      angle = 0;
      for (int i = 0; i <= 180; i += angle_step)
      {
        Servo1.write(i);
        delay(200);
        int dis = Distance_test();
        Serial.println(dis);
        if (dis < 20)
        {
          angle = i;
          Serial.println(angle);
          break;
        }
      }
      //spin motor
      if (angle > 0)
      {
        Servo1.write(angle);
        digitalWrite(7, 1);
        digitalWrite(6, 0);
        delay(10000);
        digitalWrite(7, 0);
        delay(2000);
      }
      // go back home
      for (int i = angle; i >= 0; i -= 5)
      {
        Servo1.write(i);
        delay(100);
      }
      delay(5000);
      angle = 0;
    }

Step 3: TRIAL and ERROR

Originally, I was going to use the passive infrared sensor(PIR) to control the DC motor, but after using it, I found out a huge problem...The PIR was a 180 degrees sensor which can only be used digitally instead of analogically. Which means that, instead of telling you how far or where the object is, it can only tell you whether if there is movement going on within its 180 degrees radius. After hundreds and thousands of times of experimenting, I finally decided that the PIR was not effective enough for this project, so I came to the conclusion that the ultrasonic sensor would be better to use.

Step 4: PICTURES

Share

    Recommendations

    • Pets Challenge

      Pets Challenge
    • Classroom Science Contest

      Classroom Science Contest
    • 1 Hour Challenge

      1 Hour Challenge

    Discussions