0% found this document useful (0 votes)
12 views

Assignment 05

Iot practical notes

Uploaded by

Ayan Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Assignment 05

Iot practical notes

Uploaded by

Ayan Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: Kamble Tejas Filip

Roll No: 31
Class:TE-IT

Assignment-05
Title:Design and implement IoT system using Arduino Uno/ Raspberry Pi using
'Ultrasonic sensor and Servo motor' such as 'Door opener in home automation'.
***********************************************************************************
**********************************

#include <Servo.h>
Servo servo;
const int TRIG_PIN = 6; // Arduino pin connected to Ultrasonic Sensor's
TRIG pin
const int ECHO_PIN = 7; // Arduino pin connected to Ultrasonic Sensor's
ECHO pin
const int BUZZER_PIN = 3; // Arduino pin connected to Piezo Buzzer's pin
const int DISTANCE_THRESHOLD = 20; // centimeters
// variables will change:
float timeInMicro, distance_cm;

void setup() {
Serial.begin(9600); // initialize serial port
pinMode(TRIG_PIN, OUTPUT); // set arduino pin to output mode
pinMode(ECHO_PIN, INPUT); // set arduino pin to input mode
pinMode(BUZZER_PIN, OUTPUT);
servo.attach(9);
}
void loop() {
// generate 10-microsecond pulse to TRIG pin
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
//

timeInMicro = pulseIn(ECHO_PIN, HIGH);

distance_cm = timeInMicro / 29 / 2;

if (distance_cm < DISTANCE_THRESHOLD){


digitalWrite(BUZZER_PIN, HIGH); // turn on Piezo Buzzer
for (int i = 0; i <= 90; i += 1) {
servo.write(i);
delay(15);
}
delay(1000);
for (int j = 90; j > +0; j -= 1) {
servo.write(j);
delay(15);
}
}

else digitalWrite(BUZZER_PIN, LOW); // turn off Piezo Buzzer


// print the value to Serial Monitor
Serial.print("distance: ");
Serial.print(distance_cm);
Serial.println(" cm");

delay(1000);
}

You might also like