Friday, October 12, 2018

Arduino Project : How to make automatic fan using arduino and ultrasonic sensor

Hello friends, in this project I’ll show you how to make automatic usb fan using arduino and ultrasonic sensor. So how does it work? The fan will work if the distance is less than 40 cm from the ultrasonic sensor, and when the object gets longer than 40 cm from the ultrasonic sensor, the fan will automatically turn off.
Here are the materials that we need:
  • Arduino board (I use arduino UNO, but any arduino board will work)
  • Ultrasonic sensor HC-SR04
  • Transistor BC548
  • 560 Ohm resistor
  • Breadboard
  • Jumper
  • Power adapter or battery
  • Cardboard
  • USB fan
Here are the connections:
for blog.JPG

Arduino code:
int trig = 7; //ultrasonic trig pin
int echo = 8; //ultrasonic echo pin
byte fan = 6; //mini fan connected to pin 6 arduino uno
long duration;
float distance;
void setup() {
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(fan, OUTPUT);
}
void loop() {
digitalWrite(trig, LOW);
delayMicroseconds(3);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = duration/58; //based on ultrasonic datasheet
if(distance < 40){
digitalWrite(fan, HIGH);
}else{
digitalWrite(fan, LOW);
}
}
Youtube Video:

That was it, any doubt, don’t hesitate to ask me on the comments, also please subscribe my youtube channel, Thanks…

No comments:

Post a Comment

How to control servo motor with potentiometer and ultrasonic sensor HC-SR04

Hello, In this post I want to share how to control servo motor with potentiometer and ultrasonic sensor HC-SR04. Lets get started. Schem...