Thursday, October 1, 2015

Home automation By withour any switch and using sensors

Apparatus required:

                         1x Ultrasonic sensor

                         1x Arduino Atmega328

                         1x Relay

                         1x fan

                               connecting wires As required




















Connection/Working:   






Step 1:  Upload the program given below in to Arduino board 


Step 2:  Connect the Arduino and Ultrasonic sensor in to the pins  trigPin-13, echoPin-12

Step 3: Connect relay to Arduino pin 2 and motor to relay


Step 3: Now click serial monitor in the Arduino software 


Step 4:  Move your sensor and find distance approx,


Step 5: Follow us and subscribe our YouTube channel






Program:



/*
 HC-SR04 based cooling fan distance sensor:
 VCC to arduino 5v
 GND to arduino GND
 Echo to Arduino to pin 13
 Trig to Arduino pin 12
 */
#define echoPin 13 // Echo Pin
#define trigPin 12 // Trigger Pin
#define motor 2 // Relay
long duration, distance; // Duration used to calculate distance
void setup() {
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(motor, OUTPUT); // cooling fan
}
void loop() {
/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */
 digitalWrite(trigPin, LOW);
 delayMicroseconds(2);
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);
 //Calculate the distance (in cm) based on the speed of fan.
 distance = duration/58.2;
 if (distance <= 50)
 {
 digitalWrite(motor, HIGH);
  delay(50);
 }
 else {
 /* Send the distance to the computer using Serial protocol, and
 turn motor OFF to indicate successful reading. */
 digitalWrite(motor, LOW);
  delay(50);
 }
 //Delay 10ms before next reading.
 delay(10);
}






Visit for   Instructables

For details follow us and ask in  Contact Form. You will receive response in 24 hours

0 comments:

Post a Comment